+ 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: Some(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;