generated from pricelees/issue-pr-template
58 lines
2.0 KiB
Kotlin
58 lines
2.0 KiB
Kotlin
package roomescape.reservation.implement
|
|
|
|
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 io.mockk.verify
|
|
import org.springframework.data.repository.findByIdOrNull
|
|
import roomescape.reservation.exception.ReservationErrorCode
|
|
import roomescape.reservation.exception.ReservationException
|
|
import roomescape.reservation.infrastructure.persistence.ReservationRepository
|
|
import java.time.LocalDate
|
|
|
|
class ReservationFinderTest : FunSpec({
|
|
val reservationRepository: ReservationRepository = mockk()
|
|
val reservationValidator = ReservationValidator(reservationRepository)
|
|
|
|
val reservationFinder = ReservationFinder(reservationRepository, reservationValidator)
|
|
|
|
context("findById") {
|
|
val reservationId = 1L
|
|
test("동일한 ID인 시간을 찾아 응답한다.") {
|
|
every {
|
|
reservationRepository.findByIdOrNull(reservationId)
|
|
} returns mockk()
|
|
|
|
reservationFinder.findById(reservationId)
|
|
|
|
verify(exactly = 1) {
|
|
reservationRepository.findByIdOrNull(reservationId)
|
|
}
|
|
}
|
|
|
|
test("동일한 ID인 시간이 없으면 실패한다.") {
|
|
every {
|
|
reservationRepository.findByIdOrNull(reservationId)
|
|
} returns null
|
|
|
|
shouldThrow<ReservationException> {
|
|
reservationFinder.findById(reservationId)
|
|
}.also {
|
|
it.errorCode shouldBe ReservationErrorCode.RESERVATION_NOT_FOUND
|
|
}
|
|
}
|
|
}
|
|
|
|
context("searchReservations") {
|
|
test("시작 날짜가 종료 날짜 이전이면 실패한다.") {
|
|
shouldThrow<ReservationException> {
|
|
reservationFinder.searchReservations(1L, 1L, LocalDate.now(), LocalDate.now().minusDays(1))
|
|
}.also {
|
|
it.errorCode shouldBe ReservationErrorCode.INVALID_SEARCH_DATE_RANGE
|
|
}
|
|
}
|
|
}
|
|
})
|