22
33import com .somemore .IntegrationTestSupport ;
44import com .somemore .community .domain .CommunityComment ;
5+ import com .somemore .community .dto .request .CommunityBoardCreateRequestDto ;
56import com .somemore .community .dto .request .CommunityCommentCreateRequestDto ;
67import com .somemore .community .repository .comment .CommunityCommentRepository ;
8+ import com .somemore .community .usecase .board .CreateCommunityBoardUseCase ;
9+ import com .somemore .community .usecase .board .DeleteCommunityBoardUseCase ;
710import com .somemore .global .exception .BadRequestException ;
811import com .somemore .global .exception .ExceptionMessage ;
912import org .assertj .core .api .ThrowableAssert ;
1013import org .junit .jupiter .api .AfterEach ;
14+ import org .junit .jupiter .api .BeforeEach ;
1115import org .junit .jupiter .api .DisplayName ;
1216import org .junit .jupiter .api .Test ;
1317import org .springframework .beans .factory .annotation .Autowired ;
@@ -24,6 +28,25 @@ class CreateCommunityCommentServiceTest extends IntegrationTestSupport {
2428 private CreateCommunityCommentService createCommunityCommentService ;
2529 @ Autowired
2630 private CommunityCommentRepository communityCommentRepository ;
31+ @ Autowired
32+ private CreateCommunityBoardUseCase createCommunityBoardUseCase ;
33+ @ Autowired
34+ private DeleteCommunityBoardUseCase deleteCommunityBoardUseCase ;
35+
36+ private UUID writerId ;
37+ private Long boardId ;
38+
39+ @ BeforeEach
40+ void setUp () {
41+ CommunityBoardCreateRequestDto boardDto = CommunityBoardCreateRequestDto .builder ()
42+ .title ("커뮤니티 테스트 제목" )
43+ .content ("커뮤니티 테스트 내용" )
44+ .build ();
45+
46+ writerId = UUID .randomUUID ();
47+
48+ boardId = createCommunityBoardUseCase .createCommunityBoard (boardDto , writerId , null );
49+ }
2750
2851 @ AfterEach
2952 void tearDown () {
@@ -36,6 +59,7 @@ void createCommunityCommentWithDto() {
3659
3760 //given
3861 CommunityCommentCreateRequestDto dto = CommunityCommentCreateRequestDto .builder ()
62+ .communityBoardId (boardId )
3963 .content ("커뮤니티 댓글 테스트 내용" )
4064 .parentCommentId (null )
4165 .build ();
@@ -61,6 +85,7 @@ void createCommunityCommentRelyWithDto() {
6185
6286 //given
6387 CommunityCommentCreateRequestDto commentDto = CommunityCommentCreateRequestDto .builder ()
88+ .communityBoardId (boardId )
6489 .content ("커뮤니티 댓글 테스트 내용" )
6590 .parentCommentId (null )
6691 .build ();
@@ -69,6 +94,7 @@ void createCommunityCommentRelyWithDto() {
6994 Long commentId = createCommunityCommentService .createCommunityComment (commentDto , writerId );
7095
7196 CommunityCommentCreateRequestDto replyDto = CommunityCommentCreateRequestDto .builder ()
97+ .communityBoardId (boardId )
7298 .content ("커뮤니티 대댓글 테스트 내용" )
7399 .parentCommentId (commentId )
74100 .build ();
@@ -86,12 +112,13 @@ void createCommunityCommentRelyWithDto() {
86112 assertThat (communityCommentReply .get ().getParentCommentId ()).isEqualTo (commentId );
87113 }
88114
89- @ DisplayName ("삭제된 댓글에 대댓글을 등록할 때 예외를 던진다." )
115+ @ DisplayName ("삭제된 댓글이나 존재하지 않는 댓글에 대댓글을 등록할 때 예외를 던진다." )
90116 @ Test
91117 void createCommunityCommentReplyWithDeletedParentId () {
92118
93119 //given
94120 CommunityCommentCreateRequestDto replyDto = CommunityCommentCreateRequestDto .builder ()
121+ .communityBoardId (boardId )
95122 .content ("커뮤니티 대댓글 테스트 내용" )
96123 .parentCommentId (2L )
97124 .build ();
@@ -104,4 +131,26 @@ void createCommunityCommentReplyWithDeletedParentId() {
104131 .isThrownBy (callable )
105132 .withMessage (ExceptionMessage .NOT_EXISTS_COMMUNITY_COMMENT .getMessage ());
106133 }
134+
135+ @ DisplayName ("삭제된 게시글에 댓글을 등록할 때 예외를 던진다." )
136+ @ Test
137+ void createCommunityCommentWithDeletedBoardId () {
138+
139+ //given
140+ CommunityCommentCreateRequestDto commentDto = CommunityCommentCreateRequestDto .builder ()
141+ .communityBoardId (boardId )
142+ .content ("커뮤니티 댓글 테스트 내용" )
143+ .parentCommentId (null )
144+ .build ();
145+
146+ deleteCommunityBoardUseCase .deleteCommunityBoard (writerId , boardId );
147+
148+ //when
149+ ThrowableAssert .ThrowingCallable callable = () -> createCommunityCommentService .createCommunityComment (commentDto , UUID .randomUUID ());
150+
151+ //then
152+ assertThatExceptionOfType (BadRequestException .class )
153+ .isThrownBy (callable )
154+ .withMessage (ExceptionMessage .NOT_EXISTS_COMMUNITY_BOARD .getMessage ());
155+ }
107156}
0 commit comments