From d60a58bd6e836dcaf8c9118307adc8837b17696a Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 7 Apr 2021 15:22:34 -0400 Subject: [PATCH] Fixing unit tests. --- crates/db_queries/src/aggregates/comment_aggregates.rs | 4 ++++ crates/db_queries/src/aggregates/community_aggregates.rs | 8 ++++++++ crates/db_queries/src/aggregates/person_aggregates.rs | 4 ++++ crates/db_queries/src/aggregates/post_aggregates.rs | 4 ++++ crates/db_queries/src/aggregates/site_aggregates.rs | 4 ++++ crates/db_queries/src/source/moderator.rs | 1 + crates/db_queries/src/source/person_mention.rs | 1 + crates/db_schema/src/source/comment.rs | 2 +- crates/db_schema/src/source/post.rs | 6 +++--- 9 files changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/db_queries/src/aggregates/comment_aggregates.rs b/crates/db_queries/src/aggregates/comment_aggregates.rs index 412f2e0a2..898c57da3 100644 --- a/crates/db_queries/src/aggregates/comment_aggregates.rs +++ b/crates/db_queries/src/aggregates/comment_aggregates.rs @@ -141,5 +141,9 @@ mod tests { Person::delete(&conn, another_inserted_person.id).unwrap(); let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap(); assert_eq!(1, person_num_deleted); + + // Delete the community + let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap(); + assert_eq!(1, community_num_deleted); } } diff --git a/crates/db_queries/src/aggregates/community_aggregates.rs b/crates/db_queries/src/aggregates/community_aggregates.rs index a70412660..c668c15ac 100644 --- a/crates/db_queries/src/aggregates/community_aggregates.rs +++ b/crates/db_queries/src/aggregates/community_aggregates.rs @@ -167,6 +167,14 @@ mod tests { let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap(); assert_eq!(1, person_num_deleted); + // Delete the community + let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap(); + assert_eq!(1, community_num_deleted); + + let another_community_num_deleted = + Community::delete(&conn, another_inserted_community.id).unwrap(); + assert_eq!(1, another_community_num_deleted); + // Should be none found, since the creator was deleted let after_delete = CommunityAggregates::read(&conn, inserted_community.id); assert!(after_delete.is_err()); diff --git a/crates/db_queries/src/aggregates/person_aggregates.rs b/crates/db_queries/src/aggregates/person_aggregates.rs index 99dcae9a1..56d72d38b 100644 --- a/crates/db_queries/src/aggregates/person_aggregates.rs +++ b/crates/db_queries/src/aggregates/person_aggregates.rs @@ -159,6 +159,10 @@ mod tests { assert_eq!(1, person_num_deleted); Person::delete(&conn, another_inserted_person.id).unwrap(); + // Delete the community + let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap(); + assert_eq!(1, community_num_deleted); + // Should be none found let after_delete = PersonAggregates::read(&conn, inserted_person.id); assert!(after_delete.is_err()); diff --git a/crates/db_queries/src/aggregates/post_aggregates.rs b/crates/db_queries/src/aggregates/post_aggregates.rs index de39e3029..2fcb6f5d2 100644 --- a/crates/db_queries/src/aggregates/post_aggregates.rs +++ b/crates/db_queries/src/aggregates/post_aggregates.rs @@ -148,6 +148,10 @@ mod tests { let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap(); assert_eq!(1, person_num_deleted); + // Delete the community + let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap(); + assert_eq!(1, community_num_deleted); + // Should be none found, since the creator was deleted let after_delete = PostAggregates::read(&conn, inserted_post.id); assert!(after_delete.is_err()); diff --git a/crates/db_queries/src/aggregates/site_aggregates.rs b/crates/db_queries/src/aggregates/site_aggregates.rs index bf8500203..995462e1a 100644 --- a/crates/db_queries/src/aggregates/site_aggregates.rs +++ b/crates/db_queries/src/aggregates/site_aggregates.rs @@ -118,6 +118,10 @@ mod tests { let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap(); assert_eq!(1, person_num_deleted); + // Delete the community + let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap(); + assert_eq!(1, community_num_deleted); + let after_delete = SiteAggregates::read(&conn); assert!(after_delete.is_err()); } diff --git a/crates/db_queries/src/source/moderator.rs b/crates/db_queries/src/source/moderator.rs index 238ad13be..14bb07f1c 100644 --- a/crates/db_queries/src/source/moderator.rs +++ b/crates/db_queries/src/source/moderator.rs @@ -231,6 +231,7 @@ mod tests { let new_post = PostForm { name: "A test post thweep".into(), + creator_id: inserted_person.id, community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_queries/src/source/person_mention.rs b/crates/db_queries/src/source/person_mention.rs index 2dee6c6e9..456894200 100644 --- a/crates/db_queries/src/source/person_mention.rs +++ b/crates/db_queries/src/source/person_mention.rs @@ -112,6 +112,7 @@ mod tests { let new_post = PostForm { name: "A test post".into(), + creator_id: inserted_person.id, community_id: inserted_community.id, ..PostForm::default() }; diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index fba61f463..bd36a48e8 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -56,8 +56,8 @@ pub struct CommentAlias1 { pub struct CommentForm { pub creator_id: PersonId, pub post_id: PostId, - pub parent_id: Option, pub content: String, + pub parent_id: Option, pub removed: Option, pub read: Option, pub published: Option, diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index 87681e010..2581db95c 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -35,16 +35,16 @@ pub struct Post { #[table_name = "post"] pub struct PostForm { pub name: String, - pub url: Option, - pub body: Option, pub creator_id: PersonId, pub community_id: CommunityId, + pub nsfw: bool, + pub url: Option, + pub body: Option, pub removed: Option, pub locked: Option, pub published: Option, pub updated: Option, pub deleted: Option, - pub nsfw: bool, pub stickied: Option, pub embed_title: Option, pub embed_description: Option,