From 42eb860a79a64bdec3229b8f2d7998a182d7aa31 Mon Sep 17 00:00:00 2001 From: java-saeng Date: Mon, 14 Aug 2023 14:45:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20Comment=20=EA=B0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=90=98=EC=A7=80=20=EC=95=8A=EC=95=98=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #312 --- .../com/emmsale/comment/domain/Comment.java | 5 ++++ .../emmsale/comment/domain/CommentTest.java | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/backend/emm-sale/src/main/java/com/emmsale/comment/domain/Comment.java b/backend/emm-sale/src/main/java/com/emmsale/comment/domain/Comment.java index 1c803e222..2265b56a5 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/comment/domain/Comment.java +++ b/backend/emm-sale/src/main/java/com/emmsale/comment/domain/Comment.java @@ -52,6 +52,7 @@ private Comment( this.parent = parent; this.member = member; this.content = content; + this.isDeleted = false; } public static Comment createRoot( @@ -92,6 +93,10 @@ public boolean isNotMyComment(final Member member) { return this.member.isNotMe(member); } + public boolean isNotDeleted() { + return !isDeleted || !content.equals(DELETED_COMMENT_MESSAGE); + } + public Optional getParent() { return Optional.ofNullable(parent); } diff --git a/backend/emm-sale/src/test/java/com/emmsale/comment/domain/CommentTest.java b/backend/emm-sale/src/test/java/com/emmsale/comment/domain/CommentTest.java index 6c150fe9a..96879809d 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/comment/domain/CommentTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/comment/domain/CommentTest.java @@ -10,9 +10,13 @@ import com.emmsale.member.domain.Member; import java.util.Collections; import java.util.List; +import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; class CommentTest { @@ -65,4 +69,27 @@ void getContentAndHideIfBlockedMemberWithBlockedMember() { assertEquals(BLOCKED_MEMBER_CONTENT, actual); } + @ParameterizedTest + @MethodSource("commentCandidate") + @DisplayName("isNotDeleted() : 삭제 표시가 false이고 내용이 삭제된 댓글이 아닐 경우에 삭제되지 않은 댓글이라고 할 수 있다.") + void test_isNotDeleted(final Comment comment, final boolean result) throws Exception { + //when & then + assertEquals(comment.isNotDeleted(), result); + } + + static Stream commentCandidate() { + final Event event = EventFixture.인프콘_2023(); + final Member writer = MemberFixture.memberFixture(); + + final Comment comment1 = Comment.createRoot(event, writer, "댓글 내용"); + final Comment comment2 = Comment.createRoot(event, writer, "댓글"); + comment2.delete(); + final Comment comment3 = Comment.createRoot(event, writer, "삭제된 댓글입니다."); + + return Stream.of( + Arguments.of(comment1, true), + Arguments.of(comment2, false), + Arguments.of(comment3, true) + ); + } } From 8f6bebfa415cf79f41a3c7315f16d4a9b23e5f59 Mon Sep 17 00:00:00 2001 From: java-saeng Date: Mon, 14 Aug 2023 15:14:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20:=20=EC=82=AD=EC=A0=9C=EB=90=9C=20?= =?UTF-8?q?=EB=8C=93=EA=B8=80=EC=97=90=20=EB=8C=80=ED=95=B4=EC=84=9C?= =?UTF-8?q?=EB=8A=94=20=EC=95=8C=EB=A6=BC=20=EA=B0=80=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #312 --- .../application/CommentCommandService.java | 1 + .../CommentCommandServiceTest.java | 86 +++++++++++++++++-- 2 files changed, 79 insertions(+), 8 deletions(-) diff --git a/backend/emm-sale/src/main/java/com/emmsale/comment/application/CommentCommandService.java b/backend/emm-sale/src/main/java/com/emmsale/comment/application/CommentCommandService.java index 857074c7f..dced38e08 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/comment/application/CommentCommandService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/comment/application/CommentCommandService.java @@ -86,6 +86,7 @@ private Collection removeDuplicatedCommentsWriter( ) { return comments.stream() .filter(it -> it.isNotMyComment(loginMember)) + .filter(Comment::isNotDeleted) .collect(toMap( comment -> comment.getMember().getId(), comment -> comment, diff --git a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java index 69c2eb630..51824de06 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java @@ -150,13 +150,10 @@ void test_create_child_not_notification() throws Exception { } /** - * 1 - * ㄴ2 (1에게 알림) - * ㄴ3 (1,2에게 알림) + * 1 ㄴ2 (1에게 알림) ㄴ3 (1,2에게 알림) *

- * - * 새로운 대댓글 - * ㄴ2 (1,3에게 알림) + *

