From 73145a9af69c9b8f18e060ecf430a41003b6a923 Mon Sep 17 00:00:00 2001 From: silverpill Date: Mon, 16 Jan 2023 12:46:00 +0000 Subject: [PATCH] Add test for find_extraneous_posts() --- src/models/posts/queries.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/models/posts/queries.rs b/src/models/posts/queries.rs index cc446ef..27f24ea 100644 --- a/src/models/posts/queries.rs +++ b/src/models/posts/queries.rs @@ -1133,6 +1133,7 @@ pub async fn get_local_post_count( #[cfg(test)] mod tests { + use chrono::Duration; use serial_test::serial; use crate::database::test_utils::create_test_database; use crate::models::profiles::queries::create_profile; @@ -1433,4 +1434,26 @@ mod tests { assert_eq!(timeline.iter().any(|post| post.id == reply.id), false); assert_eq!(timeline.iter().any(|post| post.id == repost.id), true); } + + #[tokio::test] + #[serial] + async fn test_find_extraneous_posts() { + let db_client = &mut create_test_database().await; + let author_data = ProfileCreateData { + username: "test".to_string(), + ..Default::default() + }; + let author = create_profile(db_client, author_data).await.unwrap(); + let post_data = PostCreateData { + content: "test post".to_string(), + ..Default::default() + }; + create_post(db_client, &author.id, post_data).await.unwrap(); + let created_before = Utc::now() - Duration::days(1); + let result = find_extraneous_posts( + db_client, + &created_before, + ).await.unwrap(); + assert!(result.is_empty()); + } }