From 9fd6724819984e310e704ca6205f6501ba558130 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 12 Feb 2023 22:31:30 +0000 Subject: [PATCH] Add test for get_thread() function --- src/models/posts/queries.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/models/posts/queries.rs b/src/models/posts/queries.rs index 167693a..c577849 100644 --- a/src/models/posts/queries.rs +++ b/src/models/posts/queries.rs @@ -1608,6 +1608,35 @@ mod tests { assert_eq!(timeline.iter().any(|post| post.id == repost.id), true); } + #[tokio::test] + #[serial] + async fn test_get_thread() { + let db_client = &mut create_test_database().await; + let user_data = UserCreateData { + username: "test".to_string(), + ..Default::default() + }; + let user = create_user(db_client, user_data).await.unwrap(); + let post_data_1 = PostCreateData { + content: "my post".to_string(), + ..Default::default() + }; + let post_1 = create_post(db_client, &user.id, post_data_1).await.unwrap(); + let post_data_2 = PostCreateData { + content: "my reply".to_string(), + in_reply_to_id: Some(post_1.id.clone()), + ..Default::default() + }; + let post_2 = create_post(db_client, &user.id, post_data_2).await.unwrap(); + let thread = get_thread( + db_client, + &post_2.id, + Some(&user.id), + ).await.unwrap(); + assert_eq!(thread[0].id, post_1.id); + assert_eq!(thread[1].id, post_2.id); + } + #[tokio::test] #[serial] async fn test_find_extraneous_posts() {