Skip to content

Commit

Permalink
feat(template): adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Asone committed Aug 25, 2023
1 parent b872fb7 commit 56b8d46
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NOSTR_BANNER="https://example.com/banner.png"
NOSTR_DESCRIPTION="Craig Wright is not satoshi"
NOSTR_PICTURE="https://example.com/picture.jpg"

DEFAULT_TEMPLATE="test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}"
DEFAULT_TEMPLATE="test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}\nAuthor: {author}\nPublished: {published}"

# Default pow to use for publishing notes
DEFAULT_POW_LEVEL=0
Expand Down
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nostrss-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ url = "2.4.0"
tempfile = "3.6.0"
mockall = "0.11.4"
mime = "0.3.17"
chrono = "0.4.26"

[dependencies.nostrss_grpc]
path = "../nostrss-grpc"
Expand Down
4 changes: 3 additions & 1 deletion nostrss-core/src/fixtures/default.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Default nostrss template file
Feed: {name}
Url: {url}
Tags: {tags}
Tags: {tags}
Author: {author}
Published: {published}
48 changes: 43 additions & 5 deletions nostrss-core/src/template/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,23 @@ mod tests {
extern crate mime;

use super::*;
use chrono::{DateTime, NaiveDateTime, Utc};
use dotenv::from_filename;

use feed_rs::model::{Content, Link, Text};
use feed_rs::model::{Content, Link, Person, Text};

#[test]
fn test_default_template_fallback() {
from_filename(".env.test").ok();

let published_datetime = NaiveDateTime::new(
chrono::NaiveDate::from_ymd(2009, 1, 3),

Check warning on line 126 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

use of deprecated associated function `chrono::NaiveDate::from_ymd`: use `from_ymd_opt()` instead

Check warning on line 126 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

use of deprecated associated function `chrono::NaiveDate::from_ymd`: use `from_ymd_opt()` instead
chrono::NaiveTime::from_hms(18, 15, 05),

Check warning on line 127 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

use of deprecated associated function `chrono::NaiveTime::from_hms`: use `from_hms_opt()` instead

Check warning on line 127 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

use of deprecated associated function `chrono::NaiveTime::from_hms`: use `from_hms_opt()` instead
);

// Convert the NaiveDateTime to a DateTime in the UTC time zone
let utc_published: DateTime<Utc> = DateTime::from_utc(published_datetime, Utc);

let entry = Entry {
content: Some(Content {
body: Some("Test".to_string()),
Expand All @@ -135,6 +144,13 @@ mod tests {
length: None,
}]
.to_vec(),
authors: [Person {
name: "Satoshi Nakamoto".to_string(),
uri: None,
email: None,
}]
.to_vec(),
published: Some(utc_published),
..Default::default()
};

Expand All @@ -148,7 +164,7 @@ mod tests {
assert_eq!(result.is_ok(), true);

let expected =
"test nostrss template\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: "
"test nostrss template\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: \nAuthor: Satoshi Nakamoto\nPublished: 2009-01-03 18:15:05 UTC"
.to_string();
let result = result.unwrap();

Expand All @@ -159,6 +175,14 @@ mod tests {
fn test_custom_template() {
from_filename(".env.test").ok();

let published_datetime = NaiveDateTime::new(
chrono::NaiveDate::from_ymd(2009, 1, 3),

Check warning on line 179 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

use of deprecated associated function `chrono::NaiveDate::from_ymd`: use `from_ymd_opt()` instead

Check warning on line 179 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

use of deprecated associated function `chrono::NaiveDate::from_ymd`: use `from_ymd_opt()` instead
chrono::NaiveTime::from_hms(18, 15, 05),

Check warning on line 180 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

use of deprecated associated function `chrono::NaiveTime::from_hms`: use `from_hms_opt()` instead

Check warning on line 180 in nostrss-core/src/template/template.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

use of deprecated associated function `chrono::NaiveTime::from_hms`: use `from_hms_opt()` instead
);

// Convert the NaiveDateTime to a DateTime in the UTC time zone
let utc_published: DateTime<Utc> = DateTime::from_utc(published_datetime, Utc);

let entry = Entry {
title: Some(Text {
content_type: mime::TEXT_PLAIN,
Expand All @@ -169,6 +193,13 @@ mod tests {
body: Some("Test body".to_string()),
..Default::default()
}),
authors: [Person {
name: "Satoshi Nakamoto".to_string(),
uri: None,
email: None,
}]
.to_vec(),
published: Some(utc_published),
links: [Link {
href: "https://www.nostr.info".to_string(),
rel: None,
Expand All @@ -193,7 +224,7 @@ mod tests {
assert_eq!(result.is_ok(), true);

let result = result.unwrap();
let expected = "Default nostrss template file\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: #Test #nostrss".to_string();
let expected = "Default nostrss template file\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: #Test #nostrss\nAuthor: Satoshi Nakamoto\nPublished: 2009-01-03 18:15:05 UTC".to_string();

assert_eq!(result, expected);
}
Expand All @@ -211,6 +242,13 @@ mod tests {
body: Some("Test body".to_string()),
..Default::default()
}),
authors: [Person {
name: "Satoshi Nakamoto".to_string(),
uri: None,
email: None,
}]
.to_vec(),
published: None,
links: [Link {
href: "https://www.nostr.info".to_string(),
rel: None,
Expand All @@ -237,7 +275,7 @@ mod tests {

let result = result.unwrap();
let expected =
"Default nostrss template file\nFeed: {name}\nUrl: {url}\nTags: {tags}".to_string();
"Default nostrss template file\nFeed: {name}\nUrl: {url}\nTags: {tags}\nAuthor: {author}\nPublished: {published}".to_string();
assert_eq!(result, expected);

let bad_path = "./src/fixture/nonexistant.template".to_string();
Expand All @@ -249,7 +287,7 @@ mod tests {
assert_eq!(result.is_ok(), true);

let result = result.unwrap();
let expected = "test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}".to_string();
let expected = "test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}\nAuthor: {author}\nPublished: {published}".to_string();
assert_eq!(result, expected);
}
}

0 comments on commit 56b8d46

Please sign in to comment.