@@ -881,4 +881,106 @@ void recoverPassword_missingField() throws Exception {
881881 .andExpect (jsonPath ("$.code" ).value ("COMMON_400" ))
882882 .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ));
883883 }
884+
885+ // ======================== 비밀번호 재설정 컨트롤러 테스트 ========================
886+
887+ @ Test
888+ @ DisplayName ("정상 비밀번호 재설정 성공 → 200 OK" )
889+ void resetPassword_success () throws Exception {
890+ // given: 가입된 사용자
891+ User user = User .createUser ("resetuser" , "reset@example.com" , passwordEncoder .encode ("OldPass123!" ));
892+ user .setUserProfile (new UserProfile (user , "닉네임" , null , null , null , 0 ));
893+ userRepository .save (user );
894+
895+ String token = tokenService .createPasswordResetToken (user .getId ());
896+
897+ String body = """
898+ {
899+ "token": "%s",
900+ "newPassword": "NewPass123!"
901+ }
902+ """ .formatted (token );
903+
904+ // when & then
905+ mvc .perform (post ("/api/auth/password/reset" )
906+ .contentType (MediaType .APPLICATION_JSON )
907+ .content (body ))
908+ .andDo (print ())
909+ .andExpect (status ().isOk ())
910+ .andExpect (jsonPath ("$.success" ).value (true ))
911+ .andExpect (jsonPath ("$.code" ).value ("SUCCESS_200" ))
912+ .andExpect (jsonPath ("$.message" ).value ("비밀번호가 성공적으로 재설정되었습니다." ))
913+ .andExpect (jsonPath ("$.data" ).isEmpty ());
914+ }
915+
916+ @ Test
917+ @ DisplayName ("비밀번호 재설정 실패 - 유효하지 않은 토큰 → 401 Unauthorized" )
918+ void resetPassword_invalidToken () throws Exception {
919+ // given: 가입된 사용자
920+ String body = """
921+ {
922+ "token": "fake-token",
923+ "newPassword": "NewPass123!"
924+ }
925+ """ ;
926+
927+ // when & then
928+ mvc .perform (post ("/api/auth/password/reset" )
929+ .contentType (MediaType .APPLICATION_JSON )
930+ .content (body ))
931+ .andDo (print ())
932+ .andExpect (status ().isUnauthorized ())
933+ .andExpect (jsonPath ("$.success" ).value (false ))
934+ .andExpect (jsonPath ("$.code" ).value ("TOKEN_003" ))
935+ .andExpect (jsonPath ("$.message" ).value ("유효하지 않은 비밀번호 재설정 토큰입니다." ));
936+ }
937+
938+ @ Test
939+ @ DisplayName ("비밀번호 재설정 실패 - 비밀번호 정책 위반 → 400 Bad Request" )
940+ void resetPassword_invalidPassword () throws Exception {
941+ // given: 가입된 사용자 + 토큰
942+ User user = User .createUser ("resetuser2" , "reset2@example.com" , passwordEncoder .encode ("OldPass123!" ));
943+ user .setUserProfile (new UserProfile (user , "닉네임" , null , null , null , 0 ));
944+ userRepository .save (user );
945+
946+ String token = tokenService .createPasswordResetToken (user .getId ());
947+
948+ String body = """
949+ {
950+ "token": "%s",
951+ "newPassword": "weakpw"
952+ }
953+ """ .formatted (token );
954+
955+ // when & then
956+ mvc .perform (post ("/api/auth/password/reset" )
957+ .contentType (MediaType .APPLICATION_JSON )
958+ .content (body ))
959+ .andDo (print ())
960+ .andExpect (status ().isBadRequest ())
961+ .andExpect (jsonPath ("$.success" ).value (false ))
962+ .andExpect (jsonPath ("$.code" ).value ("USER_005" ))
963+ .andExpect (jsonPath ("$.message" ).value ("비밀번호는 최소 8자 이상, 숫자/특수문자를 포함해야 합니다." ));
964+ }
965+
966+ @ Test
967+ @ DisplayName ("비밀번호 재설정 실패 - 요청 필드 누락 → 400 Bad Request" )
968+ void resetPassword_missingField () throws Exception {
969+ // given: 잘못된 요청 (토큰 필드 누락)
970+ String body = """
971+ {
972+ "token": ""
973+ }
974+ """ ;
975+
976+ // when & then
977+ mvc .perform (post ("/api/auth/password/reset" )
978+ .contentType (MediaType .APPLICATION_JSON )
979+ .content (body ))
980+ .andDo (print ())
981+ .andExpect (status ().isBadRequest ())
982+ .andExpect (jsonPath ("$.success" ).value (false ))
983+ .andExpect (jsonPath ("$.code" ).value ("COMMON_400" ))
984+ .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ));
985+ }
884986}
0 commit comments