+ 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;
+ }
+
+ async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
+ let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
+ Community::delete(pool, data.inserted_community.id)
+ .await
+ .unwrap();
+ Person::delete(pool, data.local_user_view.person.id)
+ .await
+ .unwrap();
+ Person::delete(pool, data.inserted_bot.id).await.unwrap();
+ Person::delete(pool, data.inserted_blocked_person.id)
+ .await
+ .unwrap();
+ Instance::delete(pool, data.inserted_instance.id)
+ .await
+ .unwrap();
+ assert_eq!(1, num_deleted);
+ }
+
+ async fn expected_post_view(data: &Data, pool: &mut DbPool<'_>) -> PostView {
+ let (inserted_person, inserted_community, inserted_post) = (
+ &data.local_user_view.person,
+ &data.inserted_community,
+ &data.inserted_post,
+ );
+ let agg = PostAggregates::read(pool, inserted_post.id).await.unwrap();
+
+ PostView {
+ post: Post {
+ id: inserted_post.id,
+ name: inserted_post.name.clone(),
+ creator_id: inserted_person.id,
+ url: None,
+ body: None,
+ published: inserted_post.published,
+ updated: None,
+ community_id: inserted_community.id,
+ removed: false,
+ deleted: false,
+ locked: false,
+ nsfw: false,
+ embed_title: None,
+ embed_description: None,
+ embed_video_url: None,
+ thumbnail_url: None,
+ ap_id: inserted_post.ap_id.clone(),
+ local: true,
+ language_id: LanguageId(47),
+ featured_community: false,
+ featured_local: false,
+ },
+ my_vote: None,
+ unread_comments: 0,
+ creator: Person {
+ id: inserted_person.id,
+ name: inserted_person.name.clone(),
+ display_name: None,
+ published: inserted_person.published,
+ avatar: None,
+ actor_id: inserted_person.actor_id.clone(),
+ local: true,
+ admin: false,
+ bot_account: false,
+ banned: false,
+ deleted: false,
+ bio: None,
+ banner: None,
+ updated: None,
+ inbox_url: inserted_person.inbox_url.clone(),
+ shared_inbox_url: None,
+ matrix_user_id: None,
+ ban_expires: None,
+ instance_id: data.inserted_instance.id,
+ private_key: inserted_person.private_key.clone(),
+ public_key: inserted_person.public_key.clone(),
+ last_refreshed_at: inserted_person.last_refreshed_at,
+ },
+ creator_banned_from_community: false,
+ community: Community {
+ id: inserted_community.id,
+ name: inserted_community.name.clone(),
+ icon: None,
+ removed: false,
+ deleted: false,
+ nsfw: false,
+ actor_id: inserted_community.actor_id.clone(),
+ local: true,
+ title: "nada".to_owned(),
+ description: None,
+ updated: None,
+ banner: None,
+ hidden: false,
+ posting_restricted_to_mods: false,
+ published: inserted_community.published,
+ instance_id: data.inserted_instance.id,
+ private_key: inserted_community.private_key.clone(),
+ public_key: inserted_community.public_key.clone(),
+ last_refreshed_at: inserted_community.last_refreshed_at,
+ followers_url: inserted_community.followers_url.clone(),
+ inbox_url: inserted_community.inbox_url.clone(),
+ shared_inbox_url: inserted_community.shared_inbox_url.clone(),
+ moderators_url: inserted_community.moderators_url.clone(),
+ featured_url: inserted_community.featured_url.clone(),
+ },
+ counts: PostAggregates {
+ id: agg.id,
+ post_id: inserted_post.id,
+ comments: 0,
+ score: 0,
+ upvotes: 0,
+ downvotes: 0,
+ published: agg.published,
+ newest_comment_time_necro: inserted_post.published,
+ newest_comment_time: inserted_post.published,
+ featured_community: false,
+ featured_local: false,
+ hot_rank: 1728,
+ hot_rank_active: 1728,
+ controversy_rank: 0.0,
+ community_id: inserted_post.community_id,
+ creator_id: inserted_post.creator_id,
+ },
+ subscribed: SubscribedType::NotSubscribed,
+ read: false,
+ saved: false,
+ creator_blocked: false,
+ }