@@ -583,7 +583,7 @@ void deleteComment_noToken() throws Exception {
583583 .andExpect (jsonPath ("$.message" ).value ("인증이 필요합니다." ));
584584 }
585585
586- // ====================== 대댓글 생성 테스트 ======================
586+ // ====================== 대댓글 테스트 ======================
587587
588588 @ Test
589589 @ DisplayName ("대댓글 생성 성공 → 201 Created" )
@@ -825,4 +825,60 @@ void createReply_noToken() throws Exception {
825825 .andExpect (jsonPath ("$.code" ).value ("AUTH_001" ))
826826 .andExpect (jsonPath ("$.message" ).value ("인증이 필요합니다." ));
827827 }
828+
829+ @ Test
830+ @ DisplayName ("대댓글 수정 성공 → 200 OK" )
831+ void updateReply_success () throws Exception {
832+ // given
833+ User user =
User .
createUser (
"writer" ,
"[email protected] " ,
passwordEncoder .
encode (
"P@ssw0rd!" ));
834+ user .setUserProfile (new UserProfile (user , "이몽룡" , null , null , null , 0 ));
835+ user .setUserStatus (UserStatus .ACTIVE );
836+ userRepository .save (user );
837+
838+ Post post = new Post (user , "제목" , "내용" );
839+ postRepository .save (post );
840+
841+ Comment parent = new Comment (post , user , "부모 댓글" , null );
842+ Comment reply = new Comment (post , user , "대댓글" , parent );
843+ commentRepository .saveAll (List .of (parent , reply ));
844+
845+ String accessToken = generateAccessToken (user );
846+ CommentRequest request = new CommentRequest ("수정된 대댓글 내용" );
847+
848+ // when & then
849+ mvc .perform (put ("/api/posts/{postId}/comments/{commentId}" , post .getId (), reply .getId ())
850+ .header ("Authorization" , "Bearer " + accessToken )
851+ .contentType (MediaType .APPLICATION_JSON )
852+ .content (objectMapper .writeValueAsString (request )))
853+ .andDo (print ())
854+ .andExpect (status ().isOk ())
855+ .andExpect (jsonPath ("$.data.content" ).value ("수정된 대댓글 내용" ));
856+ }
857+
858+ @ Test
859+ @ DisplayName ("대댓글 삭제 성공 → 200 OK" )
860+ void deleteReply_success () throws Exception {
861+ // given
862+ User user =
User .
createUser (
"writer" ,
"[email protected] " ,
passwordEncoder .
encode (
"P@ssw0rd!" ));
863+ user .setUserProfile (new UserProfile (user , "이몽룡" , null , null , null , 0 ));
864+ user .setUserStatus (UserStatus .ACTIVE );
865+ userRepository .save (user );
866+
867+ Post post = new Post (user , "제목" , "내용" );
868+ postRepository .save (post );
869+
870+ Comment parent = new Comment (post , user , "부모 댓글" , null );
871+ Comment reply = new Comment (post , user , "대댓글" , parent );
872+ commentRepository .saveAll (List .of (parent , reply ));
873+
874+ String accessToken = generateAccessToken (user );
875+
876+ // when & then
877+ mvc .perform (delete ("/api/posts/{postId}/comments/{commentId}" , post .getId (), reply .getId ())
878+ .header ("Authorization" , "Bearer " + accessToken ))
879+ .andDo (print ())
880+ .andExpect (status ().isOk ())
881+ .andExpect (jsonPath ("$.success" ).value (true ))
882+ .andExpect (jsonPath ("$.message" ).value ("댓글이 삭제되었습니다." ));
883+ }
828884}
0 commit comments