diff --git a/src/test/kotlin/roomescape/theme/business/ThemeServiceTest.kt b/src/test/kotlin/roomescape/theme/business/ThemeServiceTest.kt index 8386bd5b..8b56460b 100644 --- a/src/test/kotlin/roomescape/theme/business/ThemeServiceTest.kt +++ b/src/test/kotlin/roomescape/theme/business/ThemeServiceTest.kt @@ -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 { - themeService.createTheme(ThemeCreateRequest( - name = name, - description = "Description", - thumbnail = "http://example.com/thumbnail.jpg" - )) + themeService.createTheme(request) } exception.errorCode shouldBe ThemeErrorCode.THEME_NAME_DUPLICATED