Add test for find_extraneous_posts()

This commit is contained in:
silverpill 2023-01-16 12:46:00 +00:00
parent 3ed610969e
commit 73145a9af6

View file

@ -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());
}
}