-
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.
Merge pull request #162 from KUSITMS-29th-TEAM-B/test/flight-132
test: Token, User 도메인 테스트 코드 작성(#132)
- Loading branch information
Showing
12 changed files
with
564 additions
and
4 deletions.
There are no files selected for viewing
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
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
29 changes: 29 additions & 0 deletions
29
...in-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/TokenTest.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,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 | ||
} | ||
|
||
}) |
182 changes: 182 additions & 0 deletions
182
Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/aggregate/UserTest.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,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<IllegalArgumentException> { | ||
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<IllegalArgumentException> { | ||
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<IllegalArgumentException> { | ||
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<IllegalArgumentException> { | ||
User.create( | ||
socialId = socialId, | ||
profileImgUrl = profileImgUrl, | ||
provider = provider, | ||
email = email, | ||
nickName = nickName, | ||
jobSearchStatus = jobSearchStatus, | ||
desiredJob = desiredJob, | ||
goal = goal, | ||
dream = dream | ||
) | ||
} | ||
} | ||
|
||
}) |
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) } | ||
} | ||
} | ||
} | ||
}) |
36 changes: 36 additions & 0 deletions
36
...dule/src/test/kotlin/com/bamyanggang/domainmodule/domain/user/service/UserModifierTest.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,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<UserRepository>(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<User>(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()) } | ||
} | ||
} | ||
} | ||
}) |
Oops, something went wrong.