Unittest for Search by title only (#5033)

* added test for search by title only

* formatted rust files
This commit is contained in:
leoseg 2024-09-19 23:00:07 +02:00 committed by GitHub
parent 89745bb37d
commit dbb8f9553a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -780,6 +780,7 @@ mod tests {
use std::{collections::HashSet, time::Duration};
use url::Url;
const POST_WITH_ANOTHER_TITLE: &str = "Another title";
const POST_BY_BLOCKED_PERSON: &str = "post by blocked person";
const POST_BY_BOT: &str = "post by bot";
const POST: &str = "post";
@ -1028,6 +1029,63 @@ mod tests {
cleanup(data, pool).await
}
#[tokio::test]
#[serial]
async fn post_listing_title_only() -> LemmyResult<()> {
let pool = &build_db_pool().await?;
let pool = &mut pool.into();
let data = init_data(pool).await?;
// A post which contains the search them 'Post' not in the title (but in the body)
let new_post = PostInsertForm::builder()
.name(POST_WITH_ANOTHER_TITLE.to_string())
.creator_id(data.local_user_view.person.id)
.community_id(data.inserted_community.id)
.language_id(Some(LanguageId(47)))
.body(Some("Post".to_string()))
.build();
let inserted_post = Post::create(pool, &new_post).await?;
let read_post_listing_by_title_only = PostQuery {
community_id: Some(data.inserted_community.id),
local_user: None,
search_term: Some("Post".to_string()),
title_only: Some(true),
..data.default_post_query()
}
.list(&data.site, pool)
.await?;
let read_post_listing = PostQuery {
community_id: Some(data.inserted_community.id),
local_user: None,
search_term: Some("Post".to_string()),
..data.default_post_query()
}
.list(&data.site, pool)
.await?;
// Should be 4 posts when we do not search for title only
assert_eq!(
vec![
POST_WITH_ANOTHER_TITLE,
POST_BY_BOT,
POST,
POST_BY_BLOCKED_PERSON
],
names(&read_post_listing)
);
// Should be 3 posts when we search for title only
assert_eq!(
vec![POST_BY_BOT, POST, POST_BY_BLOCKED_PERSON],
names(&read_post_listing_by_title_only)
);
Post::delete(pool, inserted_post.id).await?;
cleanup(data, pool).await
}
#[tokio::test]
#[serial]
async fn post_listing_block_community() -> LemmyResult<()> {