mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Unittest for Search by title only (#5033)
* added test for search by title only * formatted rust files
This commit is contained in:
parent
89745bb37d
commit
dbb8f9553a
@ -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<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user