+ Instance::delete(pool, inserted_instance.id).await.unwrap();
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn test_soft_delete() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+
+ let (inserted_instance, inserted_person, inserted_site, inserted_community) =
+ prepare_site_with_community(pool).await;
+
+ let site_aggregates_before = SiteAggregates::read(pool).await.unwrap();
+ assert_eq!(1, site_aggregates_before.communities);
+
+ Community::update(
+ pool,
+ inserted_community.id,
+ &CommunityUpdateForm::builder().deleted(Some(true)).build(),
+ )
+ .await
+ .unwrap();
+
+ let site_aggregates_after_delete = SiteAggregates::read(pool).await.unwrap();
+ assert_eq!(0, site_aggregates_after_delete.communities);
+
+ Community::update(
+ pool,
+ inserted_community.id,
+ &CommunityUpdateForm::builder().deleted(Some(false)).build(),
+ )
+ .await
+ .unwrap();
+
+ Community::update(
+ pool,
+ inserted_community.id,
+ &CommunityUpdateForm::builder().removed(Some(true)).build(),
+ )
+ .await
+ .unwrap();
+
+ let site_aggregates_after_remove = SiteAggregates::read(pool).await.unwrap();
+ assert_eq!(0, site_aggregates_after_remove.communities);
+
+ Community::update(
+ pool,
+ inserted_community.id,
+ &CommunityUpdateForm::builder().deleted(Some(true)).build(),
+ )
+ .await
+ .unwrap();
+
+ let site_aggregates_after_remove_delete = SiteAggregates::read(pool).await.unwrap();
+ assert_eq!(0, site_aggregates_after_remove_delete.communities);
+
+ Community::delete(pool, inserted_community.id)
+ .await
+ .unwrap();
+ Site::delete(pool, inserted_site.id).await.unwrap();
+ Person::delete(pool, inserted_person.id).await.unwrap();
+ Instance::delete(pool, inserted_instance.id).await.unwrap();