@@ -812,4 +812,73 @@ void recoverUsername_missingField() throws Exception {
812812 .andExpect (jsonPath ("$.code" ).value ("COMMON_400" ))
813813 .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ));
814814 }
815+
816+ // ======================== 비밀번호 재설정 요청 컨트롤러 테스트 ========================
817+
818+ @ Test
819+ @ DisplayName ("정상 비밀번호 재설정 요청 → 200 OK" )
820+ void recoverPassword_success () throws Exception {
821+ // given: 가입된 사용자 생성
822+ User user =
User .
createUser (
"pwuser" ,
"[email protected] " ,
passwordEncoder .
encode (
"P@ssw0rd!" ));
823+ user .setUserProfile (new UserProfile (user , "닉네임" , null , null , null , 0 ));
824+ userRepository .save (user );
825+
826+ String body = """
827+ {
828+ 829+ }
830+ """ ;
831+
832+ // when & then
833+ mvc .perform (post ("/api/auth/password/recover" )
834+ .contentType (MediaType .APPLICATION_JSON )
835+ .content (body ))
836+ .andDo (print ())
837+ .andExpect (status ().isOk ())
838+ .andExpect (jsonPath ("$.success" ).value (true ))
839+ .andExpect (jsonPath ("$.code" ).value ("SUCCESS_200" ))
840+ .andExpect (jsonPath ("$.message" ).value ("비밀번호 재설정 링크를 이메일로 전송했습니다." ))
841+ .andExpect (jsonPath ("$.data" ).isEmpty ());
842+ }
843+
844+ @ Test
845+ @ DisplayName ("비밀번호 재설정 요청 실패 - 존재하지 않는 사용자 → 404 Not Found" )
846+ void recoverPassword_userNotFound () throws Exception {
847+ // given: 존재하지 않는 이메일 사용
848+ String body = """
849+ {
850+ 851+ }
852+ """ ;
853+
854+ // when & then
855+ mvc .perform (post ("/api/auth/password/recover" )
856+ .contentType (MediaType .APPLICATION_JSON )
857+ .content (body ))
858+ .andDo (print ())
859+ .andExpect (status ().isNotFound ())
860+ .andExpect (jsonPath ("$.success" ).value (false ))
861+ .andExpect (jsonPath ("$.code" ).value ("USER_001" ))
862+ .andExpect (jsonPath ("$.message" ).value ("존재하지 않는 사용자입니다." ));
863+ }
864+
865+ @ Test
866+ @ DisplayName ("비밀번호 재설정 요청 실패 - 이메일 필드 누락 → 400 Bad Request" )
867+ void recoverPassword_missingField () throws Exception {
868+ // given: 잘못된 요청 (이메일 필드 없음)
869+ String body = """
870+ {
871+ }
872+ """ ;
873+
874+ // when & then
875+ mvc .perform (post ("/api/auth/password/recover" )
876+ .contentType (MediaType .APPLICATION_JSON )
877+ .content (body ))
878+ .andDo (print ())
879+ .andExpect (status ().isBadRequest ())
880+ .andExpect (jsonPath ("$.success" ).value (false ))
881+ .andExpect (jsonPath ("$.code" ).value ("COMMON_400" ))
882+ .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ));
883+ }
815884}
0 commit comments