+ let new_post = PostInsertForm::builder()
+ .name("test post 3".to_string())
+ .creator_id(inserted_person.id)
+ .community_id(inserted_community.id)
+ .language_id(Some(LanguageId(47)))
+ .build();
+
+ let inserted_post = Post::create(pool, &new_post).await.unwrap();
+
+ let new_bot_post = PostInsertForm::builder()
+ .name("test bot post".to_string())
+ .creator_id(inserted_bot.id)
+ .community_id(inserted_community.id)
+ .build();
+
+ let _inserted_bot_post = Post::create(pool, &new_bot_post).await.unwrap();
+
+ Data {
+ inserted_instance,
+ inserted_person,
+ inserted_local_user,
+ inserted_blocked_person,
+ inserted_bot,
+ inserted_community,
+ inserted_post,
+ }
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn post_listing_with_person() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let data = init_data(pool).await;
+
+ 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 {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ 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_listing_with_user = expected_post_view(&data, pool).await;
+
+ // Should be only one person, IE the bot post, and blocked should be missing
+ assert_eq!(1, read_post_listing.len());
+
+ assert_eq!(expected_post_listing_with_user, read_post_listing[0]);
+ expected_post_listing_with_user.my_vote = Some(0);
+ assert_eq!(
+ expected_post_listing_with_user,
+ post_listing_single_with_person
+ );
+
+ let local_user_form = LocalUserUpdateForm::builder()
+ .show_bot_accounts(Some(true))
+ .build();
+ let inserted_local_user =
+ LocalUser::update(pool, data.inserted_local_user.id, &local_user_form)
+ .await
+ .unwrap();
+
+ let post_listings_with_bots = PostQuery {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ // should include bot post which has "undetermined" language
+ assert_eq!(2, post_listings_with_bots.len());
+
+ cleanup(data, pool).await;
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn post_listing_no_person() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let data = init_data(pool).await;
+
+ let read_post_listing_multiple_no_person = PostQuery {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ let read_post_listing_single_no_person =
+ PostView::read(pool, data.inserted_post.id, None, None)
+ .await
+ .unwrap();
+
+ let expected_post_listing_no_person = expected_post_view(&data, pool).await;