@@ -207,14 +207,73 @@ void createComment_noToken() throws Exception {
207207 .andExpect (jsonPath ("$.message" ).value ("인증이 필요합니다." ));
208208 }
209209
210+ // ====================== 댓글 조회 테스트 ======================
211+
212+ @ Test
213+ @ DisplayName ("댓글 목록 조회 성공 → 200 OK" )
214+ void getComments_success () throws Exception {
215+ // given
216+ User user =
User .
createUser (
"writer" ,
"[email protected] " ,
passwordEncoder .
encode (
"P@ssw0rd!" ));
217+ user .setUserProfile (new UserProfile (user , "홍길동" , null , null , null , 0 ));
218+ user .setUserStatus (UserStatus .ACTIVE );
219+ userRepository .save (user );
220+
221+ Post post = new Post (user , "제목" , "내용" );
222+ postRepository .save (post );
223+
224+ // 부모 댓글
225+ Comment parent = new Comment (post , user , "부모 댓글" , null );
226+ commentRepository .save (parent );
227+
228+ // 자식 댓글
229+ Comment child = new Comment (post , user , "자식 댓글" , parent );
230+ commentRepository .save (child );
231+
232+ String accessToken = generateAccessToken (user );
233+
234+ // when & then
235+ mvc .perform (get ("/api/posts/{postId}/comments" , post .getId ())
236+ .header ("Authorization" , "Bearer " + accessToken )
237+ .param ("page" , "0" )
238+ .param ("size" , "10" ))
239+ .andDo (print ())
240+ .andExpect (status ().isOk ())
241+ .andExpect (jsonPath ("$.success" ).value (true ))
242+ .andExpect (jsonPath ("$.code" ).value ("SUCCESS_200" ))
243+ .andExpect (jsonPath ("$.data.items[0].content" ).value ("부모 댓글" ))
244+ .andExpect (jsonPath ("$.data.items[0].children[0].content" ).value ("자식 댓글" ));
245+ }
246+
247+ @ Test
248+ @ DisplayName ("댓글 목록 조회 실패 - 존재하지 않는 게시글 → 404 Not Found" )
249+ void getComments_postNotFound () throws Exception {
250+ // given
251+ User user =
User .
createUser (
"ghost" ,
"[email protected] " ,
passwordEncoder .
encode (
"P@ssw0rd!" ));
252+ user .setUserProfile (new UserProfile (user , "유저" , null , null , null , 0 ));
253+ user .setUserStatus (UserStatus .ACTIVE );
254+ userRepository .save (user );
255+
256+ String accessToken = generateAccessToken (user );
257+
258+ // when & then
259+ mvc .perform (get ("/api/posts/{postId}/comments" , 999L )
260+ .header ("Authorization" , "Bearer " + accessToken )
261+ .param ("page" , "0" )
262+ .param ("size" , "10" ))
263+ .andDo (print ())
264+ .andExpect (status ().isNotFound ())
265+ .andExpect (jsonPath ("$.code" ).value ("POST_001" ))
266+ .andExpect (jsonPath ("$.message" ).value ("존재하지 않는 게시글입니다." ));
267+ }
268+
210269 // ====================== 댓글 수정 테스트 ======================
211270
212271 @ Test
213272 @ DisplayName ("댓글 수정 성공 → 200 OK" )
214273 void updateComment_success () throws Exception {
215274 // given: 유저 + 게시글 + 댓글
216275 User user =
User .
createUser (
"writer" ,
"[email protected] " ,
passwordEncoder .
encode (
"P@ssw0rd!" ));
217- user .setUserProfile (new UserProfile (user , "홍길동" , null , "소개글" , LocalDate .of (2000 ,1 , 1 ), 1000 ));
276+ user .setUserProfile (new UserProfile (user , "홍길동" , null , "소개글" , LocalDate .of (2000 , 1 , 1 ), 1000 ));
218277 user .setUserStatus (UserStatus .ACTIVE );
219278 userRepository .save (user );
220279
@@ -390,6 +449,7 @@ void updateComment_noToken() throws Exception {
390449 .andExpect (jsonPath ("$.code" ).value ("AUTH_001" ))
391450 .andExpect (jsonPath ("$.message" ).value ("인증이 필요합니다." ));
392451 }
452+
393453 // ====================== 댓글 삭제 테스트 ======================
394454
395455 @ Test
0 commit comments