-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
125 additions
and
30 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
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
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 |
---|---|---|
|
@@ -7,13 +7,14 @@ import org.junit.jupiter.api.assertThrows | |
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.BDDMockito.given | ||
import org.mockito.BDDMockito.willDoNothing | ||
import org.mockito.kotlin.any | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import team.comit.simtong.domain.auth.exception.CertifiedEmailException | ||
import team.comit.simtong.domain.auth.exception.ExceededSendAuthCodeRequestException | ||
import team.comit.simtong.domain.auth.model.AuthCode | ||
import team.comit.simtong.domain.auth.model.AuthCodeLimit | ||
import team.comit.simtong.domain.auth.service.ConstructAuthCodeLimitService | ||
import team.comit.simtong.domain.auth.service.ConstructAuthCodeService | ||
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort | ||
import team.comit.simtong.domain.auth.spi.CommandAuthCodePort | ||
import team.comit.simtong.domain.auth.spi.QueryAuthCodeLimitPort | ||
|
@@ -34,12 +35,27 @@ class SendAuthCodeUseCaseTests { | |
@MockBean | ||
private lateinit var sendEmailPort: SendEmailPort | ||
|
||
@MockBean | ||
private lateinit var constructAuthCodeLimitService: ConstructAuthCodeLimitService | ||
|
||
@MockBean | ||
private lateinit var constructAuthCodeService: ConstructAuthCodeService | ||
|
||
private lateinit var sendAuthCodeUseCase: SendAuthCodeUseCase | ||
|
||
private val email = "[email protected]" | ||
|
||
private val code = "123456" | ||
|
||
private val authCodeLimitStub by lazy { | ||
AuthCodeLimit( | ||
key = email, | ||
expirationTime = AuthCodeLimit.EXPIRED, | ||
attemptCount = 0, | ||
isVerified = false | ||
) | ||
} | ||
|
||
private val verifiedAuthCodeLimitStub by lazy { | ||
AuthCodeLimit( | ||
key = email, | ||
|
@@ -72,6 +88,8 @@ class SendAuthCodeUseCaseTests { | |
commandAuthCodeLimitPort, | ||
commandAuthCodePort, | ||
queryAuthCodeLimitPort, | ||
constructAuthCodeLimitService, | ||
constructAuthCodeService, | ||
sendEmailPort | ||
) | ||
} | ||
|
@@ -82,7 +100,13 @@ class SendAuthCodeUseCaseTests { | |
given(queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(email)) | ||
.willReturn(null) | ||
|
||
given(commandAuthCodePort.save(any())) | ||
given(constructAuthCodeLimitService.construct(email)) | ||
.willReturn(authCodeLimitStub) | ||
|
||
given(constructAuthCodeService.construct(email)) | ||
.willReturn(authCodeStub) | ||
|
||
given(commandAuthCodePort.save(authCodeStub)) | ||
.willReturn(authCodeStub) | ||
|
||
willDoNothing().given(sendEmailPort).sendAuthCode(code, email) | ||
|
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
35 changes: 35 additions & 0 deletions
35
...n/src/main/kotlin/team/comit/simtong/domain/auth/service/ConstructAuthCodeLimitService.kt
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,35 @@ | ||
package team.comit.simtong.domain.auth.service | ||
|
||
import team.comit.simtong.domain.auth.model.AuthCodeLimit | ||
import team.comit.simtong.global.annotation.DomainService | ||
|
||
/** | ||
* | ||
* AuthCodeLimit을 생성하는 ConstructAuthCodeLimitService | ||
* | ||
* @author Chokyunghyeon | ||
* @date 2022/09/29 | ||
* @version 1.0.0 | ||
**/ | ||
@DomainService | ||
class ConstructAuthCodeLimitService { | ||
|
||
fun construct(email: String): AuthCodeLimit { | ||
return AuthCodeLimit( | ||
key = email, | ||
expirationTime = AuthCodeLimit.EXPIRED, | ||
attemptCount = 0, | ||
isVerified = false | ||
) | ||
} | ||
|
||
fun verified(email: String): AuthCodeLimit { | ||
return AuthCodeLimit( | ||
key = email, | ||
expirationTime = AuthCodeLimit.VERIFIED_EXPIRED, | ||
attemptCount = AuthCodeLimit.MAX_ATTEMPT_COUNT, | ||
isVerified = true | ||
) | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...domain/src/main/kotlin/team/comit/simtong/domain/auth/service/ConstructAuthCodeService.kt
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,26 @@ | ||
package team.comit.simtong.domain.auth.service | ||
|
||
import net.bytebuddy.utility.RandomString | ||
import team.comit.simtong.domain.auth.model.AuthCode | ||
import team.comit.simtong.global.annotation.DomainService | ||
|
||
/** | ||
* | ||
* AuthCode를 생성하는 ConstructAuthCodeService | ||
* | ||
* @author Chokyunghyeon | ||
* @date 2022/09/29 | ||
* @version 1.0.0 | ||
**/ | ||
@DomainService | ||
class ConstructAuthCodeService { | ||
|
||
fun construct(email: String): AuthCode { | ||
return AuthCode( | ||
key = email, | ||
code = RandomString(6).nextString(), | ||
expirationTime = AuthCode.EXPIRED | ||
) | ||
} | ||
|
||
} |