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 { themeValidator.validateNameAlreadyExists(name) }.also { it.errorCode shouldBe ThemeErrorCode.THEME_NAME_DUPLICATED } } test("같은 이름을 가진 테마가 없으면 종료한다.") { every { themeRepository.existsByName(name) } returns false shouldNotThrow { themeValidator.validateNameAlreadyExists(name) } } } context("validateIsReserved") { test("입력된 id가 null 이면 예외를 던진다.") { shouldThrow { 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 { themeValidator.validateIsReserved(theme) }.also { it.errorCode shouldBe ThemeErrorCode.THEME_ALREADY_RESERVED } } test("예약이 없는 테마이면 종료한다.") { every { themeRepository.isReservedTheme(theme.id!!) } returns false shouldNotThrow { themeValidator.validateIsReserved(theme) } } } })