Skip to content

Commit

Permalink
[#63] test: 본인확인 인증 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeuk520 committed Oct 16, 2024
1 parent ccdbe5f commit 5623c87
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 8 deletions.
71 changes: 65 additions & 6 deletions src/test/java/com/ku/covigator/controller/AuthControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void findPassword() throws Exception {
FindPasswordRequest request = new FindPasswordRequest("covi@naver.com");

//when //then
mockMvc.perform(post("/accounts/find-password")
mockMvc.perform(post("/accounts/find-password/send-email")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
).andDo(print())
Expand All @@ -154,15 +154,53 @@ void findPassword() throws Exception {
);
}

@DisplayName(" 이메일 인증번호 입력을 잘못하는 경우 상태코드 400을 반환한다..")
@DisplayName("이메일 찾기 요청 - 문자 본인 확인")
@Test
void writeWrongVerificationCode() throws Exception {
void findEmail() throws Exception {
//given
SmsRequest request = new SmsRequest("01012341234");

//when //then
mockMvc.perform(post("/accounts/find-email/send-message")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
).andDo(print())
.andExpect(
status().isOk()
);
}

@DisplayName(" 이메일 인증번호 입력을 잘못하는 경우 상태코드 400을 반환한다.")
@Test
void writeWrongVerificationEmailCode() throws Exception {
//given
VerifyEmailCodeRequest request = new VerifyEmailCodeRequest("covi@naver.com", "abcd");
BDDMockito.given(redisUtil.getData(any())).willReturn("");


//when //then
mockMvc.perform(post("/accounts/verify-code")
mockMvc.perform(post("/accounts/find-password/verify-code")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
).andDo(print())
.andExpect(
status().isBadRequest()
);
}

@DisplayName("본인확인 인증번호 입력을 잘못하는 경우 상태코드 400을 반환한다.")
@Test
void writeWrongVerificationSmsCode() throws Exception {
//given
VerifySmsCodeRequest request = new VerifySmsCodeRequest("abcd");
BDDMockito.given(redisUtil.getData(any())).willReturn("");

given(jwtAuthArgumentResolver.resolveArgument(any(), any(), any(), any()))
.willReturn(1L);
given(jwtAuthArgumentResolver.supportsParameter(any())).willReturn(true);

//when //then
mockMvc.perform(post("/accounts/find-email/verify-code")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
).andDo(print())
Expand All @@ -173,13 +211,34 @@ void writeWrongVerificationCode() throws Exception {

@DisplayName("이메일 인증번호 입력에 성공한다.")
@Test
void writeRightVerificationCode() throws Exception {
void writeRightVerificationEmailCode() throws Exception {
//given
VerifyEmailCodeRequest request = new VerifyEmailCodeRequest("covi@naver.com", "abcd");
BDDMockito.given(redisUtil.getData(any())).willReturn("abcd");

//when //then
mockMvc.perform(post("/accounts/verify-code")
mockMvc.perform(post("/accounts/find-password/verify-code")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
).andDo(print())
.andExpect(
status().isOk()
);
}

@DisplayName("문자 본인확인 인증번호 입력에 성공한다.")
@Test
void writeRightVerificationSmsCode() throws Exception {
//given
VerifySmsCodeRequest request = new VerifySmsCodeRequest("abcd");
BDDMockito.given(redisUtil.getData(any())).willReturn("abcd");

given(jwtAuthArgumentResolver.resolveArgument(any(), any(), any(), any()))
.willReturn(1L);
given(jwtAuthArgumentResolver.supportsParameter(any())).willReturn(true);

//when //then
mockMvc.perform(post("/accounts/find-email/verify-code")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
).andDo(print())
Expand Down
32 changes: 30 additions & 2 deletions src/test/java/com/ku/covigator/service/AuthServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ void notFoundEmailExceptionOccursWhenMemberIsNotRegistered() {
).isInstanceOf(NotFoundEmailException.class);
}

@DisplayName("인증번호 생성시 Redis에 인증번호가 정상적으로 저장된다.")
@DisplayName("[이메일] 인증번호 생성시 Redis에 인증번호가 정상적으로 저장된다.")
@Test
void verificationCodeSavedInRedis() {
void emailVerificationCodeSavedInRedis() {
//given
String email = "covi@naver.com";
Member member = Member.builder()
Expand Down Expand Up @@ -457,4 +457,32 @@ void reissueToken() {
assertThat(response.accessToken()).isNotNull();
}

@DisplayName("존재하지 않는 회원에 대한 인증 번호 문자 전송 요청은 실패한다.")
@Test
void sendSmsFailForMemberNotExists() {
//when //then
assertThatThrownBy(() -> authService.sendMessage(1L, "01012341234"))
.isInstanceOf(NotFoundMemberException.class);
}

@DisplayName("[문자] 인증번호 생성시 Redis에 인증번호가 정상적으로 저장된다.")
@Test
void smsVerificationCodeSavedInRedis() {
//given
Member member = Member.builder()
.password("covigator123")
.nickname("covi")
.imageUrl("www.covi.com")
.platform(Platform.LOCAL)
.build();
Member savedMember = memberRepository.save(member);
Long memberId = savedMember.getId();

//when
authService.sendMessage(memberId, "01012341234");

//then
assertThat(redisUtil.existData(memberId.toString())).isTrue();
}

}

0 comments on commit 5623c87

Please sign in to comment.