From 086fac1f2ee80da41bd5fbf0476192b6c3933c46 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 16:47:23 +0900 Subject: [PATCH 1/5] =?UTF-8?q?refactor=20:=20FixtureMonkeyUtils=20?= =?UTF-8?q?=EC=88=98=EC=A0=95(#132)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bamyanggang/commonmodule/fixture/FixtureMonkeyUtils.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Common-Module/src/testFixtures/kotlin/com/bamyanggang/commonmodule/fixture/FixtureMonkeyUtils.kt b/Common-Module/src/testFixtures/kotlin/com/bamyanggang/commonmodule/fixture/FixtureMonkeyUtils.kt index f2941cb1..0377628c 100644 --- a/Common-Module/src/testFixtures/kotlin/com/bamyanggang/commonmodule/fixture/FixtureMonkeyUtils.kt +++ b/Common-Module/src/testFixtures/kotlin/com/bamyanggang/commonmodule/fixture/FixtureMonkeyUtils.kt @@ -29,14 +29,15 @@ inline fun generateFixture(): T { // 기본 타입의 임의의 객체 inline fun generateBasicTypeFixture(length: Int): T { return if (T::class == String::class) { - FixtureMonkey.builder() + val generatedString = FixtureMonkey.builder() .defaultNotNull(true) .plugin(KotlinPlugin()) .build() .giveMeBuilder() .sample() .toString() - .take(length) as T + val paddedString = generatedString.padEnd(length, ' ') + paddedString.take(length) as T } else { FixtureMonkey.builder() .defaultNotNull(true) @@ -45,5 +46,4 @@ inline fun generateBasicTypeFixture(length: Int): T { .giveMeBuilder() .sample() } - } From 030f9249db2ee68c89a9ed57f531bb2873ae43f5 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 16:47:54 +0900 Subject: [PATCH 2/5] =?UTF-8?q?test=20:=20Lock,Cache=20Manager=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1(#1?= =?UTF-8?q?32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bamyanggang/cache/CacheManagerTest.kt | 38 +++++ .../com/bamyanggang/lock/LockManagerTest.kt | 132 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 Support-Module/cache/src/test/kotlin/com/bamyanggang/cache/CacheManagerTest.kt create mode 100644 Support-Module/lock/src/test/kotlin/com/bamyanggang/lock/LockManagerTest.kt diff --git a/Support-Module/cache/src/test/kotlin/com/bamyanggang/cache/CacheManagerTest.kt b/Support-Module/cache/src/test/kotlin/com/bamyanggang/cache/CacheManagerTest.kt new file mode 100644 index 00000000..aa6e1567 --- /dev/null +++ b/Support-Module/cache/src/test/kotlin/com/bamyanggang/cache/CacheManagerTest.kt @@ -0,0 +1,38 @@ +package com.bamyanggang.cache + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class CacheManagerTest { + + @Test + fun testCacheByKey() { + // Given + val key = "testKey" + val body = { + "body" + } + // When + val result = CacheManager.cacheByKey(key, body = body) + + // Then + assertEquals("body", result) + } + + @Test + fun testCacheByKeyWithSameKey() { + // Given + val key = "testKey" + val body = { + "body" + } + // When + val result1 = CacheManager.cacheByKey(key, body = body) + val result2 = CacheManager.cacheByKey(key, body = body) + + // Then + assertEquals("body", result1) + assertEquals("body", result2) + } + +} diff --git a/Support-Module/lock/src/test/kotlin/com/bamyanggang/lock/LockManagerTest.kt b/Support-Module/lock/src/test/kotlin/com/bamyanggang/lock/LockManagerTest.kt new file mode 100644 index 00000000..25ce8551 --- /dev/null +++ b/Support-Module/lock/src/test/kotlin/com/bamyanggang/lock/LockManagerTest.kt @@ -0,0 +1,132 @@ +package com.bamyanggang.lock + +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit + +class LockManagerTest { + + @Test + fun testLockByKey() { + // Given + val key = "key" + val body = { + Thread.sleep(10) + "body" + } + + // When + val result = LockManager.lockByKey(key, body = body) + + // Then + assert(result == "body") + } + + + @Test + fun testLockByKeyTimeout() { + // Given + val key = "key" + val time = 1L + val body = { + Thread.sleep(2000) + "body" + } + + val countDownLatch = CountDownLatch(2) + var isTimeout = false + // When + for (i in 0..1) { + + Thread { + try { + LockManager.lockByKey(key, time, body) + } catch (e: RuntimeException) { + isTimeout = true + } finally { + countDownLatch.countDown() + } + }.start() + } + countDownLatch.await() + + // Then + isTimeout shouldBe true + } + + @Test + fun testLockConcurrent() { + // Given + var count = 0 + val key = "key" + val body = { + val currentCount = count + Thread.sleep(1) + count = currentCount + 1 + } + + val countDown = 100 + + val countDownLatch = CountDownLatch(countDown) + + // When + for (i in 0 until countDown) { + Thread { + LockManager.lockByKey(key, body = body) + countDownLatch.countDown() + }.start() + } + + countDownLatch.await() + + // Then + count shouldBe 100 + } + + @Test + fun testLockIndependence() { + // Given + val key1 = "key1" + val key2 = "key2" + val body = { Thread.sleep(1000) } + val countDownLatch = CountDownLatch(2) + + // When + Thread { + LockManager.lockByKey(key1, body = body) + countDownLatch.countDown() + }.start() + + Thread { + LockManager.lockByKey(key2, body = body) + countDownLatch.countDown() + }.start() + + // Then + countDownLatch.await(2, TimeUnit.SECONDS) shouldBe true + } + + @Test + fun testLockWait() { + // Given + val key = "key" + val body = { Thread.sleep(1000) } + val countDownLatch = CountDownLatch(2) + + // When + Thread { + LockManager.lockByKey(key, body = body) + countDownLatch.countDown() + }.start() + + Thread { + LockManager.lockByKey(key, body = body) + countDownLatch.countDown() + }.start() + + // Then + countDownLatch.await(3, TimeUnit.SECONDS) shouldBe true + } + +} From 9bdf57a20d4385169cb43ba4c914aa4829a2be4c Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 16:48:53 +0900 Subject: [PATCH 3/5] =?UTF-8?q?test=20:=20Token,=20User=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=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/aggregate/TokenTest.kt | 29 +++ .../domain/user/aggregate/UserTest.kt | 182 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/TokenTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/UserTest.kt diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/TokenTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/TokenTest.kt new file mode 100644 index 00000000..a3d4bd6f --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/TokenTest.kt @@ -0,0 +1,29 @@ +package com.bamyanggang.domainmodule.domain.user.aggregate + +import com.bamyanggang.commonmodule.fixture.generateFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import java.util.UUID + +class TokenTest : FunSpec({ + + test("Token 생성") { + val token: Token = generateFixture { + it.set("userId", UUID.randomUUID()) + it.set("value", "token") + } + token.value shouldBe "token" + } + + test("Token 업데이트") { + val userId = UUID.randomUUID() + val token: Token = generateFixture { + it.set("userId", userId) + it.set("value", "token") + } + val newToken = "newToken" + val updatedToken = token.update(userId, newToken) + updatedToken.value shouldBe newToken + } + +}) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/UserTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/UserTest.kt new file mode 100644 index 00000000..20f234d1 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/UserTest.kt @@ -0,0 +1,182 @@ +package com.bamyanggang.domainmodule.domain.user.aggregate + +import com.bamyanggang.commonmodule.fixture.generateBasicTypeFixture +import com.bamyanggang.commonmodule.fixture.generateFixture +import com.bamyanggang.domainmodule.domain.user.enums.SocialLoginProvider +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import java.time.LocalDateTime + +class UserTest : FunSpec({ + + test("User 생성") { + val socialId = "socialId" + val profileImgUrl = "profileImgUrl" + val provider: SocialLoginProvider = SocialLoginProvider.KAKAO + val email = "email" + val nickName = "nickName" + val jobSearchStatus = null + val desiredJob = null + val goal = null + val dream = null + + val user = User.create( + socialId = socialId, + profileImgUrl = profileImgUrl, + provider = provider, + email = email, + nickName = nickName, + jobSearchStatus = jobSearchStatus, + desiredJob = desiredJob, + goal = goal, + dream = dream + ) + + user.socialId shouldBe socialId + user.profileImgUrl shouldBe profileImgUrl + user.provider shouldBe provider + user.email shouldBe email + user.nickName shouldBe nickName + user.jobSearchStatus shouldBe jobSearchStatus + user.desiredJob shouldBe desiredJob + user.goal shouldBe goal + user.dream shouldBe dream + + } + + test("User 업데이트") { + val user: User = generateFixture { + it.set("socialId", "socialId") + it.set("profileImgUrl", "profileImgUrl") + it.set("provider", SocialLoginProvider.KAKAO) + it.set("email", "email") + it.set("nickName", "nickName") + it.set("createdAt", LocalDateTime.now()) + it.set("updatedAt", LocalDateTime.now()) + } + val newNickName = "newNick" + val updatedUser = user.update( + nickName = newNickName, + profileImgUrl = null, + jobSearchStatus = null, + desiredJob = null, + goal = null, + dream = null + ) + updatedUser.nickName shouldBe newNickName + } + + test("필수 항목이 누락되었을 경우 에러 반환") { + // arrange + val socialId = "socialId" + val profileImgUrl = "" + val provider: SocialLoginProvider = SocialLoginProvider.KAKAO + val email = "email" + val nickName = "nickName" + val jobSearchStatus = null + val desiredJob = null + val goal = null + val dream = null + + // act, assert + shouldThrow { + User.create( + socialId = socialId, + profileImgUrl = profileImgUrl, + provider = provider, + email = email, + nickName = nickName, + jobSearchStatus = jobSearchStatus, + desiredJob = desiredJob, + goal = goal, + dream = dream + ) + } + } + + test("닉네임이 10자를 초과할 경우 에러 반환") { + // arrange + val socialId = "socialId" + val profileImgUrl= "profileImgUrl" + val provider: SocialLoginProvider = SocialLoginProvider.KAKAO + val email = "email" + val nickName = "nickName12345" + val jobSearchStatus = null + val desiredJob = null + val goal = null + val dream = null + + // act, assert + shouldThrow { + User.create( + socialId = socialId, + profileImgUrl = profileImgUrl, + provider = provider, + email = email, + nickName = nickName, + jobSearchStatus = jobSearchStatus, + desiredJob = desiredJob, + goal = goal, + dream = dream + ) + } + } + + test("희망 직무가 50자를 초과할 경우 에러 반환") { + // arrange + val socialId = "socialId" + val profileImgUrl = "profileImgUrl" + val provider: SocialLoginProvider = SocialLoginProvider.KAKAO + val email = "email" + val nickName = "nickName" + val jobSearchStatus = null + val desiredJob: String = generateBasicTypeFixture(51) + val goal = null + val dream = null + + // act, assert + shouldThrow { + User.create( + socialId = socialId, + profileImgUrl = profileImgUrl, + provider = provider, + email = email, + nickName = nickName, + jobSearchStatus = jobSearchStatus, + desiredJob = desiredJob, + goal = goal, + dream = dream + ) + } + } + + test("발전시키고 싶은 역량이 400자를 초과할 경우 에러 반환") { + // arrange + val socialId = "socialId" + val profileImgUrl = "profileImgUrl" + val provider: SocialLoginProvider = SocialLoginProvider.KAKAO + val email = "email" + val nickName = "nickName" + val jobSearchStatus = null + val desiredJob = null + val goal: String = generateBasicTypeFixture(401) + val dream = null + + // act, assert + shouldThrow { + User.create( + socialId = socialId, + profileImgUrl = profileImgUrl, + provider = provider, + email = email, + nickName = nickName, + jobSearchStatus = jobSearchStatus, + desiredJob = desiredJob, + goal = goal, + dream = dream + ) + } + } + +}) From ddf5365c7a6aa6c78644670d3137f0141f6b97d5 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 16:49:41 +0900 Subject: [PATCH 4/5] =?UTF-8?q?test=20:=20Token,=20User=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1(#1?= =?UTF-8?q?32)?= 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 { +} From a72147a39c1e35b9d4bd0731ab4300f738058b62 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 16:50:02 +0900 Subject: [PATCH 5/5] =?UTF-8?q?test=20:=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/UserModifierTest.kt | 36 ++++++++++++++++ .../domain/user/service/UserReaderTest.kt | 42 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserModifierTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserReaderTest.kt diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserModifierTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserModifierTest.kt new file mode 100644 index 00000000..815b5807 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserModifierTest.kt @@ -0,0 +1,36 @@ +package com.bamyanggang.domainmodule.domain.user.service + +import com.bamyanggang.domainmodule.domain.user.aggregate.User +import com.bamyanggang.domainmodule.domain.user.repository.UserRepository +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import java.util.UUID + +class UserModifierTest : BehaviorSpec({ + val mockUserRepository = mockk(relaxed = true) + val userModifier = UserModifier(mockUserRepository) + val userId = UUID.randomUUID() + val nickName = "nickName" + val profileImgUrl = "profileImgUrl" + val jobSearchStatus = "jobSearchStatus" + val desiredJob = "desiredJob" + val goal = "goal" + val dream = "dream" + + Given("a user id, nickname, profile image url, job search status, desired job, goal, and dream") { + val mockUser = mockk(relaxed = true) + every { mockUserRepository.findById(userId) } returns mockUser + + When("modifyUserInfo is called") { + userModifier.modifyUserInfo(userId, nickName, profileImgUrl, jobSearchStatus, desiredJob, goal, dream) + + Then("the user info should be updated and saved") { + verify { mockUserRepository.findById(userId) } + verify { mockUser.update(nickName, profileImgUrl, jobSearchStatus, desiredJob, goal, dream) } + verify { mockUserRepository.save(any()) } + } + } + } +}) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserReaderTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserReaderTest.kt new file mode 100644 index 00000000..f2cc0bd1 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserReaderTest.kt @@ -0,0 +1,42 @@ +package com.bamyanggang.domainmodule.domain.user.service + +import com.bamyanggang.domainmodule.domain.user.aggregate.User +import com.bamyanggang.domainmodule.domain.user.repository.UserRepository +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import java.util.UUID + +class UserReaderTest : BehaviorSpec({ + val mockUserRepository = mockk(relaxed = true) + val userReader = UserReader(mockUserRepository) + val socialId = "socialId" + val userId = UUID.randomUUID() + + Given("a social id") { + val mockUser = mockk(relaxed = true) + every { mockUserRepository.findBySocialId(socialId) } returns mockUser + + When("readUserBySocialId is called") { + userReader.readUserBySocialId(socialId) + + Then("the user with the given social id should be returned") { + verify { mockUserRepository.findBySocialId(socialId) } + } + } + } + + Given("a user id") { + val mockUser = mockk(relaxed = true) + every { mockUserRepository.findById(userId) } returns mockUser + + When("readUserById is called") { + userReader.readUserById(userId) + + Then("the user with the given id should be returned") { + verify { mockUserRepository.findById(userId) } + } + } + } +})