Skip to content

Commit 26a789f

Browse files
committed
test[jwt]: 로직 변경으로 인한 테스트 코드 수정
1 parent 8ef193e commit 26a789f

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

backend/src/test/java/com/ai/lawyer/domain/member/controller/MemberControllerTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,15 @@ void verifyPassword_Fail_NotLoggedIn() throws Exception {
680680
}
681681

682682
@Test
683-
@DisplayName("이메일 인증번호 검증 실패 - 로그인된 사용자 접근 차단")
684-
void verifyEmail_Fail_LoggedInUser() throws Exception {
683+
@DisplayName("이메일 인증번호 검증 성공 - 로그인된 사용자도 가능")
684+
void verifyEmail_Success_LoggedInUser() throws Exception {
685685
// given
686686
EmailVerifyCodeRequestDto requestDto = new EmailVerifyCodeRequestDto();
687687
requestDto.setLoginId("[email protected]");
688688
requestDto.setVerificationCode("123456");
689689

690+
given(memberService.verifyAuthCode("[email protected]", "123456")).willReturn(true);
691+
690692
// when and then - principal과 함께 요청 (로그인 상태)
691693
mockMvc.perform(post("/api/auth/verifyEmail")
692694
.with(csrf())
@@ -695,8 +697,11 @@ void verifyEmail_Fail_LoggedInUser() throws Exception {
695697
.contentType(MediaType.APPLICATION_JSON)
696698
.content(objectMapper.writeValueAsString(requestDto)))
697699
.andDo(print())
698-
.andExpect(status().isBadRequest());
700+
.andExpect(status().isOk())
701+
.andExpect(jsonPath("$.message").value("인증번호 검증 성공"))
702+
.andExpect(jsonPath("$.email").value("[email protected]"))
703+
.andExpect(jsonPath("$.success").value(true));
699704

700-
verify(memberService, never()).verifyAuthCode(anyString(), anyString());
705+
verify(memberService).verifyAuthCode("[email protected]", "123456");
701706
}
702707
}

backend/src/test/java/com/ai/lawyer/global/email/service/EmailAuthServiceTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,42 @@ void authenticationFlow_Success() {
236236
verify(valueOperations).set(successKey, "true", 5L, TimeUnit.MINUTES);
237237
verify(valueOperations).get(successKey);
238238
}
239+
240+
@Test
241+
@DisplayName("비밀번호 검증 성공 표시 저장")
242+
void markPasswordVerified_Success() {
243+
// given
244+
given(redisTemplate.opsForValue()).willReturn(valueOperations);
245+
doNothing().when(valueOperations).set(eq(successKey), eq("true"), eq(5L), eq(TimeUnit.MINUTES));
246+
247+
// when
248+
emailAuthService.markPasswordVerified(loginId);
249+
250+
// then
251+
verify(redisTemplate).opsForValue();
252+
verify(valueOperations).set(successKey, "true", 5L, TimeUnit.MINUTES);
253+
}
254+
255+
@Test
256+
@DisplayName("비밀번호 검증 성공 후 성공 상태 확인 플로우")
257+
void passwordVerificationFlow_Success() {
258+
// given
259+
given(redisTemplate.opsForValue()).willReturn(valueOperations);
260+
261+
// 1. 비밀번호 검증 성공 표시
262+
doNothing().when(valueOperations).set(eq(successKey), eq("true"), eq(5L), eq(TimeUnit.MINUTES));
263+
264+
// 2. 성공 상태 확인
265+
given(valueOperations.get(successKey)).willReturn("true");
266+
267+
// when
268+
emailAuthService.markPasswordVerified(loginId);
269+
boolean isVerified = emailAuthService.isEmailVerified(loginId);
270+
271+
// then
272+
assertThat(isVerified).isTrue();
273+
274+
verify(valueOperations).set(successKey, "true", 5L, TimeUnit.MINUTES);
275+
verify(valueOperations).get(successKey);
276+
}
239277
}

0 commit comments

Comments
 (0)