-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/65 커뮤니티 댓글 생성 기능 #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6094c71
4b666aa
e087c0c
9a4c087
58038ee
b686152
0be3598
f68bb02
f265514
10a0dbb
3151a8b
21e7a2a
c5d8e3c
dbaf67e
3c306dc
f4a5f6b
0f23e4a
b43a5e6
7835bb2
6c0def6
62aa1e5
01656ce
b12b771
27a199a
d1caba6
f7d3478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ | |
| import com.somemore.community.domain.CommunityComment; | ||
| import com.somemore.community.dto.request.CommunityCommentCreateRequestDto; | ||
| import com.somemore.community.repository.comment.CommunityCommentRepository; | ||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.global.exception.ExceptionMessage; | ||
| import org.assertj.core.api.ThrowableAssert; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
@@ -13,6 +16,7 @@ | |
| import java.util.UUID; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
|
||
| class CreateCommunityCommentServiceTest extends IntegrationTestSupport { | ||
|
|
||
|
|
@@ -33,12 +37,13 @@ void createCommunityCommentWithDto() { | |
| //given | ||
| CommunityCommentCreateRequestDto dto = CommunityCommentCreateRequestDto.builder() | ||
| .content("커뮤니티 댓글 테스트 내용") | ||
| .parentCommentId(null) | ||
| .build(); | ||
|
|
||
| UUID writerId = UUID.randomUUID(); | ||
|
|
||
| //when | ||
| Long commentId = createCommunityCommentService.CreateCommunityComment(dto, writerId, null); | ||
| Long commentId = createCommunityCommentService.createCommunityComment(dto, writerId); | ||
|
|
||
| //then | ||
| Optional<CommunityComment> communityComment = communityCommentRepository.findById(commentId); | ||
|
|
@@ -50,27 +55,53 @@ void createCommunityCommentWithDto() { | |
| assertThat(communityComment.get().getParentCommentId()).isNull(); | ||
| } | ||
|
|
||
| @DisplayName("커뮤니티 게시글에 대댓글을 등록한다.") | ||
| @DisplayName("댓글에 대댓글을 등록한다.") | ||
| @Test | ||
| void createCommunityCommenReplytWithDto() { | ||
| void createCommunityCommentRelyWithDto() { | ||
|
|
||
| //given | ||
| CommunityCommentCreateRequestDto dto = CommunityCommentCreateRequestDto.builder() | ||
| CommunityCommentCreateRequestDto commentDto = CommunityCommentCreateRequestDto.builder() | ||
| .content("커뮤니티 댓글 테스트 내용") | ||
| .parentCommentId(null) | ||
| .build(); | ||
|
|
||
| UUID writerId = UUID.randomUUID(); | ||
| Long commentId = createCommunityCommentService.createCommunityComment(commentDto, writerId); | ||
|
|
||
| CommunityCommentCreateRequestDto replyDto = CommunityCommentCreateRequestDto.builder() | ||
| .content("커뮤니티 대댓글 테스트 내용") | ||
| .parentCommentId(commentId) | ||
| .build(); | ||
|
|
||
| //when | ||
| Long commentId = createCommunityCommentService.CreateCommunityComment(dto, writerId, 2L); | ||
| Long replyCommentId = createCommunityCommentService.createCommunityComment(replyDto, writerId); | ||
|
|
||
| //then | ||
| Optional<CommunityComment> communityComment = communityCommentRepository.findById(commentId); | ||
| Optional<CommunityComment> communityCommentReply = communityCommentRepository.findById(replyCommentId); | ||
|
|
||
| assertThat(communityComment).isPresent(); | ||
| assertThat(communityComment.get().getId()).isEqualTo(commentId); | ||
| assertThat(communityComment.get().getWriterId()).isEqualTo(writerId); | ||
| assertThat(communityComment.get().getContent()).isEqualTo("커뮤니티 댓글 테스트 내용"); | ||
| assertThat(communityComment.get().getParentCommentId()).isEqualTo(2L); | ||
| assertThat(communityCommentReply).isPresent(); | ||
| assertThat(communityCommentReply.get().getId()).isEqualTo(replyCommentId); | ||
| assertThat(communityCommentReply.get().getWriterId()).isEqualTo(writerId); | ||
| assertThat(communityCommentReply.get().getContent()).isEqualTo("커뮤니티 대댓글 테스트 내용"); | ||
| assertThat(communityCommentReply.get().getParentCommentId()).isEqualTo(commentId); | ||
| } | ||
|
|
||
| @DisplayName("삭제된 댓글에 대댓글을 등록할 때 예외를 던진다.") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다 |
||
| @Test | ||
| void createCommunityCommentRelyWithDeletedParentId() { | ||
|
||
|
|
||
| //given | ||
| CommunityCommentCreateRequestDto replyDto = CommunityCommentCreateRequestDto.builder() | ||
| .content("커뮤니티 대댓글 테스트 내용") | ||
| .parentCommentId(2L) | ||
| .build(); | ||
|
|
||
| //when | ||
| ThrowableAssert.ThrowingCallable callable = () -> createCommunityCommentService.createCommunityComment(replyDto, UUID.randomUUID()); | ||
|
|
||
| //then | ||
| assertThatExceptionOfType(BadRequestException.class) | ||
| .isThrownBy(callable) | ||
| .withMessage(ExceptionMessage.NOT_EXISTS_COMMUNITY_COMMENT.getMessage()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
억지스러운 예외일수도 있지만 대댓글 작성중에 댓글이 삭제될수도 있다는 생각이 들었습니다
관련 예외도 테스트해보면 좋지 않을까... 생각만 해봤습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
삭제된 댓글에는 대댓글을 달지 못하는 게 맞는 거 같아요.
그 부분 추가했습니다!