|
| 1 | +package com.somemore.community.service.comment; |
| 2 | + |
| 3 | +import com.somemore.IntegrationTestSupport; |
| 4 | +import com.somemore.community.domain.CommunityComment; |
| 5 | +import com.somemore.community.dto.request.CommunityCommentCreateRequestDto; |
| 6 | +import com.somemore.community.repository.comment.CommunityCommentRepository; |
| 7 | +import org.junit.jupiter.api.AfterEach; |
| 8 | +import org.junit.jupiter.api.DisplayName; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; |
| 11 | + |
| 12 | +import java.util.Optional; |
| 13 | +import java.util.UUID; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | + |
| 17 | +public class CreateCommunityCommentServiceTest extends IntegrationTestSupport { |
| 18 | + |
| 19 | + @Autowired |
| 20 | + private CreateCommunityCommentService createCommunityCommentService; |
| 21 | + @Autowired |
| 22 | + private CommunityCommentRepository communityCommentRepository; |
| 23 | + |
| 24 | + @AfterEach |
| 25 | + void tearDown() { |
| 26 | + communityCommentRepository.deleteAllInBatch(); |
| 27 | + } |
| 28 | + |
| 29 | + @DisplayName("커뮤니티 게시글에 댓글을 등록한다.") |
| 30 | + @Test |
| 31 | + void createCommunityCommentWithDto() { |
| 32 | + |
| 33 | + //given |
| 34 | + CommunityCommentCreateRequestDto dto = CommunityCommentCreateRequestDto.builder() |
| 35 | + .content("커뮤니티 댓글 테스트 내용") |
| 36 | + .build(); |
| 37 | + |
| 38 | + UUID writerId = UUID.randomUUID(); |
| 39 | + |
| 40 | + //when |
| 41 | + Long commentId = createCommunityCommentService.CreateCommunityComment(dto, writerId, null); |
| 42 | + |
| 43 | + //then |
| 44 | + Optional<CommunityComment> communityComment = communityCommentRepository.findById(commentId); |
| 45 | + |
| 46 | + assertThat(communityComment).isPresent(); |
| 47 | + assertThat(communityComment.get().getId()).isEqualTo(commentId); |
| 48 | + assertThat(communityComment.get().getWriterId()).isEqualTo(writerId); |
| 49 | + assertThat(communityComment.get().getContent()).isEqualTo("커뮤니티 댓글 테스트 내용"); |
| 50 | + assertThat(communityComment.get().getParentCommentId()).isNull(); |
| 51 | + } |
| 52 | + |
| 53 | + @DisplayName("커뮤니티 게시글에 대댓글을 등록한다.") |
| 54 | + @Test |
| 55 | + void createCommunityCommenReplytWithDto() { |
| 56 | + |
| 57 | + //given |
| 58 | + CommunityCommentCreateRequestDto dto = CommunityCommentCreateRequestDto.builder() |
| 59 | + .content("커뮤니티 댓글 테스트 내용") |
| 60 | + .build(); |
| 61 | + |
| 62 | + UUID writerId = UUID.randomUUID(); |
| 63 | + |
| 64 | + //when |
| 65 | + Long commentId = createCommunityCommentService.CreateCommunityComment(dto, writerId, 2L); |
| 66 | + |
| 67 | + //then |
| 68 | + Optional<CommunityComment> communityComment = communityCommentRepository.findById(commentId); |
| 69 | + |
| 70 | + assertThat(communityComment).isPresent(); |
| 71 | + assertThat(communityComment.get().getId()).isEqualTo(commentId); |
| 72 | + assertThat(communityComment.get().getWriterId()).isEqualTo(writerId); |
| 73 | + assertThat(communityComment.get().getContent()).isEqualTo("커뮤니티 댓글 테스트 내용"); |
| 74 | + assertThat(communityComment.get().getParentCommentId()).isEqualTo(2L); |
| 75 | + } |
| 76 | +} |
0 commit comments