generated from pricelees/issue-pr-template
[#20] 도메인별 예외 분리 #21
@ -12,6 +12,7 @@ import roomescape.theme.exception.ThemeException
|
|||||||
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
|
||||||
|
import roomescape.theme.web.ThemeRetrieveResponse
|
||||||
import roomescape.util.ThemeFixture
|
import roomescape.util.ThemeFixture
|
||||||
|
|
||||||
class ThemeServiceTest : FunSpec({
|
class ThemeServiceTest : FunSpec({
|
||||||
@ -59,19 +60,43 @@ class ThemeServiceTest : FunSpec({
|
|||||||
}
|
}
|
||||||
|
|
||||||
context("save") {
|
context("save") {
|
||||||
test("테마 이름이 중복되면 409 예외를 던진다.") {
|
val request = ThemeCreateRequest(
|
||||||
val name = "Duplicate Theme"
|
name = "New Theme",
|
||||||
|
description = "Description",
|
||||||
|
thumbnail = "http://example.com/thumbnail.jpg"
|
||||||
|
)
|
||||||
|
|
||||||
|
test("저장 성공") {
|
||||||
|
every {
|
||||||
|
themeRepository.existsByName(request.name)
|
||||||
|
} returns false
|
||||||
|
|
||||||
every {
|
every {
|
||||||
themeRepository.existsByName(name)
|
themeRepository.save(any())
|
||||||
|
} returns ThemeFixture.create(
|
||||||
|
id = 1L,
|
||||||
|
name = request.name,
|
||||||
|
description = request.description,
|
||||||
|
thumbnail = request.thumbnail
|
||||||
|
)
|
||||||
|
|
||||||
|
val response: ThemeRetrieveResponse = themeService.createTheme(request)
|
||||||
|
|
||||||
|
assertSoftly(response) {
|
||||||
|
this.id shouldBe 1L
|
||||||
|
this.name shouldBe request.name
|
||||||
|
this.description shouldBe request.description
|
||||||
|
this.thumbnail shouldBe request.thumbnail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test("테마 이름이 중복되면 409 예외를 던진다.") {
|
||||||
|
every {
|
||||||
|
themeRepository.existsByName(request.name)
|
||||||
} returns true
|
} returns true
|
||||||
|
|
||||||
val exception = shouldThrow<ThemeException> {
|
val exception = shouldThrow<ThemeException> {
|
||||||
themeService.createTheme(ThemeCreateRequest(
|
themeService.createTheme(request)
|
||||||
name = name,
|
|
||||||
description = "Description",
|
|
||||||
thumbnail = "http://example.com/thumbnail.jpg"
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exception.errorCode shouldBe ThemeErrorCode.THEME_NAME_DUPLICATED
|
exception.errorCode shouldBe ThemeErrorCode.THEME_NAME_DUPLICATED
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user