From e8821af126ff036ce6a10b9ceb4330264b96d6f1 Mon Sep 17 00:00:00 2001 From: kdkdhoho Date: Tue, 10 Dec 2024 22:15:21 +0900 Subject: [PATCH] =?UTF-8?q?=20feat:=20=EB=8C=93=EA=B8=80/=EB=8B=B5?= =?UTF-8?q?=EA=B8=80=EC=97=90=EC=84=9C=20=EB=A9=98=EC=85=98=20=EB=8B=B9?= =?UTF-8?q?=ED=95=9C=20=EC=9C=A0=EC=A0=80=EA=B0=80=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=ED=95=9C=20=EA=B2=BD=EC=9A=B0=20=EB=B3=B4=EC=97=AC=EC=A7=80?= =?UTF-8?q?=EB=8A=94=20=EA=B0=92=20=EC=88=98=EC=A0=95=20(#313)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/CommentFindResponse.java | 13 ++++--- .../listywave/mention/MentionServiceTest.java | 35 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/listywave/list/application/dto/response/CommentFindResponse.java b/src/main/java/com/listywave/list/application/dto/response/CommentFindResponse.java index 183144db..1e22e8b9 100644 --- a/src/main/java/com/listywave/list/application/dto/response/CommentFindResponse.java +++ b/src/main/java/com/listywave/list/application/dto/response/CommentFindResponse.java @@ -6,6 +6,7 @@ import com.listywave.list.application.domain.comment.Comment; import com.listywave.list.application.domain.reply.Reply; import com.listywave.mention.Mention; +import com.listywave.user.application.domain.User; import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -119,10 +120,14 @@ public record MentionDto( public static List toList(List mentions) { return mentions.stream() - .map(Mention::getUser) - .filter(user -> !user.isDelete()) - .map(user -> new MentionDto(user.getId(), user.getNickname())) - .sorted(comparingLong(MentionDto::userId)) + .sorted(comparingLong(Mention::getId)) + .map(mention -> { + User user = mention.getUser(); + if (user.isDelete()) { + return new MentionDto(0L, "withdrawer"); + } + return new MentionDto(user.getId(), user.getNickname()); + }) .toList(); } } diff --git a/src/test/java/com/listywave/mention/MentionServiceTest.java b/src/test/java/com/listywave/mention/MentionServiceTest.java index 80d9c1b4..f8b8d1fc 100644 --- a/src/test/java/com/listywave/mention/MentionServiceTest.java +++ b/src/test/java/com/listywave/mention/MentionServiceTest.java @@ -122,10 +122,9 @@ class 멘션_조회 { } @Test - void 댓글에서_멘션을_당한_사용자가_탈퇴한_사용자인_경우_조회하지_않는다() { + void 댓글에서_멘션을_당한_사용자가_탈퇴한_사용자인_경우_id는_0이고_닉네임은_withdrawer로_응답한다() { // given - List mentionIds = List.of(js.getId(), ej.getId()); - commentService.create(list.getId(), dh.getId(), "댓글이용", mentionIds); + commentService.create(list.getId(), dh.getId(), "댓글이용", List.of(js.getId(), ej.getId())); // when authService.withdraw(js.getId()); @@ -133,9 +132,21 @@ class 멘션_조회 { // then CommentFindResponse response = commentService.findAllBy(list.getId(), 5, null); CommentDto commentDto = response.comments().get(0); + List mentions = commentDto.mentions(); - assertThat(commentDto.mentions()).hasSize(1); - assertThat(commentDto.mentions().get(0).userId()).isEqualTo(ej.getId()); + assertAll( + () -> assertThat(mentions).hasSize(2), + () -> { + MentionDto mentionToJs = mentions.get(0); + assertThat(mentionToJs.userId()).isEqualTo(0L); + assertThat(mentionToJs.userNickname()).isEqualTo("withdrawer"); + }, + () -> { + MentionDto mentionToEj = mentions.get(1); + assertThat(mentionToEj.userId()).isEqualTo(ej.getId()); + assertThat(mentionToEj.userNickname()).isEqualTo(ej.getNickname()); + } + ); } @Test @@ -169,11 +180,10 @@ class 멘션_조회 { } @Test - void 답글에서_멘션을_당한_사용자가_탈퇴한_사용자인_경우_조회하지_않는다() { + void 답글에서_멘션을_당한_사용자가_탈퇴한_사용자인_경우_id는_0이고_닉네임은_withdrawer으로_응답한다() { // given Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이용", EMPTY_LIST).id(); - List mentionIds = List.of(dh.getId(), ej.getId()); - replyService.create(list.getId(), commentId, js.getId(), "답글이용", mentionIds); + replyService.create(list.getId(), commentId, js.getId(), "답글이용", List.of(dh.getId(), ej.getId())); authService.withdraw(ej.getId()); @@ -183,8 +193,13 @@ class 멘션_조회 { // then assertAll( - () -> assertThat(reply.mentions()).hasSize(1), - () -> assertThat(reply.mentions().get(0).userId()).isEqualTo(dh.getId()) + () -> assertThat(reply.mentions()).hasSize(2), + () -> assertThat(reply.mentions().get(0).userId()).isEqualTo(dh.getId()), + () -> { + MentionDto mentionToEj = reply.mentions().get(1); + assertThat(mentionToEj.userId()).isEqualTo(0L); + assertThat(mentionToEj.userNickname()).isEqualTo("withdrawer"); + } ); } }