diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemover.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemover.kt index dd5e1397..4ce21878 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemover.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemover.kt @@ -1,6 +1,5 @@ package com.bamyanggang.domainmodule.domain.user.service -import com.bamyanggang.domainmodule.domain.user.aggregate.Token import com.bamyanggang.domainmodule.domain.user.repository.TokenRepository class TokenRemover( diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenAppenderTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenAppenderTest.kt new file mode 100644 index 00000000..9a642f09 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenAppenderTest.kt @@ -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(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(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) } + } + } + } +}) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenModifierTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenModifierTest.kt new file mode 100644 index 00000000..2fce8e5b --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenModifierTest.kt @@ -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(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(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()) } + } + } + } +}) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemoverTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemoverTest.kt new file mode 100644 index 00000000..c0c33d13 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemoverTest.kt @@ -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(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) } + } + } + } +}) diff --git a/Support-Module/Jwt/src/test/kotlin/com/bamyanggang/jwt/TokenProviderTest.kt b/Support-Module/Jwt/src/test/kotlin/com/bamyanggang/jwt/TokenProviderTest.kt new file mode 100644 index 00000000..77433d3a --- /dev/null +++ b/Support-Module/Jwt/src/test/kotlin/com/bamyanggang/jwt/TokenProviderTest.kt @@ -0,0 +1,4 @@ +package com.bamyanggang.jwt + +class TokenProviderTest { +}