Skip to content

Commit

Permalink
test: 테스트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Dompoo committed Aug 23, 2024
1 parent d1e3231 commit 6c1ed11
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MyPlantControllerTest : WebMvcDescribeSpec() {
init {
describe("내 식물 저장") {
beforeTest {
every { myPlantService.saveMyPlant(any(), any()) } returns
every { myPlantService.saveMyPlant(any(), any(), any()) } returns
MyPlantSaveResponse(
myPlantId = MYPLANT_ID,
message = "등록 되었습니다.",
Expand Down Expand Up @@ -221,8 +221,8 @@ class MyPlantControllerTest : WebMvcDescribeSpec() {

describe("내 식물 수정") {
beforeTest {
every { myPlantService.modifyMyPlant(any(), any(), any()) } just runs
every { myPlantService.modifyMyPlant(not(eq(MYPLANT_ID)), any(), any()) } throws
every { myPlantService.modifyMyPlant(any(), any(), any(), any()) } just runs
every { myPlantService.modifyMyPlant(not(eq(MYPLANT_ID)), any(), any(), any()) } throws
NotFoundException(ErrorType.NOT_FOUND_MYPLANT)
every {
myPlantService.modifyMyPlant(
Expand All @@ -231,6 +231,7 @@ class MyPlantControllerTest : WebMvcDescribeSpec() {
it.locationId != LOCATION_ID
},
any(),
any(),
)
} throws
NotFoundException(ErrorType.NOT_FOUND_LOCATION)
Expand Down Expand Up @@ -438,9 +439,9 @@ class MyPlantControllerTest : WebMvcDescribeSpec() {
const val LOCATION_ID = 100L
const val LOCATION_NAME = "거실"
val START_DATE: LocalDate = LocalDate.of(2024, 4, 19)
val WITH_DAYS = 234
val LAST_WATERED_DATE: LocalDate = LocalDate.of(2024, 6, 29)
val LAST_FERTILIZER_DATE: LocalDate = LocalDate.of(2024, 6, 15)
const val WITH_DAYS = 234
const val LAST_WATERED_DATE = 1
const val LAST_FERTILIZER_DATE = 2
val LAST_HEALTHCHECK_DATE: LocalDate = LocalDate.of(2024, 6, 15)
const val DATE_SINCE_LAST_WATER = 3
const val DATE_SINCE_LAST_FERTILIZER = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
}.andDo { print() }
}
}
context("마지막으로 물 준 날짜를 미래로 전달하면") {
context("마지막으로 물 준 날짜를 0~6 이외의 값으로 전달하면") {
val json =
objectMapper.writeValueAsString(
MyPlantSaveRequest(
Expand All @@ -112,7 +112,7 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
nickname = NICKNAME,
locationId = LOCATION_ID,
startDate = START_DATE,
lastWateredDate = FUTURE_DATE,
lastWateredDate = 7,
lastFertilizerDate = LAST_FERTILIZER_DATE,
waterAlarm = WATER_ALARM,
waterPeriod = WATER_PERIOD,
Expand All @@ -128,11 +128,11 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
}.andExpectAll {
status { isBadRequest() }
jsonPath("$.code", equalTo(ERROR_CODE))
jsonPath("$.message", equalTo("마지막으로 물 준 날짜는 미래일 수 없습니다."))
jsonPath("$.message", equalTo("1에서 6의 값을 입력하세요."))
}.andDo { print() }
}
}
context("마지막으로 비료 준 날짜를 미래로 전달하면") {
context("마지막으로 비료 준 날짜를 0~6 이외의 값으로 전달하면") {
val json =
objectMapper.writeValueAsString(
MyPlantSaveRequest(
Expand All @@ -142,7 +142,7 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
locationId = LOCATION_ID,
startDate = START_DATE,
lastWateredDate = LAST_WATERED_DATE,
lastFertilizerDate = FUTURE_DATE,
lastFertilizerDate = 7,
waterAlarm = WATER_ALARM,
waterPeriod = WATER_PERIOD,
fertilizerAlarm = FERTILIZER_ALARM,
Expand All @@ -157,7 +157,7 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
}.andExpectAll {
status { isBadRequest() }
jsonPath("$.code", equalTo(ERROR_CODE))
jsonPath("$.message", equalTo("마지막으로 비료 준 날짜는 미래일 수 없습니다."))
jsonPath("$.message", equalTo("1에서 6의 값을 입력하세요."))
}.andDo { print() }
}
}
Expand Down Expand Up @@ -273,14 +273,14 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
}.andDo { print() }
}
}
context("마지막으로 물 준 날짜를 미래로 전달하면") {
context("마지막으로 물 준 날짜를 1~6 이외의 값으로 전달하면") {
val json =
objectMapper.writeValueAsString(
MyPlantModifyRequest(
nickname = NICKNAME,
locationId = LOCATION_ID,
startDate = START_DATE,
lastWateredDate = FUTURE_DATE,
lastWateredDate = 7,
lastFertilizerDate = LAST_FERTILIZER_DATE,
),
)
Expand All @@ -291,19 +291,19 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
}.andExpectAll {
status { isBadRequest() }
jsonPath("$.code", equalTo(ERROR_CODE))
jsonPath("$.message", equalTo("마지막으로 물 준 날짜는 미래일 수 없습니다."))
jsonPath("$.message", equalTo("1에서 6의 값을 입력하세요."))
}.andDo { print() }
}
}
context("마지막으로 비료 준 날짜를 미래로 전달하면") {
context("마지막으로 비료 준 날짜를 1~6 이외의 값으로 전달하면") {
val json =
objectMapper.writeValueAsString(
MyPlantModifyRequest(
nickname = NICKNAME,
locationId = LOCATION_ID,
startDate = START_DATE,
lastWateredDate = LAST_WATERED_DATE,
lastFertilizerDate = FUTURE_DATE,
lastFertilizerDate = 7,
),
)
it("예외 응답이 와야 한다.") {
Expand All @@ -313,7 +313,7 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
}.andExpectAll {
status { isBadRequest() }
jsonPath("$.code", equalTo(ERROR_CODE))
jsonPath("$.message", equalTo("마지막으로 비료 준 날짜는 미래일 수 없습니다."))
jsonPath("$.message", equalTo("1에서 6의 값을 입력하세요."))
}.andDo { print() }
}
}
Expand Down Expand Up @@ -398,8 +398,8 @@ class MyPlantControllerValidationTest : WebMvcDescribeSpec() {
const val LOCATION_ID = 100L
val FUTURE_DATE: LocalDate = LocalDate.now().plusDays(1)
val START_DATE: LocalDate = LocalDate.of(2024, 4, 19)
val LAST_WATERED_DATE: LocalDate = LocalDate.of(2024, 6, 29)
val LAST_FERTILIZER_DATE: LocalDate = LocalDate.of(2024, 6, 15)
const val LAST_WATERED_DATE = 1
const val LAST_FERTILIZER_DATE = 2
const val WATER_ALARM = true
const val WATER_PERIOD = 3
const val FERTILIZER_ALARM = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ class MyPlantServiceTest : DescribeSpec(
plantId = PLANT_ID,
locationId = LOCATION_ID,
startDate = START_DATE,
lastWateredDate = LAST_WATERED_DATE,
lastFertilizerDate = LAST_FERTILIZER_DATE,
lastWateredDate = LAST_WATERED_DATE_INT,
lastFertilizerDate = LAST_FERTILIZER_DATE_INT,
waterAlarm = WATER_ALARM,
waterPeriod = WATER_PERIOD,
fertilizerAlarm = FERTILIZER_ALARM,
fertilizerPeriod = FERTILIZER_PERIOD,
healthCheckAlarm = HEALTHCHECK_ALARM,
)
it("정상적으로 저장되고 예외가 발생하면 안된다.") {
val result = myPlantService.saveMyPlant(request, USER)
val result = myPlantService.saveMyPlant(request, USER, CURRENT_DAY)

result.myPlantId shouldBe MYPLANT_ID
result.message shouldBe "등록 되었습니다."
Expand Down Expand Up @@ -294,11 +294,11 @@ class MyPlantServiceTest : DescribeSpec(
nickname = NICKNAME,
locationId = LOCATION_ID,
startDate = START_DATE,
lastWateredDate = LAST_WATERED_DATE,
lastFertilizerDate = LAST_FERTILIZER_DATE,
lastWateredDate = LAST_WATERED_DATE_INT,
lastFertilizerDate = LAST_FERTILIZER_DATE_INT,
)
it("정상 흐름을 반환해야 한다.") {
myPlantService.modifyMyPlant(MYPLANT_ID, request, USER)
myPlantService.modifyMyPlant(MYPLANT_ID, request, USER, CURRENT_DAY)
}
}
context("존재하지 않는 내 식물 ID로 수정하면") {
Expand All @@ -307,12 +307,19 @@ class MyPlantServiceTest : DescribeSpec(
nickname = NICKNAME,
locationId = LOCATION_ID,
startDate = START_DATE,
lastWateredDate = LAST_WATERED_DATE,
lastFertilizerDate = LAST_FERTILIZER_DATE,
lastWateredDate = LAST_WATERED_DATE_INT,
lastFertilizerDate = LAST_FERTILIZER_DATE_INT,
)
it("NotFoundException(NOT_FOUND_MYPLANT_ID) 예외가 발생해야 한다.") {
val exception =
shouldThrow<NotFoundException> { myPlantService.modifyMyPlant(MYPLANT_ID2, request, USER) }
shouldThrow<NotFoundException> {
myPlantService.modifyMyPlant(
MYPLANT_ID2,
request,
USER,
CURRENT_DAY,
)
}
exception.message shouldBe "존재하지 않는 내 식물입니다."
exception.errorType shouldBe ErrorType.NOT_FOUND_MYPLANT
}
Expand All @@ -323,12 +330,19 @@ class MyPlantServiceTest : DescribeSpec(
nickname = NICKNAME,
locationId = LOCATION_ID + 1,
startDate = START_DATE,
lastWateredDate = LAST_WATERED_DATE,
lastFertilizerDate = LAST_FERTILIZER_DATE,
lastWateredDate = LAST_WATERED_DATE_INT,
lastFertilizerDate = LAST_FERTILIZER_DATE_INT,
)
it("NotFoundException(NOT_FOUND_LOCATION_ID) 예외가 발생해야 한다.") {
val exception =
shouldThrow<NotFoundException> { myPlantService.modifyMyPlant(MYPLANT_ID, request, USER) }
shouldThrow<NotFoundException> {
myPlantService.modifyMyPlant(
MYPLANT_ID,
request,
USER,
CURRENT_DAY,
)
}
exception.message shouldBe "존재하지 않는 위치입니다."
exception.errorType shouldBe ErrorType.NOT_FOUND_LOCATION
}
Expand Down Expand Up @@ -535,7 +549,9 @@ class MyPlantServiceTest : DescribeSpec(

val START_DATE: LocalDate = CURRENT_DAY.minusDays(1)
val LAST_WATERED_DATE: LocalDate = CURRENT_DAY.minusDays(1)
const val LAST_WATERED_DATE_INT = 1
val LAST_FERTILIZER_DATE: LocalDate = CURRENT_DAY.minusDays(1)
const val LAST_FERTILIZER_DATE_INT = 1
val LAST_HEALTHCHECK_DATE: LocalDate = CURRENT_DAY.minusDays(1)

const val WATER_ALARM = true
Expand Down

0 comments on commit 6c1ed11

Please sign in to comment.