@@ -295,4 +295,173 @@ void t12() throws Exception {
295295
296296 result .andExpect (status ().is4xxClientError ());
297297 }
298+
299+ @ Test
300+ @ DisplayName ("관리자 회원 목록 조회 성공 - 기본 페이징" )
301+ @ WithMockUser (roles = "ADMIN" )
302+ void t13 () throws Exception {
303+ // 테스트용 회원 3명 생성
304+ memberService .
joinMentee (
"[email protected] " ,
"멘티1" ,
"멘티닉네임1" ,
"password123" ,
"Backend" );
305+ memberService .
joinMentor (
"[email protected] " ,
"멘토1" ,
"멘토닉네임1" ,
"password123" ,
"Frontend" ,
3 );
306+ memberService .
joinMentee (
"[email protected] " ,
"멘티2" ,
"멘티닉네임2" ,
"password123" ,
"AI/ML" );
307+
308+ // 관리자가 회원 목록 조회 (기본값: page=0, size=10)
309+ ResultActions result = mvc
310+ .perform (get ("/members" ))
311+ .andDo (print ());
312+
313+ result
314+ .andExpect (handler ().handlerType (AdmMemberController .class ))
315+ .andExpect (handler ().methodName ("getAllMembers" ))
316+ .andExpect (status ().isOk ())
317+ .andExpect (jsonPath ("$.resultCode" ).value ("200-18" ))
318+ .andExpect (jsonPath ("$.msg" ).value ("회원 목록 조회 성공" ))
319+ .andExpect (jsonPath ("$.data.members" ).isArray ())
320+ .andExpect (jsonPath ("$.data.totalElements" ).exists ())
321+ .andExpect (jsonPath ("$.data.totalPage" ).exists ())
322+ .andExpect (jsonPath ("$.data.currentPage" ).value (0 ))
323+ .andExpect (jsonPath ("$.data.hasNext" ).exists ());
324+ }
325+
326+ @ Test
327+ @ DisplayName ("관리자 회원 목록 조회 성공 - 커스텀 페이징" )
328+ @ WithMockUser (roles = "ADMIN" )
329+ void t14 () throws Exception {
330+ // 테스트용 회원 5명 생성
331+ memberService .
joinMentee (
"[email protected] " ,
"유저1" ,
"닉네임1" ,
"password123" ,
"Backend" );
332+ memberService .
joinMentee (
"[email protected] " ,
"유저2" ,
"닉네임2" ,
"password123" ,
"Frontend" );
333+ memberService .
joinMentor (
"[email protected] " ,
"유저3" ,
"닉네임3" ,
"password123" ,
"Backend" ,
2 );
334+ memberService .
joinMentor (
"[email protected] " ,
"유저4" ,
"닉네임4" ,
"password123" ,
"AI/ML" ,
5 );
335+ memberService .
joinMentee (
"[email protected] " ,
"유저5" ,
"닉네임5" ,
"password123" ,
"DevOps" );
336+
337+ // 페이지 크기 2로 첫 페이지 조회
338+ ResultActions result = mvc
339+ .perform (get ("/members" )
340+ .param ("page" , "0" )
341+ .param ("size" , "2" ))
342+ .andDo (print ());
343+
344+ result
345+ .andExpect (status ().isOk ())
346+ .andExpect (jsonPath ("$.resultCode" ).value ("200-18" ))
347+ .andExpect (jsonPath ("$.data.members" ).isArray ())
348+ .andExpect (jsonPath ("$.data.currentPage" ).value (0 ))
349+ .andExpect (jsonPath ("$.data.members.length()" ).value (2 ));
350+ }
351+
352+ @ Test
353+ @ DisplayName ("관리자 회원 목록 조회 - 두 번째 페이지" )
354+ @ WithMockUser (roles = "ADMIN" )
355+ void t15 () throws Exception {
356+ // 테스트용 회원 5명 생성
357+ memberService .
joinMentee (
"[email protected] " ,
"페이지유저1" ,
"페이지닉네임1" ,
"password123" ,
"Backend" );
358+ memberService .
joinMentee (
"[email protected] " ,
"페이지유저2" ,
"페이지닉네임2" ,
"password123" ,
"Frontend" );
359+ memberService .
joinMentor (
"[email protected] " ,
"페이지유저3" ,
"페이지닉네임3" ,
"password123" ,
"Backend" ,
3 );
360+ memberService .
joinMentor (
"[email protected] " ,
"페이지유저4" ,
"페이지닉네임4" ,
"password123" ,
"AI/ML" ,
4 );
361+ memberService .
joinMentee (
"[email protected] " ,
"페이지유저5" ,
"페이지닉네임5" ,
"password123" ,
"DevOps" );
362+
363+ // 페이지 크기 2로 두 번째 페이지 조회
364+ ResultActions result = mvc
365+ .perform (get ("/members" )
366+ .param ("page" , "1" )
367+ .param ("size" , "2" ))
368+ .andDo (print ());
369+
370+ result
371+ .andExpect (status ().isOk ())
372+ .andExpect (jsonPath ("$.resultCode" ).value ("200-18" ))
373+ .andExpect (jsonPath ("$.data.members" ).isArray ())
374+ .andExpect (jsonPath ("$.data.currentPage" ).value (1 ));
375+ }
376+
377+ @ Test
378+ @ DisplayName ("관리자 회원 목록 조회 - 기본 정보만 포함 확인" )
379+ @ WithMockUser (roles = "ADMIN" )
380+ void t16 () throws Exception {
381+ // 멘토와 멘티 생성
382+ memberService .
joinMentor (
"[email protected] " ,
"멘토유저" ,
"멘토닉네임" ,
"password123" ,
"Backend" ,
5 );
383+ memberService .
joinMentee (
"[email protected] " ,
"멘티유저" ,
"멘티닉네임" ,
"password123" ,
"Frontend" );
384+
385+ // 회원 목록 조회
386+ ResultActions result = mvc
387+ .perform (get ("/members" )
388+ .param ("size" , "10" ))
389+ .andDo (print ());
390+
391+ result
392+ .andExpect (status ().isOk ())
393+ .andExpect (jsonPath ("$.data.members" ).isArray ())
394+ // 기본 정보만 포함되어야 함
395+ .andExpect (jsonPath ("$.data.members[0].id" ).exists ())
396+ .andExpect (jsonPath ("$.data.members[0].email" ).exists ())
397+ .andExpect (jsonPath ("$.data.members[0].name" ).exists ())
398+ .andExpect (jsonPath ("$.data.members[0].nickname" ).exists ())
399+ .andExpect (jsonPath ("$.data.members[0].role" ).exists ())
400+ .andExpect (jsonPath ("$.data.members[0].isDeleted" ).exists ())
401+ .andExpect (jsonPath ("$.data.members[0].createdAt" ).exists ());
402+ }
403+
404+ @ Test
405+ @ DisplayName ("관리자 회원 목록 조회 - 삭제된 회원도 포함" )
406+ @ WithMockUser (roles = "ADMIN" )
407+ void t17 () throws Exception {
408+ // 회원 생성 후 삭제
409+ Member member =
memberService .
joinMentee (
"[email protected] " ,
"삭제될유저" ,
"삭제될닉네임" ,
"password123" ,
"Backend" );
410+ memberService .deleteMemberByAdmin (member .getId ());
411+
412+ // 회원 목록 조회 (삭제된 회원도 포함되어야 함)
413+ ResultActions result = mvc
414+ .perform (get ("/members" ))
415+ .andDo (print ());
416+
417+ result
418+ .andExpect (status ().isOk ())
419+ .andExpect (jsonPath ("$.resultCode" ).value ("200-18" ))
420+ .andExpect (jsonPath ("$.data.members" ).isArray ())
421+ .
andExpect (
jsonPath (
"$.data.members[?(@.email == '[email protected] ')].isDeleted" ).
value (
true ));
422+ }
423+
424+ @ Test
425+ @ DisplayName ("관리자가 아닌 사용자의 회원 목록 조회 시도 - 실패" )
426+ @ WithMockUser (roles = "MENTEE" )
427+ void t18 () throws Exception {
428+ // 일반 사용자가 회원 목록 조회 시도
429+ ResultActions result = mvc
430+ .perform (get ("/members" ))
431+ .andDo (print ());
432+
433+ result .andExpect (status ().isForbidden ()); // 403 Forbidden 예상
434+ }
435+
436+ @ Test
437+ @ DisplayName ("로그인하지 않은 상태에서 회원 목록 조회 시도 - 실패" )
438+ void t19 () throws Exception {
439+ // 인증 없이 회원 목록 조회 시도
440+ ResultActions result = mvc
441+ .perform (get ("/members" ))
442+ .andDo (print ());
443+
444+ result .andExpect (status ().is4xxClientError ());
445+ }
446+
447+ @ Test
448+ @ DisplayName ("관리자 회원 목록 조회 - 생성일 역순 정렬 확인" )
449+ @ WithMockUser (roles = "ADMIN" )
450+ void t20 () throws Exception {
451+ // 시간 차이를 두고 회원 생성
452+ Member member1 =
memberService .
joinMentee (
"[email protected] " ,
"첫번째유저" ,
"첫번째닉네임" ,
"password123" ,
"Backend" );
453+ Thread .sleep (100 ); // 시간 차이를 위한 대기
454+ Member member2 =
memberService .
joinMentee (
"[email protected] " ,
"두번째유저" ,
"두번째닉네임" ,
"password123" ,
"Frontend" );
455+
456+ // 회원 목록 조회 (최신순 정렬)
457+ ResultActions result = mvc
458+ .perform (get ("/members" )
459+ .param ("size" , "10" ))
460+ .andDo (print ());
461+
462+ result
463+ .andExpect (status ().isOk ())
464+ .andExpect (jsonPath ("$.data.members" ).isArray ());
465+ // 최신 회원이 먼저 나와야 함 (createDate DESC)
466+ }
298467}
0 commit comments