+ * 새로운 대댓글 ㄴ2 (1,3에게 알림) */ @Test @DisplayName("create() : 자신이 작성한 댓글, 대댓글들 중에서 다른 사람이 댓글을 작성할 경우 알림이 온다.") @@ -167,24 +164,97 @@ void test_create_child_notification() throws Exception { final Member 댓글_작성자2 = memberRepository.findById(2L).get(); final Member savedMember = memberRepository.save(new Member(200L, "imageUrl")); final Member 댓글_작성자3 = memberRepository.findById(savedMember.getId()).get(); + doNothing().when(eventPublisher).publish(any()); final CommentAddRequest 부모_댓글_요청 = new CommentAddRequest(content, eventId, null); commentCommandService.create(부모_댓글_요청, 댓글_작성자); + + // 댓글_작성자에게 알림 1번 final CommentAddRequest 자식_댓글_요청1 = new CommentAddRequest(content, eventId, 1L); commentCommandService.create(자식_댓글_요청1, 댓글_작성자2); + + // 댓글_작성자, 댓글_작성자2에게 알림 각각 1번 final CommentAddRequest 자식_댓글_요청2 = new CommentAddRequest(content, eventId, 1L); commentCommandService.create(자식_댓글_요청2, 댓글_작성자3); final CommentAddRequest 알림이_가는_자식_댓글_요청 = new CommentAddRequest(content, eventId, 1L); - //when + //when 댓글_작성자, 댓글_작성자3에게 알림 각각 1번 commentCommandService.create(알림이_가는_자식_댓글_요청, 댓글_작성자2); //then verify(eventPublisher, times(5)).publish(any()); } + @Test + @DisplayName("create() : 삭제된 댓글에 대해서는 알림이 가지 않는다.") + void test_create_not_notification_deletedComment() throws Exception { + //given + final String content = "내용"; + final Long eventId = event.getId(); + final Member 댓글_작성자2 = memberRepository.findById(2L).get(); + final Member savedMember = memberRepository.save(new Member(200L, "imageUrl")); + final Member 댓글_작성자3 = memberRepository.findById(savedMember.getId()).get(); + + doNothing().when(eventPublisher).publish(any()); + + final CommentAddRequest 부모_댓글_요청 = new CommentAddRequest(content, eventId, null); + commentCommandService.create(부모_댓글_요청, 댓글_작성자); + + // 댓글_작성자에게 알림 1번 + final CommentAddRequest 자식_댓글_요청1 = new CommentAddRequest(content, eventId, 1L); + commentCommandService.create(자식_댓글_요청1, 댓글_작성자2); + + // 댓글_작성자, 댓글_작성자2에게 알림 각각 1번 + final CommentAddRequest 자식_댓글_요청2 = new CommentAddRequest(content, eventId, 1L); + final CommentResponse response = commentCommandService.create(자식_댓글_요청2, 댓글_작성자3); + commentCommandService.delete(response.getCommentId(), 댓글_작성자3); + + final CommentAddRequest 알림이_가는_자식_댓글_요청 = new CommentAddRequest(content, eventId, 1L); + + //when 댓글_작성자에게 알림 1번, 댓글_작성자3은 삭제된 댓글이므로 알림이 가지 않음 + commentCommandService.create(알림이_가는_자식_댓글_요청, 댓글_작성자2); + + //then + verify(eventPublisher, times(4)).publish(any()); + } + + @Test + @DisplayName("create() : 삭제된 댓글에 대해서는 알림이 가지 않는다.") + void test_create_not_notification_deletedComment2() throws Exception { + //given + final String content = "내용"; + final Long eventId = event.getId(); + final Member 댓글_작성자2 = memberRepository.findById(2L).get(); + final Member savedMember = memberRepository.save(new Member(200L, "imageUrl")); + final Member 댓글_작성자3 = memberRepository.findById(savedMember.getId()).get(); + + doNothing().when(eventPublisher).publish(any()); + + final CommentAddRequest 부모_댓글_요청 = new CommentAddRequest(content, eventId, null); + final CommentResponse response = commentCommandService.create(부모_댓글_요청, 댓글_작성자); + + // 댓글_작성자에게 알림 1번 + final CommentAddRequest 자식_댓글_요청1 = new CommentAddRequest(content, eventId, 1L); + commentCommandService.create(자식_댓글_요청1, 댓글_작성자2); + + // 댓글_작성자의 댓글 삭제 + commentCommandService.delete(response.getCommentId(), 댓글_작성자); + + // 댓글_작성자의 댓글은 삭제 -> 알림 X, 댓글_작성자2에게 알림 1번 + final CommentAddRequest 자식_댓글_요청2 = new CommentAddRequest(content, eventId, 1L); + commentCommandService.create(자식_댓글_요청2, 댓글_작성자3); + + final CommentAddRequest 알림이_가는_자식_댓글_요청 = new CommentAddRequest(content, eventId, 1L); + + //when 댓글_작성자 삭제 -> 알림 X, 댓글_작성자3 알림 1번 + commentCommandService.create(알림이_가는_자식_댓글_요청, 댓글_작성자2); + + //then + verify(eventPublisher, times(3)).publish(any()); + } + @Test @DisplayName("delete() : 댓글을 삭제할 때, 로그인 한 본인의 댓글이 아니면 CAN_NOT_DELETE_COMMENT 가 발생합니다.") void test_delete_canNotDeleteComment() throws Exception { @@ -212,7 +282,7 @@ void test_delete() throws Exception { assertAll( () -> assertTrue(updatedComment.isDeleted()), - () -> assertEquals(updatedComment.getContent(), "삭제된 댓글입니다.") + () -> assertEquals("삭제된 댓글입니다.", updatedComment.getContent()) ); }