generated from pricelees/issue-pr-template
refactor: ThemeService에서의 정상 저장 테스트 추가
This commit is contained in:
parent
50e8bbf668
commit
42780f1eed
@ -12,6 +12,7 @@ import roomescape.theme.exception.ThemeException
|
||||
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
||||
import roomescape.theme.infrastructure.persistence.ThemeRepository
|
||||
import roomescape.theme.web.ThemeCreateRequest
|
||||
import roomescape.theme.web.ThemeRetrieveResponse
|
||||
import roomescape.util.ThemeFixture
|
||||
|
||||
class ThemeServiceTest : FunSpec({
|
||||
@ -59,19 +60,43 @@ class ThemeServiceTest : FunSpec({
|
||||
}
|
||||
|
||||
context("save") {
|
||||
test("테마 이름이 중복되면 409 예외를 던진다.") {
|
||||
val name = "Duplicate Theme"
|
||||
val request = ThemeCreateRequest(
|
||||
name = "New Theme",
|
||||
description = "Description",
|
||||
thumbnail = "http://example.com/thumbnail.jpg"
|
||||
)
|
||||
|
||||
test("저장 성공") {
|
||||
every {
|
||||
themeRepository.existsByName(request.name)
|
||||
} returns false
|
||||
|
||||
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
|
||||
|
||||
val exception = shouldThrow<ThemeException> {
|
||||
themeService.createTheme(ThemeCreateRequest(
|
||||
name = name,
|
||||
description = "Description",
|
||||
thumbnail = "http://example.com/thumbnail.jpg"
|
||||
))
|
||||
themeService.createTheme(request)
|
||||
}
|
||||
|
||||
exception.errorCode shouldBe ThemeErrorCode.THEME_NAME_DUPLICATED
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user