-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat-be: 이메일 인증 후, 회원가입 이메일의 인증 여부 확인 (#882)
Co-authored-by: Kwoun Ki Ho <[email protected]>
- Loading branch information
Showing
8 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/cruru/email/exception/NotVerifiedEmailException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.cruru.email.exception; | ||
|
||
import com.cruru.advice.UnauthorizedException; | ||
|
||
public class NotVerifiedEmailException extends UnauthorizedException { | ||
|
||
private static final String MESSAGE = "이메일 인증이 필요합니다."; | ||
|
||
public NotVerifiedEmailException() { | ||
super(MESSAGE); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
backend/src/main/java/com/cruru/email/service/VerificationStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.cruru.email.service; | ||
|
||
import java.util.Arrays; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum VerificationStatus { | ||
|
||
VERIFIED("verified"), | ||
NOT_VERIFIED("not_verified"), | ||
; | ||
|
||
private final String value; | ||
|
||
VerificationStatus(String value) { | ||
this.value = value; | ||
} | ||
|
||
public static VerificationStatus fromValue(String value) { | ||
return Arrays.stream(VerificationStatus.values()) | ||
.filter(status -> status.getValue().equalsIgnoreCase(value)) | ||
.findFirst() | ||
.orElse(NOT_VERIFIED); | ||
} | ||
|
||
public boolean isVerified() { | ||
return this == VERIFIED; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package com.cruru.member.controller; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; | ||
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.document; | ||
|
||
import com.cruru.email.exception.NotVerifiedEmailException; | ||
import com.cruru.email.service.EmailRedisClient; | ||
import com.cruru.member.controller.request.MemberCreateRequest; | ||
import com.cruru.util.ControllerTest; | ||
import io.restassured.RestAssured; | ||
|
@@ -13,10 +17,14 @@ | |
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
@DisplayName("사용자 컨트롤러 테스트") | ||
class MemberControllerTest extends ControllerTest { | ||
|
||
@MockBean | ||
private EmailRedisClient emailRedisClient; | ||
|
||
private static Stream<MemberCreateRequest> InvalidMemberSignUpRequest() { | ||
String validName = "크루루"; | ||
String validMail = "[email protected]"; | ||
|
@@ -40,6 +48,7 @@ private static Stream<MemberCreateRequest> InvalidMemberSignUpRequest() { | |
void create() { | ||
// given | ||
MemberCreateRequest request = new MemberCreateRequest("크루루", "[email protected]", "newPassword214!", "01012341234"); | ||
doNothing().when(emailRedisClient).verifyEmail(request.email()); | ||
|
||
// when&then | ||
RestAssured.given(spec).log().all() | ||
|
@@ -61,7 +70,10 @@ void create() { | |
@ParameterizedTest | ||
@MethodSource("InvalidMemberSignUpRequest") | ||
void create_invalidEmail(MemberCreateRequest request) { | ||
// given&when&then | ||
// given | ||
doNothing().when(emailRedisClient).verifyEmail(request.email()); | ||
|
||
//when&then | ||
RestAssured.given(spec).log().all() | ||
.contentType(ContentType.JSON) | ||
.body(request) | ||
|
@@ -76,4 +88,27 @@ void create_invalidEmail(MemberCreateRequest request) { | |
.when().post("/v1/members/signup") | ||
.then().log().all().statusCode(400); | ||
} | ||
|
||
@DisplayName("인증되지 않은 사용자가 회원가입할 경우, 401을 반환한다.") | ||
@Test | ||
void create_notVerifiedEmail() { | ||
// given | ||
MemberCreateRequest request = new MemberCreateRequest("크루루", "[email protected]", "newPassword214!", "01012341234"); | ||
doThrow(NotVerifiedEmailException.class).when(emailRedisClient).verifyEmail(request.email()); | ||
|
||
// when&then | ||
RestAssured.given(spec).log().all() | ||
.contentType(ContentType.JSON) | ||
.body(request) | ||
.filter(document("member/signup-fail/not-verified-email", | ||
requestFields( | ||
fieldWithPath("clubName").description("동아리명"), | ||
fieldWithPath("email").description("인증되지 않은 사용자 이메일"), | ||
fieldWithPath("password").description("사용자 패스워드"), | ||
fieldWithPath("phone").description("사용자 전화번호") | ||
) | ||
)) | ||
.when().post("/v1/members/signup") | ||
.then().log().all().statusCode(401); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com.cruru.member.facade; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
|
||
import com.cruru.email.exception.NotVerifiedEmailException; | ||
import com.cruru.email.service.EmailRedisClient; | ||
import com.cruru.member.controller.request.MemberCreateRequest; | ||
import com.cruru.member.domain.Member; | ||
import com.cruru.member.domain.repository.MemberRepository; | ||
|
@@ -11,6 +16,7 @@ | |
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
@DisplayName("회원 파사드 서비스 테스트") | ||
class MemberFacadeTest extends ServiceTest { | ||
|
@@ -21,6 +27,9 @@ class MemberFacadeTest extends ServiceTest { | |
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
@MockBean | ||
private EmailRedisClient emailRedisClient; | ||
|
||
@DisplayName("사용자를 생성하면 ID를 반환한다.") | ||
@Test | ||
void create() { | ||
|
@@ -30,6 +39,7 @@ void create() { | |
String password = "newPassword214!"; | ||
String phone = "01012341234"; | ||
MemberCreateRequest request = new MemberCreateRequest(clubName, email, password, phone); | ||
doNothing().when(emailRedisClient).verifyEmail(email); | ||
|
||
// when | ||
long memberId = memberFacade.create(request); | ||
|
@@ -42,4 +52,20 @@ void create() { | |
() -> assertThat(member.get().getPhone()).isEqualTo(phone) | ||
); | ||
} | ||
|
||
@DisplayName("인증되지 않은 사용자로 사용자를 생성하면, 예외가 발생한다.") | ||
@Test | ||
void create_notVerifiedEmail() { | ||
// given | ||
String clubName = "크루루"; | ||
String email = "[email protected]"; | ||
String password = "newPassword214!"; | ||
String phone = "01012341234"; | ||
MemberCreateRequest request = new MemberCreateRequest(clubName, email, password, phone); | ||
doThrow(NotVerifiedEmailException.class).when(emailRedisClient).verifyEmail(email); | ||
|
||
// when&then | ||
assertThatThrownBy(() -> memberFacade.create(request)) | ||
.isInstanceOf(NotVerifiedEmailException.class); | ||
} | ||
} |