Skip to content

Commit

Permalink
Merge pull request #168 from KUSITMS-29th-TEAM-B/test/flight-165
Browse files Browse the repository at this point in the history
test: 역량 키워드 도메인 테스트 코드 작성(#165)
  • Loading branch information
whereami2048 authored May 23, 2024
2 parents f5b58e4 + f38ed47 commit 76cde35
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bamyanggang.domainmodule.domain.strongpoint.aggregate

import com.bamyanggang.commonmodule.fixture.generateFixture
import com.bamyanggang.domainmodule.domain.strongpoint.aggregate.StrongPoint
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -31,5 +30,4 @@ class StrongPointTest: FunSpec({

originStrongPoint.isDuplicated(name) shouldBe true
}

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.bamyanggang.domainmodule.domain.strongpoint.service

import com.bamyanggang.domainmodule.domain.strongpoint.repository.KeywordRepository
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
import io.mockk.verify
import java.util.*

class KeywordReaderTest : BehaviorSpec({
val keywordRepository = mockk<KeywordRepository>(relaxed = true)
val keywordReader = KeywordReader(keywordRepository)

Given("기본 역량 키워드 id 배열이 주어졌을 때") {
val defaultStrongPoints = arrayListOf(
UUID.randomUUID(),
UUID.randomUUID(),
UUID.randomUUID()
)

When("KeywordReader.readByIds 함수가 호출되면") {
keywordReader.readByIds(defaultStrongPoints)

Then("keywordRepository.findByIds 함수가 호출된다.") {
verify { keywordRepository.findByIds(defaultStrongPoints) }
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import io.mockk.verify
import java.util.*

class StrongPointAppenderTest : BehaviorSpec({
val strongPointRepository: StrongPointRepository = mockk<StrongPointRepository>(relaxed = true)
val strongPointRepository = mockk<StrongPointRepository>(relaxed = true)
val strongPointAppender = StrongPointAppender(strongPointRepository)

Given("역량 키워드 입력 값이 주어졌을 때") {
val name: String = "역량 키워드 이름"
val name = "역량 키워드 이름"
val userId: UUID = UUID.randomUUID()

When("StrongPointAppender.appendStrongPoint 함수가 호출되면") {
Expand All @@ -26,4 +26,22 @@ class StrongPointAppenderTest : BehaviorSpec({
}
}
}

Given("역량 키워드 이름 배열과 userId가 주어졌을 때") {
val names = arrayListOf(
"역량 키워드 이름 1",
"역량 키워드 이름 2",
"역량 키워드 이름 3",
)

val userId: UUID = UUID.randomUUID()

When("StrongPointAppender.appendAllStrongPoint 함수가 호출되면") {
strongPointAppender.appendAllStrongPoint(names, userId)

Then("StrongPointRepository.saveAll이 호출된다.") {
verify { strongPointRepository.saveAll(any()) }
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import io.mockk.verify
import java.util.*

class StrongPointReaderTest : BehaviorSpec({

val strongPointRepository: StrongPointRepository = mockk<StrongPointRepository>(relaxed = true)
val strongPointRepository = mockk<StrongPointRepository>(relaxed = true)
val strongPointReader = StrongPointReader(strongPointRepository)

Given("userId가 주어졌을 때") {
Expand All @@ -23,4 +22,38 @@ class StrongPointReaderTest : BehaviorSpec({
}
}
}

Given("userId 배열이 주어졌을 때") {
val userIds = arrayListOf(
UUID.randomUUID(),
UUID.randomUUID(),
UUID.randomUUID()
)

When("StrongPointReader.readByIds 함수가 호출되면") {
strongPointReader.readByIds(userIds)

Then("strongPointRepository.findByIds 함수가 호출된다.") {
verify { strongPointRepository.findByIds(userIds) }
}
}
}

Given("userId, search 검색 문자열이 주어졌을 때") {
val userId = UUID.randomUUID()
val search = "검색 문자열"

When("StrongPointReader.readIdsByUserIdAndNameContains 함수가 호출되면") {
strongPointReader.readIdsByUserIdAndNameContains(
userId = userId,
search = search)

Then("strongPointRepository.findByUserIdAndNameContains 함수가 호출된다.") {
verify { strongPointRepository.findByUserIdAndNameContains(
userId = userId,
search = search)
}
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.bamyanggang.domainmodule.domain.strongpoint.service

import com.bamyanggang.domainmodule.domain.strongpoint.exception.StrongPointExceptionMessage
import com.bamyanggang.domainmodule.domain.strongpoint.repository.StrongPointRepository
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import java.util.*

class StrongPointRemoverTest : BehaviorSpec({
val strongPointRepository = mockk<StrongPointRepository>(relaxed = true)
val strongPointRemover = StrongPointRemover(strongPointRepository)

Given("삭제할 역량 키워드 id가 주어졌을 때") {
val deleteStrongPointId = UUID.randomUUID()

When("StrongPointReader.removeStrongPoint 함수가 호출되면") {
every { strongPointRepository.isExistByStrongPointId(deleteStrongPointId) } returns true
strongPointRemover.removeStrongPoint(deleteStrongPointId)

Then("strongPointRepository.deleteByStrongPointId 함수가 호출된다.") {
verify { strongPointRepository.deleteByStrongPointId(deleteStrongPointId) }
}
}
}

Given("존재하지 않는 역량 키워드 id가 주어졌을 때") {
val deleteStrongPointId = UUID.randomUUID()

When("StrongPointReader.removeStrongPoint 함수가 호출되면") {
every { strongPointRepository.isExistByStrongPointId(deleteStrongPointId) } returns false
val exception = shouldThrow<IllegalArgumentException> {
strongPointRemover.removeStrongPoint(deleteStrongPointId)
}

Then("IllegalAgumentException이 발생한다.") {
assert(exception.message == StrongPointExceptionMessage.NOT_FOUND_STRONG_POINT.message)
}
}
}
})

0 comments on commit 76cde35

Please sign in to comment.