Skip to content

Commit

Permalink
test: 멘션 아이디를 given 절로 추출 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed Oct 13, 2024
1 parent 2273adf commit e750b13
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/test/java/com/listywave/mention/MentionServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ class 멘션_생성 {

@Test
void 댓글_작성_시_다른_유저를_멘션할_경우_저장된다() {
// given
List<Long> mentionIds = List.of(js.getId(), ej.getId());

// when
Long savedCommentId = commentService.create(list.getId(), dh.getId(), "댓글 남겨요!", List.of(js.getId(), ej.getId())).id();
Long savedCommentId = commentService.create(list.getId(), dh.getId(), "댓글 남겨요!", mentionIds).id();
Comment comment = commentRepository.getById(savedCommentId);

// then
Expand Down Expand Up @@ -54,7 +57,8 @@ class 멘션_생성 {
Long savedCommentId = commentService.create(list.getId(), dh.getId(), "댓글 남겨요!", EMPTY_LIST).id();

// when
Long savedMentionId = replyService.create(list.getId(), savedCommentId, js.getId(), "답글 남깁니당", List.of(dh.getId(), ej.getId())).id();
List<Long> mentionIds = List.of(dh.getId(), ej.getId());
Long savedMentionId = replyService.create(list.getId(), savedCommentId, js.getId(), "답글 남깁니당", mentionIds).id();
Reply reply = replyRepository.getById(savedMentionId);

// then
Expand Down Expand Up @@ -87,7 +91,8 @@ class 멘션_조회 {
@Test
void 멘션을_포함한_댓글을_조회한다() {
// given
Long savedCommentId = commentService.create(list.getId(), dh.getId(), "댓글이용", List.of(js.getId(), ej.getId())).id();
List<Long> mentionIds = List.of(js.getId(), ej.getId());
Long savedCommentId = commentService.create(list.getId(), dh.getId(), "댓글이용", mentionIds).id();
commentRepository.getById(savedCommentId);

// when
Expand Down Expand Up @@ -119,7 +124,8 @@ class 멘션_조회 {
@Test
void 댓글에서_멘션을_당한_사용자가_탈퇴한_사용자인_경우_조회하지_않는다() {
// given
commentService.create(list.getId(), dh.getId(), "댓글이용", List.of(js.getId(), ej.getId()));
List<Long> mentionIds = List.of(js.getId(), ej.getId());
commentService.create(list.getId(), dh.getId(), "댓글이용", mentionIds);

// when
authService.withdraw(js.getId());
Expand All @@ -136,7 +142,8 @@ class 멘션_조회 {
void 멘션을_포함한_답글을_조회한다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이용", EMPTY_LIST).id();
replyService.create(list.getId(), commentId, js.getId(), "답글이용", List.of(dh.getId()));
List<Long> mentionIds = List.of(dh.getId());
replyService.create(list.getId(), commentId, js.getId(), "답글이용", mentionIds);

// when
List<CommentDto> comments = commentService.findCommentBy(list.getId(), 5, null).comments();
Expand Down Expand Up @@ -165,7 +172,8 @@ class 멘션_조회 {
void 답글에서_멘션을_당한_사용자가_탈퇴한_사용자인_경우_조회하지_않는다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이용", EMPTY_LIST).id();
replyService.create(list.getId(), commentId, js.getId(), "답글이용", List.of(dh.getId(), ej.getId()));
List<Long> mentionIds = List.of(dh.getId(), ej.getId());
replyService.create(list.getId(), commentId, js.getId(), "답글이용", mentionIds);

authService.withdraw(ej.getId());

Expand All @@ -187,10 +195,12 @@ class 멘션_수정 {
@Test
void 댓글을_수정해_새로운_멘션을_추가한다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", List.of(js.getId())).id();
List<Long> firstMentionedIds = List.of(js.getId());
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", firstMentionedIds).id();

// when
commentService.update(list.getId(), dh.getId(), commentId, "댓글 수정이요", List.of(js.getId(), ej.getId()));
List<Long> newMentionedIds = List.of(js.getId(), ej.getId());
commentService.update(list.getId(), dh.getId(), commentId, "댓글 수정이요", newMentionedIds);

// then
CommentFindResponse response = commentService.findCommentBy(list.getId(), 5, null);
Expand All @@ -205,7 +215,8 @@ class 멘션_수정 {
@Test
void 댓글을_수정해_멘션을_제거한다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", List.of(js.getId())).id();
List<Long> mentionIds = List.of(js.getId());
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", mentionIds).id();

// when
commentService.update(list.getId(), dh.getId(), commentId, "댓글 수정이요", EMPTY_LIST);
Expand All @@ -220,10 +231,12 @@ class 멘션_수정 {
void 답글을_수정해_새로운_멘션을_추가한다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", EMPTY_LIST).id();
Long replyId = replyService.create(list.getId(), commentId, js.getId(), "답글이요", List.of(dh.getId())).id();
List<Long> firstMentionedIds = List.of(dh.getId());
Long replyId = replyService.create(list.getId(), commentId, js.getId(), "답글이요", firstMentionedIds).id();

// when
ReplyUpdateCommand replyUpdateCommand = new ReplyUpdateCommand(list.getId(), commentId, replyId, "답글 수정이요", List.of(dh.getId(), ej.getId()));
List<Long> newMentionedIds = List.of(dh.getId(), ej.getId());
ReplyUpdateCommand replyUpdateCommand = new ReplyUpdateCommand(list.getId(), commentId, replyId, "답글 수정이요", newMentionedIds);
replyService.update(replyUpdateCommand, js.getId());

// then
Expand All @@ -240,7 +253,8 @@ class 멘션_수정 {
void 답글을_수정해_멘션을_제거한다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", EMPTY_LIST).id();
Long replyId = replyService.create(list.getId(), commentId, js.getId(), "답글이요", List.of(dh.getId())).id();
List<Long> firstMentionedIds = List.of(dh.getId());
Long replyId = replyService.create(list.getId(), commentId, js.getId(), "답글이요", firstMentionedIds).id();

// when
ReplyUpdateCommand replyUpdateCommand = new ReplyUpdateCommand(list.getId(), commentId, replyId, "답글 수정이요", EMPTY_LIST);
Expand All @@ -259,7 +273,8 @@ class 멘션_삭제 {
@Test
void 멘션을_한_댓글_삭제_시_함께_삭제한다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", List.of(js.getId(), ej.getId())).id();
List<Long> mentionIds = List.of(js.getId(), ej.getId());
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", mentionIds).id();

// when
commentService.delete(list.getId(), commentId, dh.getId());
Expand All @@ -272,7 +287,8 @@ class 멘션_삭제 {
void 멘션을_한_답글_삭제_시_함께_삭제한다() {
// given
Long commentId = commentService.create(list.getId(), dh.getId(), "댓글이요", EMPTY_LIST).id();
Long replyId = replyService.create(list.getId(), commentId, js.getId(), "답글이요", List.of(dh.getId())).id();
List<Long> mentionIds = List.of(dh.getId());
Long replyId = replyService.create(list.getId(), commentId, js.getId(), "답글이요", mentionIds).id();

// when
ReplyDeleteCommand command = new ReplyDeleteCommand(list.getId(), commentId, replyId);
Expand Down

0 comments on commit e750b13

Please sign in to comment.