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

View File

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

View File

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