From a9cb1c6a8306a1570508f1c6f2438b83d5969a58 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sat, 18 Feb 2023 19:48:17 +0000 Subject: [PATCH] Add test for make_entry function --- src/atom/feeds.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/atom/feeds.rs b/src/atom/feeds.rs index 1626b7a..6247f70 100644 --- a/src/atom/feeds.rs +++ b/src/atom/feeds.rs @@ -83,3 +83,40 @@ pub fn make_feed( entries=entries.join("\n"), ) } + +#[cfg(test)] +mod tests { + use chrono::{TimeZone, Utc}; + use uuid::uuid; + use super::*; + + #[test] + fn test_make_entry() { + let instance_url = "https://example.org"; + let author = DbActorProfile { + username: "username".to_string(), + ..Default::default() + }; + let post_id = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8"); + let created_at = Utc.with_ymd_and_hms(2020, 3, 3, 3, 3, 3).unwrap(); + let post = Post { + id: post_id, + author: author, + content: "

title

text text text

".to_string(), + created_at: created_at, + ..Default::default() + }; + let entry = make_entry(instance_url, &post); + let expected_entry = concat!( + "\n", + " https://example.org/objects/67e55044-10b1-426f-9247-bb680e5fe0c8\n", + " titletext text text\n", + " 2020-03-03T03:03:03+00:00\n", + " username\n", + r#" <p>title</p><p>text text text</p>"#, "\n", + r#" "#, "\n", + "", + ); + assert_eq!(entry, expected_entry); + } +}