Skip to content

Commit

Permalink
test : Token, User 도메인 서비스 테스트 코드 작성(#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
isprogrammingfun committed May 23, 2024
1 parent 9bdf57a commit ddf5365
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
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) }
}
}
}
})
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()) }
}
}
}
})
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) }
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.bamyanggang.jwt

class TokenProviderTest {
}

0 comments on commit ddf5365

Please sign in to comment.