Skip to content

Commit

Permalink
Merge pull request #206 from depromeet/feature/203-valid-email
Browse files Browse the repository at this point in the history
fix: 이메일 검증 시 + 문자 허용
  • Loading branch information
nature1216 authored May 14, 2023
2 parents 62791e2 + 4060fb0 commit 88dca35
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public void resetPasswordForAuthEmailSend(String email) {
throw new PostNotFoundException(ExceptionType.EMAIL_ALREADY_AUTHENTICATED.getMessage());
}

if(email.contains("+")) {
throw new PostNotFoundException("잘못된 이메일 형식입니다.");
}

String authToken = AuthTokenUtil.getAuthToken();

resetPasswordForAuthSendService.send(email, authToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Getter
Expand All @@ -22,4 +23,7 @@ public class ExtraInfoRequest {

@NotNull(message = "관심 직무는 필수 입력입니다.")
private String job;

@NotBlank(message = "이메일은 필수 입력입니다.")
private String email;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public ResultResponse checkNickName(String nickname) {
}

@Transactional
public void updateExtraInfo(String email, ExtraInfoRequest request) {
public void updateExtraInfo(ExtraInfoRequest request) {

Member member = memberRepository.findByEmail(email)
Member member = memberRepository.findByEmail(request.getEmail())
.orElseThrow(() -> new PostNotFoundException(ExceptionType.USER_NOT_EXISTS.getMessage()));

member.updateExtraInfo(request.getGender(), request.getAge(), request.getJob());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public ResultResponse<TokenResponse> signUp(@RequestBody @Valid SignUpRequest re
@PatchMapping("/extra-informations")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "사용자 추가 정보", notes = "사용자 추가 정보를 저장합니다.")
public void updateExtraInfo(@RequestBody @Valid ExtraInfoRequest request,
@RequestParam(value = "email") String email) {
public void updateExtraInfo(@RequestBody @Valid ExtraInfoRequest request) {

signupService.updateExtraInfo(email, request);
signupService.updateExtraInfo(request);
}

@GetMapping("/nicknames/{nickname}/exists")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,45 @@ void testAgeGroupIsNull() throws Exception {
.andExpect(status().isCreated());
// when
mockMvc.perform(patch("/api/v1/signup/extra-informations")
.queryParam("email", email)
.contentType(MediaType.APPLICATION_JSON)
.content("{\"gender\":\"ETC\",\"ageGroup\":null,\"job\":\"job\"}")
.content("{\"gender\":\"ETC\",\"ageGroup\":null,\"job\":\"job\",\"email\":\""+email+"\"}")
// then
).andExpect(status().isOk());
}

@DisplayName("회원가입 email 검증: email에 + 문자가 포함되어 있어도 성공한다.")
@Test
void signUpEmailValid() throws Exception {
// given
String email = "localpart+01@domain";
SendEmailRequest sendEmailRequest = new SendEmailRequest();
sendEmailRequest.setEmail(email);
doNothing().when(signUpEmailSendService).send(any(), any());
mockMvc.perform(
post("/api/v1/auth/sends-email/signup")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsBytes(sendEmailRequest)))
.andExpect(status().isCreated());
mockMvc.perform(
get("/api/v1/auth/email/signup")
.queryParam("email",email))
.andExpect(status().isFound());
// when
SignUpRequest signUpRequest = new SignUpRequest();
signUpRequest.setEmail(email);
signUpRequest.setNickName("nickname");
signUpRequest.setPassword("password");
signUpRequest.setConfirmPassword("password");
mockMvc.perform(
post("/api/v1/signup")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsBytes(signUpRequest)))
// then 1
.andExpect(status().isCreated());
// then 2
Optional<Member> member = memberRepository.findByEmail(email);
assertThat(member).isPresent();
assertThat(member.get().getEmail()).isEqualTo(email);
assertThat(member.get().getNickname()).isEqualTo("nickname");
}
}

0 comments on commit 88dca35

Please sign in to comment.