Skip to content

Commit

Permalink
merge: (#228) 회원가입시 사원번호 검사 추가 (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 authored Dec 17, 2022
2 parents 07e6237 + 7bc1981 commit fa5689c
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import team.comit.simtong.domain.file.exception.FileExceptions
import team.comit.simtong.domain.spot.exception.SpotExceptions
import team.comit.simtong.domain.team.exception.TeamExceptions
import team.comit.simtong.domain.user.dto.SignUpRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.User
import team.comit.simtong.domain.user.spi.CommandUserPort
Expand Down Expand Up @@ -44,8 +45,15 @@ class SignUpUseCase(
fun execute(request: SignUpRequest): TokenResponse {
val (name, email, password, nickname, employeeNumber, profileImagePath) = request

if (queryUserPort.existsUserByEmail(email)) {
throw AuthExceptions.AlreadyUsedEmail()
when {
queryUserPort.existsUserByEmail(email) ->
throw AuthExceptions.AlreadyUsedEmail()

queryUserPort.existsUserByEmployeeNumber(employeeNumber) ->
throw AuthExceptions.AlreadyUsedEmployeeNumber()

nickname != null && queryUserPort.existsUserByNickname(nickname) ->
throw UserExceptions.AlreadyUsedNickname()
}

val authCodeLimit = queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import team.comit.simtong.domain.spot.model.Spot
import team.comit.simtong.domain.team.exception.TeamExceptions
import team.comit.simtong.domain.team.model.Team
import team.comit.simtong.domain.user.dto.SignUpRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.User
import team.comit.simtong.domain.user.spi.CommandUserPort
Expand Down Expand Up @@ -175,11 +176,17 @@ class SignUpUseCaseTests {
profileImagePath = profileImagePath
)

given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)
given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(false)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)
Expand Down Expand Up @@ -230,11 +237,17 @@ class SignUpUseCaseTests {
profileImagePath = User.DEFAULT_IMAGE
)

given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)
given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(false)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)
Expand Down Expand Up @@ -274,6 +287,15 @@ class SignUpUseCaseTests {
given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(unVerifiedAuthCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(false)

// when & then
assertThrows<AuthExceptions.UncertifiedEmail> {
signUpUseCase.execute(requestStub)
Expand All @@ -286,6 +308,15 @@ class SignUpUseCaseTests {
given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(null)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(false)

// when & then
assertThrows<AuthExceptions.RequiredNewEmailAuthentication> {
signUpUseCase.execute(requestStub)
Expand Down Expand Up @@ -316,6 +347,12 @@ class SignUpUseCaseTests {
given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(false)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(null)

Expand All @@ -334,6 +371,12 @@ class SignUpUseCaseTests {
given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(false)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)

Expand All @@ -355,6 +398,12 @@ class SignUpUseCaseTests {
given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(false)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)

Expand All @@ -370,4 +419,43 @@ class SignUpUseCaseTests {
}
}

@Test
fun `이미 사용중인 사원번호`() {
// given
given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(true)

// when & then
assertThrows<AuthExceptions.AlreadyUsedEmployeeNumber> {
signUpUseCase.execute(requestStub)
}
}

@Test
fun `이미 사용중인 닉네임`() {
// given
given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryUserPort.existsUserByEmployeeNumber(requestStub.employeeNumber))
.willReturn(false)

given(queryUserPort.existsUserByNickname(nickname))
.willReturn(true)

// when & then
assertThrows<UserExceptions.AlreadyUsedNickname> {
signUpUseCase.execute(requestStub)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sealed class AuthExceptions(

// 409
class AlreadyUsedEmail(message: String = ALREADY_USED_EMAIL) : AuthExceptions(409, message)
class AlreadyUsedEmployeeNumber(message: String = ALREADY_USED_EMPLOYEE_NUMBER) : AuthExceptions(409, message)
class AlreadyCertifiedEmail(message: String = ALREADY_CERTIFIED_EMAIL) : AuthExceptions(409, message)

// 429
Expand All @@ -36,6 +37,7 @@ sealed class AuthExceptions(
private const val REQUIRED_NEW_EMAIL_AUTHENTICATION = "새로운 이메일 인증이 필요합니다."
private const val REFRESH_TOKEN_NOT_FOUND = "리프레시 토큰을 찾을 수 없습니다."
private const val ALREADY_USED_EMAIL = "이미 사용중인 이메일입니다."
private const val ALREADY_USED_EMPLOYEE_NUMBER = "이미 사용중인 사원번호입니다."
private const val ALREADY_CERTIFIED_EMAIL = "이미 인증된 이메일입니다."
private const val EXCEEDED_SEND_AUTH_CODE_REQUEST = "인증 코드 발송 횟수를 초과하였습니다."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import java.util.UUID
**/
interface QueryUserPort {

fun existsUserByEmployeeNumber(employeeNumber: Int): Boolean

fun existsUserByEmail(email: String): Boolean

fun existsUserByNickname(nickname: String): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class UserPersistenceAdapter(
.let(userMapper::toDomain)
}

override fun existsUserByEmployeeNumber(employeeNumber: Int): Boolean {
return userJpaRepository.existsUserJpaEntitiesByEmployeeNumber(employeeNumber)
}

override fun existsUserByEmail(email: String): Boolean {
return userJpaRepository.existsUserJpaEntitiesByEmail(email)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ interface UserJpaRepository : CrudRepository<UserJpaEntity, UUID> {

fun existsUserJpaEntitiesByNickname(nickname: String): Boolean

fun existsUserJpaEntitiesByEmployeeNumber(employeeNumber: Int): Boolean

fun queryUserJpaEntityByNameAndSpotIdAndEmail(name: String, spotId: UUID, email: String): UserJpaEntity?

fun queryUserJpaEntityByEmailAndEmployeeNumber(email: String, employeeNumber: Int): UserJpaEntity?
Expand Down

0 comments on commit fa5689c

Please sign in to comment.