]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/aggregates/person_aggregates.rs
Do not decrement comment score twice when removing then deleting. (#3196)
[lemmy.git] / crates / db_schema / src / aggregates / person_aggregates.rs
index 6f804590845016db79490b97d44e6c8932ecb309..295f1bfbb94f78947aea0883c86ef711b70d7156 100644 (file)
@@ -22,7 +22,7 @@ mod tests {
   use crate::{
     aggregates::person_aggregates::PersonAggregates,
     source::{
-      comment::{Comment, CommentInsertForm, CommentLike, CommentLikeForm},
+      comment::{Comment, CommentInsertForm, CommentLike, CommentLikeForm, CommentUpdateForm},
       community::{Community, CommunityInsertForm},
       instance::Instance,
       person::{Person, PersonInsertForm},
@@ -138,6 +138,27 @@ mod tests {
       .unwrap();
     assert_eq!(0, after_post_like_remove.post_score);
 
+    Comment::update(
+      pool,
+      inserted_comment.id,
+      &CommentUpdateForm::builder().removed(Some(true)).build(),
+    )
+    .await
+    .unwrap();
+    Comment::update(
+      pool,
+      inserted_child_comment.id,
+      &CommentUpdateForm::builder().removed(Some(true)).build(),
+    )
+    .await
+    .unwrap();
+
+    let after_parent_comment_removed = PersonAggregates::read(pool, inserted_person.id)
+      .await
+      .unwrap();
+    assert_eq!(0, after_parent_comment_removed.comment_count);
+    assert_eq!(0, after_parent_comment_removed.comment_score);
+
     // Remove a parent comment (the scores should also be removed)
     Comment::delete(pool, inserted_comment.id).await.unwrap();
     Comment::delete(pool, inserted_child_comment.id)