- fn cleanup(data: Data, conn: &PgConnection) {
- let num_deleted = Post::delete(conn, data.inserted_post.id).unwrap();
- Community::delete(conn, data.inserted_community.id).unwrap();
- Person::delete(conn, data.inserted_person.id).unwrap();
- Person::delete(conn, data.inserted_bot.id).unwrap();
- Person::delete(conn, data.inserted_blocked_person.id).unwrap();
+ #[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_admin = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.inserted_local_user)),
+ is_mod_or_admin: (Some(false)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ assert_eq!(1, post_listings_no_admin.len());
+
+ // Make sure they see both
+ let post_listings_is_admin = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.inserted_local_user)),
+ is_mod_or_admin: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ assert_eq!(2, post_listings_is_admin.len());
+
+ 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.inserted_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();