-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: TalkRoom Comment 삭제 API 테스트 코드 작성 (#38)
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,68 @@ void editCommentWithUserB() { | |
.hasMessage("권한이 없는 사용자입니다."); | ||
} | ||
|
||
@Test | ||
@DisplayName("의견을 작성한 유저가 의견을 삭제한다.") | ||
void deleteComment() { | ||
// given | ||
User user = createUser(); | ||
userRepository.save(user); | ||
|
||
Book book = createBook(); | ||
bookRepository.save(book); | ||
|
||
TalkRoom talkRoom = createTalkRoom(book, user); | ||
talkRoomRepository.save(talkRoom); | ||
|
||
createTalkRoomRole(talkRoom); | ||
|
||
Comment comment = createComment(user, talkRoom); | ||
commentRepository.save(comment); | ||
|
||
// when | ||
commentService.deleteComment(comment.getId(), user.getId()); | ||
|
||
// then | ||
List<Comment> comments = commentRepository.findAll(); | ||
assertThat(0).isEqualTo(comments.size()); | ||
} | ||
|
||
@Test | ||
@DisplayName("의견을 작성한 유저(userA)가 아닌 다른 유저(userB)가 의견을 삭제할 수 없다.") | ||
void deleteCommentWithUserB() { | ||
// given | ||
User userA = createUser(); | ||
userRepository.save(userA); | ||
|
||
User userB = User.builder() | ||
.name("[email protected]") | ||
.profileImage("image") | ||
.oauthId( | ||
OauthId.builder() | ||
.oauthId("oauthId2") | ||
.oauthType(OauthType.KAKAO) | ||
.build() | ||
) | ||
.build(); | ||
userRepository.save(userB); | ||
|
||
Book book = createBook(); | ||
bookRepository.save(book); | ||
|
||
TalkRoom talkRoom = createTalkRoom(book, userA); | ||
talkRoomRepository.save(talkRoom); | ||
|
||
createTalkRoomRole(talkRoom); | ||
|
||
Comment comment = createComment(userA, talkRoom); | ||
commentRepository.save(comment); | ||
|
||
// when // then | ||
assertThatThrownBy(() -> commentService.deleteComment(comment.getId(), userB.getId())) | ||
.isInstanceOf(BusinessException.class) | ||
.hasMessage("권한이 없는 사용자입니다."); | ||
} | ||
|
||
private static Comment createComment(User user, TalkRoom talkRoom) { | ||
return Comment.builder() | ||
.content("의견") | ||
|