Skip to content

Commit a235d47

Browse files
authored
πŸ”€ :: ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„±
πŸ”€ :: ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„±
2 parents 101a0e7 + 39c5f61 commit a235d47

12 files changed

+337
-8
lines changed

β€ŽbuildSrc/src/main/kotlin/Dependencies.kt

+17-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Libraries {
1414

1515
override fun dependencies() = listOf(
1616
KOTLIN_REFLECT to ImplementationType.IMPLEMENTATION,
17-
KOTLIN_STDLIB to ImplementationType.IMPLEMENTATION
17+
KOTLIN_STDLIB to ImplementationType.IMPLEMENTATION,
1818
)
1919
}
2020

@@ -34,7 +34,7 @@ interface Libraries {
3434
KOTLIN_JDSL to ImplementationType.IMPLEMENTATION,
3535
REACTIVE_MYSQL to ImplementationType.IMPLEMENTATION,
3636
REACTIVE_HIBERNATE to ImplementationType.IMPLEMENTATION,
37-
SPRING_DATA_COMMON to ImplementationType.IMPLEMENTATION
37+
SPRING_DATA_COMMON to ImplementationType.IMPLEMENTATION,
3838
)
3939
}
4040

@@ -43,23 +43,23 @@ interface Libraries {
4343
"com.fasterxml.jackson.module:jackson-module-kotlin:${DependencyVersions.JACKSON_VERSION}"
4444

4545
override fun dependencies() = listOf(
46-
MODULE_KOTLIN to ImplementationType.IMPLEMENTATION
46+
MODULE_KOTLIN to ImplementationType.IMPLEMENTATION,
4747
)
4848
}
4949

5050
object Transaction : Libraries {
5151
private const val SPRING_TRANSACTION = "org.springframework:spring-tx:${DependencyVersions.SPRING_TRANSACTION}"
5252

5353
override fun dependencies() = listOf(
54-
SPRING_TRANSACTION to ImplementationType.IMPLEMENTATION
54+
SPRING_TRANSACTION to ImplementationType.IMPLEMENTATION,
5555
)
5656
}
5757

5858
object Component : Libraries {
5959
private const val SPRING_COMPONENT = "org.springframework:spring-context:${DependencyVersions.SPRING_COMPONENT}"
6060

6161
override fun dependencies() = listOf(
62-
SPRING_COMPONENT to ImplementationType.IMPLEMENTATION
62+
SPRING_COMPONENT to ImplementationType.IMPLEMENTATION,
6363
)
6464
}
6565

@@ -79,7 +79,7 @@ interface Libraries {
7979
private const val CLOUD_CONFIG = "org.springframework.cloud:spring-cloud-config-client"
8080

8181
override fun dependencies() = listOf(
82-
CLOUD_CONFIG to ImplementationType.IMPLEMENTATION
82+
CLOUD_CONFIG to ImplementationType.IMPLEMENTATION,
8383
)
8484
}
8585

@@ -104,7 +104,17 @@ interface Libraries {
104104
REACTOR_COROUTINE_EXTENSION to ImplementationType.IMPLEMENTATION,
105105
COROUTINE_REACTOR to ImplementationType.IMPLEMENTATION,
106106
COROUTINE_JDK to ImplementationType.RUNTIME_ONLY,
107-
KOTLINX_COROUTINE to ImplementationType.IMPLEMENTATION
107+
KOTLINX_COROUTINE to ImplementationType.IMPLEMENTATION,
108+
)
109+
}
110+
111+
object Test : Libraries {
112+
private const val KOTEST = "io.kotest:kotest-runner-junit5:${DependencyVersions.KOTEST_VERSION}"
113+
private const val MOCKK = "io.mockk:mockk:${DependencyVersions.MOCKK_VERSION}"
114+
115+
override fun dependencies() = listOf(
116+
KOTEST to ImplementationType.TEST_IMPLEMENTATION,
117+
MOCKK to ImplementationType.TEST_IMPLEMENTATION,
108118
)
109119
}
110120
}

