pricelees 5fe1427fc1 [#30] 코드 구조 개선 (#31)
<!-- 제목 양식 -->
<!-- [이슈번호] 작업 요약 (예시: [#10] Gitea 템플릿 생성) -->

## 📝 관련 이슈 및 PR

**PR과 관련된 이슈 번호**
- #30

##  작업 내용
<!-- 어떤 작업을 했는지 알려주세요! -->
- ReservationService를 읽기(Find) / 쓰기(Write) 서비스로 분리
- 모든 도메인에 repository를 사용하는 Finder, Writer, Validator 도입 -> ReservationService에 있는 조회, 검증, 쓰기 작업을 별도의 클래스로 분리하기 위함이었고, 이 과정에서 다른 도메인에도 도입함.

## 🧪 테스트
<!-- 어떤 테스트를 생각했고 진행했는지 알려주세요! -->
새로 추가된 기능 & 클래스는 모두 테스트 추가하였고, 작업 후 전체 테스트 완료

## 📚 참고 자료 및 기타
<!-- 참고한 자료, 또는 논의할 사항이 있다면 알려주세요! -->

Reviewed-on: #31
Co-authored-by: pricelees <priceelees@gmail.com>
Co-committed-by: pricelees <priceelees@gmail.com>
2025-08-06 10:16:08 +00:00

80 lines
2.5 KiB
Kotlin

package roomescape.theme.implement
import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import roomescape.theme.exception.ThemeErrorCode
import roomescape.theme.exception.ThemeException
import roomescape.theme.infrastructure.persistence.ThemeEntity
import roomescape.theme.infrastructure.persistence.ThemeRepository
import roomescape.util.ThemeFixture
class ThemeValidatorTest : FunSpec({
val themeRepository: ThemeRepository = mockk()
val themeValidator = ThemeValidator(themeRepository)
context("validateNameAlreadyExists") {
val name = "name"
test("같은 이름을 가진 테마가 있으면 예외를 던진다.") {
every {
themeRepository.existsByName(name)
} returns true
shouldThrow<ThemeException> {
themeValidator.validateNameAlreadyExists(name)
}.also {
it.errorCode shouldBe ThemeErrorCode.THEME_NAME_DUPLICATED
}
}
test("같은 이름을 가진 테마가 없으면 종료한다.") {
every {
themeRepository.existsByName(name)
} returns false
shouldNotThrow<ThemeException> {
themeValidator.validateNameAlreadyExists(name)
}
}
}
context("validateIsReserved") {
test("입력된 id가 null 이면 예외를 던진다.") {
shouldThrow<ThemeException> {
themeValidator.validateIsReserved(ThemeFixture.create(id = null))
}.also {
it.errorCode shouldBe ThemeErrorCode.INVALID_REQUEST_VALUE
}
}
val theme: ThemeEntity = ThemeFixture.create(id = 1L, name = "name")
test("예약이 있는 테마이면 예외를 던진다.") {
every {
themeRepository.isReservedTheme(theme.id!!)
} returns true
shouldThrow<ThemeException> {
themeValidator.validateIsReserved(theme)
}.also {
it.errorCode shouldBe ThemeErrorCode.THEME_ALREADY_RESERVED
}
}
test("예약이 없는 테마이면 종료한다.") {
every {
themeRepository.isReservedTheme(theme.id!!)
} returns false
shouldNotThrow<ThemeException> {
themeValidator.validateIsReserved(theme)
}
}
}
})