[#20] 도메인별 예외 분리 #21

Merged
pricelees merged 37 commits from refactor/#20 into main 2025-07-24 02:48:53 +00:00
3 changed files with 22 additions and 24 deletions
Showing only changes of commit 0cbdcde8c7 - Show all commits

View File

@ -29,6 +29,7 @@ import roomescape.payment.infrastructure.persistence.PaymentEntity
import roomescape.reservation.infrastructure.persistence.ReservationEntity
import roomescape.reservation.infrastructure.persistence.ReservationStatus
import roomescape.reservation.infrastructure.persistence.TimeEntity
import roomescape.theme.exception.ThemeErrorCode
import roomescape.theme.infrastructure.persistence.ThemeEntity
import roomescape.util.*
import java.time.LocalDate
@ -123,7 +124,7 @@ class ReservationControllerTest(
// 예약 저장 과정에서 테마가 없는 예외
val invalidRequest = reservationRequest.copy(themeId = reservationRequest.themeId + 1)
val expectedException = RoomescapeException(ErrorType.THEME_NOT_FOUND, HttpStatus.BAD_REQUEST)
val expectedException = ThemeErrorCode.THEME_NOT_FOUND
every {
paymentClient.cancel(any())
@ -142,7 +143,7 @@ class ReservationControllerTest(
post("/reservations")
}.Then {
statusCode(expectedException.httpStatus.value())
body("errorType", equalTo(expectedException.errorType.name))
body("code", equalTo(expectedException.errorCode))
}
val canceledPaymentSizeAfterApiCall: Long = entityManager.createQuery(

View File

@ -7,9 +7,8 @@ import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import org.springframework.data.repository.findByIdOrNull
import org.springframework.http.HttpStatus
import roomescape.common.exception.ErrorType
import roomescape.common.exception.RoomescapeException
import roomescape.theme.exception.ThemeErrorCode
import roomescape.theme.exception.ThemeException
import roomescape.theme.infrastructure.persistence.ThemeEntity
import roomescape.theme.infrastructure.persistence.ThemeRepository
import roomescape.theme.web.ThemeCreateRequest
@ -36,11 +35,11 @@ class ThemeServiceTest : FunSpec({
themeRepository.findByIdOrNull(themeId)
} returns null
val exception = shouldThrow<RoomescapeException> {
val exception = shouldThrow<ThemeException> {
themeService.findById(themeId)
}
exception.errorType shouldBe ErrorType.THEME_NOT_FOUND
exception.errorCode shouldBe ThemeErrorCode.THEME_NOT_FOUND
}
}
@ -67,7 +66,7 @@ class ThemeServiceTest : FunSpec({
themeRepository.existsByName(name)
} returns true
val exception = shouldThrow<RoomescapeException> {
val exception = shouldThrow<ThemeException> {
themeService.createTheme(ThemeCreateRequest(
name = name,
description = "Description",
@ -75,10 +74,7 @@ class ThemeServiceTest : FunSpec({
))
}
assertSoftly(exception) {
this.errorType shouldBe ErrorType.THEME_DUPLICATED
this.httpStatus shouldBe HttpStatus.CONFLICT
}
exception.errorCode shouldBe ThemeErrorCode.THEME_NAME_DUPLICATED
}
}
@ -90,14 +86,11 @@ class ThemeServiceTest : FunSpec({
themeRepository.isReservedTheme(themeId)
} returns true
val exception = shouldThrow<RoomescapeException> {
val exception = shouldThrow<ThemeException> {
themeService.deleteTheme(themeId)
}
assertSoftly(exception) {
this.errorType shouldBe ErrorType.THEME_IS_USED_CONFLICT
this.httpStatus shouldBe HttpStatus.CONFLICT
}
exception.errorCode shouldBe ThemeErrorCode.THEME_ALREADY_RESERVED
}
}
})

View File

@ -13,6 +13,7 @@ import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import roomescape.auth.exception.AuthErrorCode
import roomescape.theme.business.ThemeService
import roomescape.theme.exception.ThemeErrorCode
import roomescape.theme.infrastructure.persistence.ThemeRepository
import roomescape.util.RoomescapeApiTest
import roomescape.util.ThemeFixture
@ -117,7 +118,9 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
When("동일한 이름의 테마가 있으면") {
loginAsAdmin()
Then("409 에러를 응답한다.") {
val expectedError = ThemeErrorCode.THEME_NAME_DUPLICATED
Then("에러 응답.") {
every {
themeRepository.existsByName(request.name)
} returns true
@ -127,8 +130,8 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
endpoint = endpoint,
body = request,
) {
status { isConflict() }
jsonPath("$.errorType") { value("THEME_DUPLICATED") }
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code") { value(expectedError.errorCode) }
}
}
}
@ -255,10 +258,11 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
}
}
When("입력된 ID에 해당하는 테마가 없으") {
When("이미 예약된 테마이") {
loginAsAdmin()
val expectedError = ThemeErrorCode.THEME_ALREADY_RESERVED
Then("409 에러 응답한다.") {
Then("에러 응답") {
every {
themeRepository.isReservedTheme(themeId)
} returns true
@ -267,8 +271,8 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { isConflict() }
jsonPath("$.errorType") { value("THEME_IS_USED_CONFLICT") }
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code") { value(expectedError.errorCode) }
}
}
}