Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6094c71
test(community): communityComment 생성 기능 테스트 작성
ayoung-dev Nov 28, 2024
4b666aa
feat(community): communityComment Entity, Repository 추가
ayoung-dev Nov 28, 2024
e087c0c
feat(community): communityComment 생성 RequestDto, Usecase 추가 및 Service 구현
ayoung-dev Nov 28, 2024
9a4c087
refactor(community): CommunityBoardRepository 네이밍 변경
ayoung-dev Nov 28, 2024
58038ee
refactor(community): community board/comment 폴더 구조 변경
ayoung-dev Nov 28, 2024
b686152
chore(community): 불필요한 import 및 public 키워드 제거
ayoung-dev Nov 28, 2024
0be3598
Feature/36 s3 이미지 업로드 기능 구현 (#66)
7zrv Nov 28, 2024
f68bb02
test(community): 커뮤니티 댓글 생성 테스트 추가
ayoung-dev Nov 28, 2024
f265514
chore(community): 소문자로 네이밍 변경
ayoung-dev Nov 28, 2024
10a0dbb
fix(community): 커뮤니티 댓글 생성 requestDto 수정
ayoung-dev Nov 28, 2024
3151a8b
feat(community): 커뮤니티 댓글 생성 예외 처리 및 메세지 추가
ayoung-dev Nov 28, 2024
21e7a2a
refactor(community): 코드 리뷰 사항 반영
ayoung-dev Nov 28, 2024
c5d8e3c
test(community): communityComment 생성 기능 테스트 작성
ayoung-dev Nov 28, 2024
dbaf67e
feat(community): communityComment Entity, Repository 추가
ayoung-dev Nov 28, 2024
3c306dc
feat(community): communityComment 생성 RequestDto, Usecase 추가 및 Service 구현
ayoung-dev Nov 28, 2024
f4a5f6b
refactor(community): CommunityBoardRepository 네이밍 변경
ayoung-dev Nov 28, 2024
0f23e4a
refactor(community): community board/comment 폴더 구조 변경
ayoung-dev Nov 28, 2024
b43a5e6
chore(community): 불필요한 import 및 public 키워드 제거
ayoung-dev Nov 28, 2024
7835bb2
test(community): 커뮤니티 댓글 생성 테스트 추가
ayoung-dev Nov 28, 2024
6c0def6
chore(community): 소문자로 네이밍 변경
ayoung-dev Nov 28, 2024
62aa1e5
fix(community): 커뮤니티 댓글 생성 requestDto 수정
ayoung-dev Nov 28, 2024
01656ce
feat(community): 커뮤니티 댓글 생성 예외 처리 및 메세지 추가
ayoung-dev Nov 28, 2024
b12b771
refactor(community): 코드 리뷰 사항 반영
ayoung-dev Nov 28, 2024
27a199a
Merge remote-tracking branch 'origin/feature/65-add-community-comment…
ayoung-dev Nov 28, 2024
d1caba6
feat(community): 커뮤니티 댓글 존재 여부 메서드 및 테스트 추가
ayoung-dev Nov 28, 2024
f7d3478
chore(community): 불필요한 import 제거
ayoung-dev Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -38,7 +40,7 @@ void createCommunityComment() {
assertThat(savedComment.getParentCommentId()).isNull();
}

@DisplayName("커뮤니티 게시글에 대댓글을 생성할 수 있다. (Repository)")
@DisplayName("댓글에 대댓글을 생성할 수 있다. (Repository)")
@Test
void createCommunityCommentReply() {

Expand All @@ -59,4 +61,29 @@ void createCommunityCommentReply() {
assertThat(savedComment.getContent()).isEqualTo("커뮤니티 댓글 테스트 내용");
assertThat(savedComment.getParentCommentId()).isEqualTo(1L);
}

@DisplayName("댓글을 id로 조회할 수 있다. (Repository)")
@Test
void findCommunityCommentById() {

//given
UUID writerId = UUID.randomUUID();

CommunityComment communityComment = CommunityComment.builder()
.writerId(writerId)
.content("커뮤니티 댓글 테스트 내용")
.parentCommentId(null)
.build();

CommunityComment savedComment = communityCommentRepository.save(communityComment);

//when
Optional<CommunityComment> comment = communityCommentRepository.findById(savedComment.getId());

//then
assertThat(comment).isPresent();
assertThat(comment.get().getWriterId()).isEqualTo(writerId);
assertThat(comment.get().getContent()).isEqualTo("커뮤니티 댓글 테스트 내용");
assertThat(comment.get().getParentCommentId()).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

억지스러운 예외일수도 있지만 대댓글 작성중에 댓글이 삭제될수도 있다는 생각이 들었습니다
관련 예외도 테스트해보면 좋지 않을까... 생각만 해봤습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제된 댓글에는 대댓글을 달지 못하는 게 맞는 거 같아요.
그 부분 추가했습니다!


Expand All @@ -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);
Expand All @@ -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("삭제된 댓글에 대댓글을 등록할 때 예외를 던진다.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다

@Test
void createCommunityCommentRelyWithDeletedParentId() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rely -> Reply 오타 있어요~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와우 수정했습니다


//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());
}
}