Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@ import io.swagger.v3.oas.annotations.media.Schema
data class AddBloomingRequest(
@Schema(description = "장소 ID", example = "1", nullable = true)
val flowerSpotId: Long? = null,
@Schema(description = "꽃 이벤트 ID", example = "1", nullable = true)
@Schema(description = "벚꽃 축제 ID", example = "1", nullable = true)
val flowerEventId: Long? = null,
@Schema(description = "카페 ID", example = "1", nullable = true)
val flowerSpotCafeId: Long? = null,
@Schema(description = "개화 상태", example = "BLOOMED")
val status: BloomingStatus,
) {
fun toNewBlooming(userId: Long): NewBlooming =
when {
flowerSpotId != null && flowerEventId == null ->
flowerSpotId != null && flowerEventId == null && flowerSpotCafeId == null ->
NewBlooming.FlowerSpot(
userId = userId,
flowerSpotId = flowerSpotId,
status = status,
)

flowerSpotId == null && flowerEventId != null ->
flowerSpotId == null && flowerEventId != null && flowerSpotCafeId == null ->
NewBlooming.FlowerEvent(
userId = userId,
flowerEventId = flowerEventId,
status = status,
)

flowerSpotId == null && flowerEventId == null && flowerSpotCafeId != null ->
NewBlooming.FlowerSpotCafe(
userId = userId,
flowerSpotCafeId = flowerSpotCafeId,
status = status,
)

else -> throw ErrorException(ErrorType.INVALID_REQUEST)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AddBloomingRequestTest {
result.userId shouldBe 10L
result.flowerSpotId shouldBe 1L
result.flowerEventId shouldBe null
result.flowerSpotCafeId shouldBe null
result.status shouldBe BloomingStatus.BLOOMED
}

Expand All @@ -43,19 +44,41 @@ class AddBloomingRequestTest {
result.userId shouldBe 11L
result.flowerSpotId shouldBe null
result.flowerEventId shouldBe 2L
result.flowerSpotCafeId shouldBe null
result.status shouldBe BloomingStatus.WITHERED
}

@Test
fun `flowerSpotId와 flowerEventId가 모두 없으면 INVALID_REQUEST를 던진다`() {
fun `flowerSpotCafeId만 있으면 FlowerSpotCafe 개화 입력으로 변환한다`() {
val request =
AddBloomingRequest(
flowerSpotId = null,
flowerEventId = null,
flowerSpotCafeId = 3L,
status = BloomingStatus.LITTLE,
)

val result = request.toNewBlooming(12L)

result.shouldBeInstanceOf<NewBlooming.FlowerSpotCafe>()
result.userId shouldBe 12L
result.flowerSpotId shouldBe null
result.flowerEventId shouldBe null
result.flowerSpotCafeId shouldBe 3L
result.status shouldBe BloomingStatus.LITTLE
}

@Test
fun `flowerSpotId와 flowerEventId와 flowerSpotCafeId가 모두 없으면 INVALID_REQUEST를 던진다`() {
val request =
AddBloomingRequest(
flowerSpotId = null,
flowerEventId = null,
flowerSpotCafeId = null,
status = BloomingStatus.BLOOMED,
)

val exception = assertThrows<ErrorException> { request.toNewBlooming(12L) }
val exception = assertThrows<ErrorException> { request.toNewBlooming(13L) }

exception.errorType shouldBe ErrorType.INVALID_REQUEST
}
Expand All @@ -66,10 +89,26 @@ class AddBloomingRequestTest {
AddBloomingRequest(
flowerSpotId = 1L,
flowerEventId = 2L,
flowerSpotCafeId = null,
status = BloomingStatus.BLOOMED,
)

val exception = assertThrows<ErrorException> { request.toNewBlooming(13L) }
val exception = assertThrows<ErrorException> { request.toNewBlooming(14L) }

exception.errorType shouldBe ErrorType.INVALID_REQUEST
}

@Test
fun `flowerSpotId와 flowerSpotCafeId가 모두 있으면 INVALID_REQUEST를 던진다`() {
val request =
AddBloomingRequest(
flowerSpotId = 1L,
flowerEventId = null,
flowerSpotCafeId = 3L,
status = BloomingStatus.BLOOMED,
)

val exception = assertThrows<ErrorException> { request.toNewBlooming(15L) }

exception.errorType shouldBe ErrorType.INVALID_REQUEST
}
Expand Down
Loading