-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test : Token, User 도메인 서비스 테스트 코드 작성(#132)
- Loading branch information
1 parent
9bdf57a
commit ddf5365
Showing
5 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...n-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemover.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
44 changes: 44 additions & 0 deletions
44
...ule/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenAppenderTest.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,44 @@ | ||
package com.bamyanggang.domainmodule.domain.user.service | ||
|
||
import com.bamyanggang.domainmodule.domain.user.aggregate.Token | ||
import com.bamyanggang.domainmodule.domain.user.repository.TokenRepository | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import java.util.UUID | ||
|
||
class TokenAppenderTest : BehaviorSpec({ | ||
val mockTokenRepository = mockk<TokenRepository>(relaxed = true) | ||
val tokenAppender = TokenAppender(mockTokenRepository) | ||
val userId = UUID.randomUUID() | ||
val refreshToken = "refreshToken" | ||
|
||
Given("a user id and a refresh token, and the user does not have an existing token") { | ||
every { mockTokenRepository.findByUserId(userId) } returns null | ||
|
||
When("appendToken is called") { | ||
tokenAppender.appendToken(userId, refreshToken) | ||
|
||
Then("a new token should be created and saved") { | ||
verify { mockTokenRepository.findByUserId(userId) } | ||
verify { mockTokenRepository.save(any()) } | ||
} | ||
} | ||
} | ||
|
||
Given("a user id and a refresh token, and the user has an existing token") { | ||
val mockToken = mockk<Token>(relaxed = true) | ||
every { mockTokenRepository.findByUserId(userId) } returns mockToken | ||
|
||
When("appendToken is called") { | ||
tokenAppender.appendToken(userId, refreshToken) | ||
|
||
Then("the existing token should be updated and saved") { | ||
verify { mockTokenRepository.findByUserId(userId) } | ||
verify { mockToken.update(userId, refreshToken) } | ||
verify { mockTokenRepository.save(mockToken) } | ||
} | ||
} | ||
} | ||
}) |
32 changes: 32 additions & 0 deletions
32
...ule/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenModifierTest.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,32 @@ | ||
package com.bamyanggang.domainmodule.domain.user.service | ||
|
||
import com.bamyanggang.domainmodule.domain.user.aggregate.Token | ||
import com.bamyanggang.domainmodule.domain.user.repository.TokenRepository | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import java.util.UUID | ||
|
||
class TokenModifierTest : BehaviorSpec({ | ||
val mockTokenRepository = mockk<TokenRepository>(relaxed = true) | ||
val tokenModifier = TokenModifier(mockTokenRepository) | ||
val userId = UUID.randomUUID() | ||
val refreshToken = "refreshToken" | ||
val newRefreshToken = "newRefreshToken" | ||
|
||
Given("a user id, a refresh token, and a new refresh token") { | ||
val mockToken = mockk<Token>(relaxed = true) | ||
every { mockTokenRepository.findByValue(refreshToken) } returns mockToken | ||
|
||
When("modifyToken is called") { | ||
tokenModifier.modifyToken(userId, refreshToken, newRefreshToken) | ||
|
||
Then("the token should be updated and saved") { | ||
verify { mockTokenRepository.findByValue(refreshToken) } | ||
verify { mockToken.update(userId, newRefreshToken) } | ||
verify { mockTokenRepository.save(any()) } | ||
} | ||
} | ||
} | ||
}) |
22 changes: 22 additions & 0 deletions
22
...dule/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemoverTest.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,22 @@ | ||
package com.bamyanggang.domainmodule.domain.user.service | ||
|
||
import com.bamyanggang.domainmodule.domain.user.repository.TokenRepository | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
|
||
class TokenRemoverTest : BehaviorSpec({ | ||
val mockTokenRepository = mockk<TokenRepository>(relaxed = true) | ||
val tokenRemover = TokenRemover(mockTokenRepository) | ||
val token = "token" | ||
|
||
Given("a token") { | ||
When("removeToken is called") { | ||
tokenRemover.removeToken(token) | ||
|
||
Then("the token should be removed") { | ||
verify { mockTokenRepository.deleteByValue(token) } | ||
} | ||
} | ||
} | ||
}) |
4 changes: 4 additions & 0 deletions
4
Support-Module/Jwt/src/test/kotlin/com/bamyanggang/jwt/TokenProviderTest.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,4 @@ | ||
package com.bamyanggang.jwt | ||
|
||
class TokenProviderTest { | ||
} |