From: JP Moresmau Date: Wed, 21 Jun 2023 08:48:39 +0000 (+0200) Subject: Add test to check reading and listing posts return my_vote (#3215) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/static/README.zh.hant.md?a=commitdiff_plain;h=a1beccf3538202e2154ddd521a2e0c00f8d8cdf0;p=lemmy.git Add test to check reading and listing posts return my_vote (#3215) --- diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 4c65f568..79cc875c 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -746,6 +746,42 @@ mod tests { }; assert_eq!(expected_post_like, inserted_post_like); + let post_listing_single_with_person = PostView::read( + pool, + data.inserted_post.id, + Some(data.inserted_person.id), + None, + ) + .await + .unwrap(); + + let mut expected_post_with_upvote = expected_post_view(&data, pool).await; + expected_post_with_upvote.my_vote = Some(1); + expected_post_with_upvote.counts.score = 1; + expected_post_with_upvote.counts.upvotes = 1; + assert_eq!(expected_post_with_upvote, post_listing_single_with_person); + + let local_user_form = LocalUserUpdateForm::builder() + .show_bot_accounts(Some(false)) + .build(); + let inserted_local_user = + LocalUser::update(pool, data.inserted_local_user.id, &local_user_form) + .await + .unwrap(); + + let read_post_listing = PostQuery::builder() + .pool(pool) + .sort(Some(SortType::New)) + .community_id(Some(data.inserted_community.id)) + .local_user(Some(&inserted_local_user)) + .build() + .list() + .await + .unwrap(); + assert_eq!(1, read_post_listing.len()); + + assert_eq!(expected_post_with_upvote, read_post_listing[0]); + let like_removed = PostLike::remove(pool, data.inserted_person.id, data.inserted_post.id) .await .unwrap();