β€ŽbuildSrc/src/main/kotlin/DependencyVersions.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ object DependencyVersions {
33
const val SPRING_TRANSACTION = "6.0.6"
44
const val SPRING_CLOUD_VERSION = "2021.0.1"
55
const val SPRING_COMPONENT = "6.0.6"
6-
const val OPENFEIGN = "3.1.4"
76
const val JSOUP_VERSION = "1.15.2"
87
const val COROUTINE_VERSION = "1.6.1"
98
const val REACTIVE_MYSQL_VERSION = "4.2.5"
109
const val HIBERNATE_REACTIVE_VERSION = "1.1.3.Final"
1110
const val JDSL_VERSION = "2.0.3.RELEASE"
1211
const val MUTINY_VERSION = "1.4.0"
12+
const val KOTEST_VERSION = "5.5.4"
13+
const val MOCKK_VERSION = "1.13.2"
1314
}

β€Žgit-application/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ plugins {
55
dependencies {
66
implementationDependencies(Libraries.Transaction)
77
implementationDependencies(Libraries.Component)
8+
implementationDependencies(Libraries.Test)
89
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.xquare.git
2+
3+
import io.kotest.core.spec.style.DescribeSpec
4+
5+
abstract class BaseApplicationTest(testcase: DescribeSpec.() -> Unit) : DescribeSpec(testcase)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.xquare.git.config
2+
3+
import io.kotest.core.annotation.AutoScan
4+
import io.kotest.core.listeners.TestListener
5+
import io.kotest.core.test.TestCase
6+
import io.kotest.core.test.TestResult
7+
import io.mockk.clearAllMocks
8+
9+
@AutoScan
10+
object DefaultTestConfig : TestListener {
11+
override suspend fun afterEach(testCase: TestCase, result: TestResult) {
12+
clearAllMocks()
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.xquare.git.git
2+
3+
import com.xquare.v1servicegit.git.Git
4+
import java.util.UUID
5+
6+
fun createGit(
7+
id: UUID = UUID.randomUUID(),
8+
username: String = "testUsername",
9+
contributions: Int = 1,
10+
ranking: Int = 1,
11+
) = Git(
12+
userId = id,
13+
username = username,
14+
contributions = contributions,
15+
ranking = ranking,
16+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.xquare.git.git.usecase
2+
3+
import com.xquare.git.BaseApplicationTest
4+
import com.xquare.git.git.createGit
5+
import com.xquare.v1servicegit.git.Git
6+
import com.xquare.v1servicegit.git.dto.request.FindUserInfoRequest
7+
import com.xquare.v1servicegit.git.dto.response.FindAllUserResponse
8+
import com.xquare.v1servicegit.git.dto.response.FindAllUserResponse.FindUserElement
9+
import com.xquare.v1servicegit.git.port.QueryGitPort
10+
import com.xquare.v1servicegit.git.usecase.FindAllGitUseCase
11+
import com.xquare.v1servicegit.user.dto.FindUserInfoElement
12+
import com.xquare.v1servicegit.user.dto.FindUserListResponse
13+
import com.xquare.v1servicegit.user.port.QueryUserPort
14+
import io.kotest.matchers.shouldBe
15+
import io.mockk.coEvery
16+
import io.mockk.mockk
17+
18+
class FindAllGitTest : BaseApplicationTest({
19+
val queryGitPort: QueryGitPort = mockk()
20+
val queryUserPort: QueryUserPort = mockk()
21+
22+
val findAllGitUseCase = FindAllGitUseCase(
23+
queryGitPort = queryGitPort,
24+
queryUserPort = queryUserPort,
25+
)
26+
27+
describe("λͺ¨λ“  κΉƒν—ˆλΈŒ 정보λ₯Ό 뢈러올 λ•Œ") {
28+
val name = "testName"
29+
val profileFileName = "testProfileFileName"
30+
val userInfo = createGit()
31+
val userIds = listOf(userInfo).map(Git::userId)
32+
val request = FindUserInfoRequest(userIds)
33+
34+
coEvery { queryGitPort.getAllGit() } returns listOf(userInfo)
35+
coEvery { queryUserPort.getAllUserInfo(request) } returns FindUserListResponse(
36+
listOf(
37+
FindUserInfoElement(
38+
id = userInfo.userId,
39+
name = name,
40+
profileFileName = profileFileName,
41+
),
42+
),
43+
)
44+
45+
it("Responseλ₯Ό λ°˜ν™˜ν•œλ‹€.") {
46+
val result = findAllGitUseCase.execute()
47+
48+
result shouldBe FindAllUserResponse(
49+
listOf(
50+
FindUserElement(
51+
userId = userInfo.userId,
52+
name = name,
53+
username = userInfo.username,
54+
profileFileName = profileFileName,
55+
contributions = userInfo.contributions,
56+
ranking = userInfo.ranking,
57+
),
58+
),
59+
)
60+
}
61+
}
62+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.xquare.git.git.usecase
2+
3+
import com.xquare.git.BaseApplicationTest
4+
import com.xquare.git.git.createGit
5+
import com.xquare.v1servicegit.git.dto.response.FindAllUserResponse
6+
import com.xquare.v1servicegit.git.exceptions.GitExceptions
7+
import com.xquare.v1servicegit.git.port.QueryGitPort
8+
import com.xquare.v1servicegit.git.usecase.FindGitByCurrentUserIdUseCase
9+
import com.xquare.v1servicegit.user.dto.FindUserInfoElement
10+
import com.xquare.v1servicegit.user.port.QueryUserPort
11+
import io.kotest.assertions.throwables.shouldThrow
12+
import io.kotest.matchers.shouldBe
13+
import io.mockk.coEvery
14+
import io.mockk.mockk
15+
16+
class FindGitByCurrentUserIdTest : BaseApplicationTest({
17+
val queryGitPort: QueryGitPort = mockk()
18+
val queryUserPort: QueryUserPort = mockk()
19+
20+
val findGitByCurrentUserIdUseCase = FindGitByCurrentUserIdUseCase(
21+
queryGitPort = queryGitPort,
22+
queryUserPort = queryUserPort,
23+
)
24+
25+
describe("μžμ‹ μ˜ κΉƒν—ˆλΈŒ 정보λ₯Ό 뢈러올 λ•Œ") {
26+
val name = "testName"
27+
val profileFileName = "testProfileFileName"
28+
29+
val userInfo = createGit()
30+
31+
context("νƒμƒ‰ν•˜λŠ” κΉƒν—ˆλΈŒ 정보가 μ‘΄μž¬ν•˜μ§€ μ•ŠμœΌλ©΄") {
32+
coEvery { queryGitPort.getGitByUserId(userInfo.userId) } returns null
33+
34+
it("μ˜ˆμ™Έλ₯Ό λ˜μ§„λ‹€.") {
35+
shouldThrow<GitExceptions.NotFound> {
36+
findGitByCurrentUserIdUseCase.execute(userInfo.userId)
37+
}
38+
}
39+
}
40+
41+
coEvery { queryGitPort.getGitByUserId(userInfo.userId) } returns userInfo
42+
coEvery { queryUserPort.getNameAndProfileFileName(userInfo.userId) } returns FindUserInfoElement(
43+
id = userInfo.userId,
44+
name = name,
45+
profileFileName = profileFileName,
46+
)
47+
48+
it("Responseλ₯Ό λ°˜ν™˜ν•œλ‹€.") {
49+
val result = findGitByCurrentUserIdUseCase.execute(userInfo.userId)
50+
51+
result shouldBe FindAllUserResponse.FindUserElement(
52+
userId = userInfo.userId,
53+
name = name,
54+
username = userInfo.username,
55+
profileFileName = profileFileName,
56+
contributions = userInfo.contributions,
57+
ranking = userInfo.ranking,
58+
)
59+
}
60+
}
61+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.xquare.git.git.usecase
2+
3+
import com.xquare.git.BaseApplicationTest
4+
import com.xquare.git.git.createGit
5+
import com.xquare.v1servicegit.git.port.CommandGitPort
6+
import com.xquare.v1servicegit.git.port.QueryGitPort
7+
import com.xquare.v1servicegit.git.usecase.SaveUsernameUseCase
8+
import io.mockk.coEvery
9+
import io.mockk.mockk
10+
11+
class SaveUsernameTest : BaseApplicationTest({
12+
val commandGitPort: CommandGitPort = mockk()
13+
val queryGitPort: QueryGitPort = mockk()
14+
15+
val saveUsernameUseCase = SaveUsernameUseCase(
16+
commandGitPort = commandGitPort,
17+
queryGitPort = queryGitPort,
18+
)
19+
20+
describe("κΉƒν—ˆλΈŒ μœ μ € 이름을 μ €μž₯ν•  λ•Œ") {
21+
val userInfo = createGit()
22+
23+
coEvery { queryGitPort.getContributionCount(userInfo.username) } returns userInfo.contributions
24+
coEvery { commandGitPort.saveUser(userInfo) } returns Unit
25+
26+
it("μœ μ € 이름을 μ €μž₯ν•œλ‹€.") {
27+
saveUsernameUseCase.execute(userInfo.userId, userInfo.username)
28+
}
29+
}
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.xquare.git.git.usecase
2+
3+
import com.xquare.git.BaseApplicationTest
4+
import com.xquare.git.git.createGit
5+
import com.xquare.v1servicegit.git.exceptions.GitExceptions
6+
import com.xquare.v1servicegit.git.port.CommandGitPort
7+
import com.xquare.v1servicegit.git.port.QueryGitPort
8+
import com.xquare.v1servicegit.git.usecase.UpdateGitUseCase
9+
import io.kotest.assertions.throwables.shouldThrow
10+
import io.mockk.coEvery
11+
import io.mockk.mockk
12+
13+
class UpdateGitTest : BaseApplicationTest({
14+
val queryGitPort: QueryGitPort = mockk()
15+
val commandGitPort: CommandGitPort = mockk()
16+
17+
val updateGitUseCase = UpdateGitUseCase(
18+
queryGitPort = queryGitPort,
19+
commandGitPort = commandGitPort,
20+
)
21+
22+
describe("λͺ¨λ“  κΉƒν—ˆλΈŒ 정보λ₯Ό 뢈러올 λ•Œ") {
23+
val ranking = 1
24+
val userInfo = createGit()
25+
val userList = listOf(userInfo)
26+
27+
context("νƒμƒ‰ν•˜λŠ” κΉƒν—ˆλΈŒ 정보가 μ‘΄μž¬ν•˜μ§€ μ•ŠμœΌλ©΄") {
28+
coEvery { queryGitPort.getAllGitByContributionCount() } returns userList
29+
coEvery { commandGitPort.updateContributionCount(userList) } returns emptyMap()
30+
coEvery { commandGitPort.updateGit(userInfo) } returns Unit
31+
32+
it("μ˜ˆμ™Έλ₯Ό λ˜μ§„λ‹€.") {
33+
shouldThrow<GitExceptions.NotFound> {
34+
updateGitUseCase.execute()
35+
}
36+
}
37+
}
38+
39+
coEvery { queryGitPort.getAllGitByContributionCount() } returns userList
40+
coEvery { commandGitPort.updateContributionCount(userList) } returns mapOf(userInfo.userId to ranking)
41+
coEvery { commandGitPort.updateGit(userInfo) } returns Unit
42+
43+
it("값을 μ—…λ°μ΄νŠΈν•œλ‹€.") {
44+
updateGitUseCase.execute()
45+
}
46+
}
47+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.xquare.git.github.usecase
2+
3+
import com.xquare.git.BaseApplicationTest
4+
import com.xquare.v1servicegit.git.exceptions.GitExceptions
5+
import com.xquare.v1servicegit.github.port.QueryGithubPort
6+
import com.xquare.v1servicegit.github.usecase.GetGithubAccessTokenUseCase
7+
import io.kotest.assertions.throwables.shouldThrow
8+
import io.kotest.matchers.shouldBe
9+
import io.mockk.coEvery
10+
import io.mockk.mockk
11+
12+
class GetGithubAccessTokenTest : BaseApplicationTest({
13+
val queryGithubPort: QueryGithubPort = mockk()
14+
15+
val getGithubAccessTokenUseCase = GetGithubAccessTokenUseCase(
16+
queryGithubPort = queryGithubPort,
17+
)
18+
19+
describe("κΉƒν—ˆλΈŒ 토큰을 κ°€μ Έμ˜¬ λ•Œ") {
20+
val code = "testCode"
21+
val accessToken = "testAccessToken"
22+
23+
context("토큰이 μœ νš¨ν•˜μ§€ μ•ŠμœΌλ©΄") {
24+
coEvery { queryGithubPort.getAccessToken(code).accessToken } returns null
25+
26+
it("μ˜ˆμ™Έλ₯Ό λ˜μ§„λ‹€.") {
27+
shouldThrow<GitExceptions.UnauthorizedToken> {
28+
getGithubAccessTokenUseCase.execute(code)
29+
}
30+
}
31+
}
32+
33+
coEvery { queryGithubPort.getAccessToken(code).accessToken } returns accessToken
34+
35+
it("Responseλ₯Ό λ°˜ν™˜ν•œλ‹€.") {
36+
val result = getGithubAccessTokenUseCase.execute(code)
37+
38+
result shouldBe accessToken
39+
}
40+
}
41+
})

0 commit comments

Comments
Β (0)