+ LocalUserLanguage::update(pool, vec![french_id], data.local_user_view.local_user.id)
+ .await
+ .unwrap();
+
+ let post_listing_french = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.local_user_view)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ // only one post in french and one undetermined should be returned
+ assert_eq!(2, post_listing_french.len());
+ assert!(post_listing_french
+ .iter()
+ .any(|p| p.post.language_id == french_id));
+
+ LocalUserLanguage::update(
+ pool,
+ vec![french_id, UNDETERMINED_ID],
+ data.local_user_view.local_user.id,
+ )
+ .await
+ .unwrap();
+ let post_listings_french_und = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.local_user_view)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ // french post and undetermined language post should be returned
+ assert_eq!(2, post_listings_french_und.len());
+ assert_eq!(
+ UNDETERMINED_ID,
+ post_listings_french_und[0].post.language_id
+ );
+ assert_eq!(french_id, post_listings_french_und[1].post.language_id);
+
+ cleanup(data, pool).await;
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn post_listings_removed() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let mut data = init_data(pool).await;
+
+ // Remove the post
+ Post::update(
+ pool,
+ data.inserted_post.id,
+ &PostUpdateForm::builder().removed(Some(true)).build(),
+ )
+ .await
+ .unwrap();
+
+ // Make sure you don't see the removed post in the results
+ let post_listings_no_admin = PostQuery {
+ sort: Some(SortType::New),
+ local_user: Some(&data.local_user_view),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ assert_eq!(1, post_listings_no_admin.len());
+
+ // Removed post is shown to admins on profile page
+ data.local_user_view.person.admin = true;
+ let post_listings_is_admin = PostQuery {
+ sort: Some(SortType::New),
+ local_user: Some(&data.local_user_view),
+ is_profile_view: true,
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ assert_eq!(2, post_listings_is_admin.len());
+
+ cleanup(data, pool).await;
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn post_listings_deleted() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let data = init_data(pool).await;
+
+ // Delete the post
+ Post::update(
+ pool,
+ data.inserted_post.id,
+ &PostUpdateForm::builder().deleted(Some(true)).build(),
+ )
+ .await
+ .unwrap();
+
+ // Make sure you don't see the deleted post in the results
+ let post_listings_no_creator = PostQuery {
+ sort: Some(SortType::New),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ let not_contains_deleted = post_listings_no_creator
+ .iter()
+ .map(|p| p.post.id)
+ .all(|p| p != data.inserted_post.id);
+ assert!(not_contains_deleted);
+
+ // Deleted post is shown to creator
+ let post_listings_is_creator = PostQuery {
+ sort: Some(SortType::New),
+ local_user: Some(&data.local_user_view),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ let contains_deleted = post_listings_is_creator
+ .iter()
+ .map(|p| p.post.id)
+ .any(|p| p == data.inserted_post.id);
+ assert!(contains_deleted);
+
+ cleanup(data, pool).await;
+ }