From ddf5365c7a6aa6c78644670d3137f0141f6b97d5 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 16:49:41 +0900 Subject: [PATCH] =?UTF-8?q?test=20:=20Token,=20User=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1(#132)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/TokenRemover.kt | 1 - .../domain/user/service/TokenAppenderTest.kt | 44 +++++++++++++++++++ .../domain/user/service/TokenModifierTest.kt | 32 ++++++++++++++ .../domain/user/service/TokenRemoverTest.kt | 22 ++++++++++ .../com/bamyanggang/jwt/TokenProviderTest.kt | 4 ++ 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenAppenderTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenModifierTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/TokenRemoverTest.kt create mode 100644 Support-Module/Jwt/src/test/kotlin/com/bamyanggang/jwt/TokenProviderTest.kt 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 { +}