diff --git a/src/main/kotlin/gdsc/plantory/plant/presentation/dto/PlantHistoryDto.kt b/src/main/kotlin/gdsc/plantory/plant/presentation/dto/PlantHistoryDto.kt index 8fa8d54..fb0c39e 100644 --- a/src/main/kotlin/gdsc/plantory/plant/presentation/dto/PlantHistoryDto.kt +++ b/src/main/kotlin/gdsc/plantory/plant/presentation/dto/PlantHistoryDto.kt @@ -1,7 +1,7 @@ package gdsc.plantory.plant.presentation.dto -import gdsc.plantory.plant.domain.PlantHistory import gdsc.plantory.plant.domain.HistoryType +import gdsc.plantory.plant.domain.PlantHistory import java.time.LocalDate data class PlantHistoryDto( diff --git a/src/test/kotlin/gdsc/plantory/acceptance/CompanionPlantAcceptanceTest.kt b/src/test/kotlin/gdsc/plantory/acceptance/CompanionPlantAcceptanceTest.kt index 82b080a..918a4a9 100644 --- a/src/test/kotlin/gdsc/plantory/acceptance/CompanionPlantAcceptanceTest.kt +++ b/src/test/kotlin/gdsc/plantory/acceptance/CompanionPlantAcceptanceTest.kt @@ -1,21 +1,18 @@ package gdsc.plantory.acceptance import gdsc.plantory.acceptance.CommonStep.Companion.응답_확인 -import gdsc.plantory.acceptance.CompanionPlantStep.Companion.반려_식물_등록_요청 -import gdsc.plantory.acceptance.CompanionPlantStep.Companion.식물_조회_요청 import gdsc.plantory.acceptance.CompanionPlantStep.Companion.데일리_기록_등록_요청 import gdsc.plantory.acceptance.CompanionPlantStep.Companion.데일리_기록_조회_요청 import gdsc.plantory.acceptance.CompanionPlantStep.Companion.데일리_기록_조회_응답_확인 +import gdsc.plantory.acceptance.CompanionPlantStep.Companion.반려_식물_등록_요청 import gdsc.plantory.acceptance.CompanionPlantStep.Companion.반려_식물_삭제_요청 -import gdsc.plantory.acceptance.CompanionPlantStep.Companion.식물_히스토리_생성_요청 +import gdsc.plantory.acceptance.CompanionPlantStep.Companion.식물_조회_요청 import gdsc.plantory.acceptance.CompanionPlantStep.Companion.식물_조회_응답_확인 +import gdsc.plantory.acceptance.CompanionPlantStep.Companion.식물_히스토리_생성_요청 import gdsc.plantory.acceptance.CompanionPlantStep.Companion.히스토리_조회_요청 import gdsc.plantory.acceptance.CompanionPlantStep.Companion.히스토리_조회_응답_확인 -import gdsc.plantory.fixture.기록없는_테스트식물_ID -import gdsc.plantory.fixture.기록있는_테스트식물_ID -import gdsc.plantory.fixture.테스터_디바이스_토큰 -import gdsc.plantory.fixture.테스트_식물정보_ID import gdsc.plantory.fixture.CompanionPlantFixture.generateCompanionPlantCreateRequest +import gdsc.plantory.fixture.테스터_디바이스_토큰 import gdsc.plantory.plant.presentation.dto.PlantHistoryRequest import gdsc.plantory.plant.presentation.dto.PlantRecordCreateRequest import gdsc.plantory.util.AcceptanceTest @@ -31,7 +28,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() { @Test fun `반려식물 등록`() { // given - val 반려_식물_정보 = generateCompanionPlantCreateRequest(테스트_식물정보_ID) + val 반려_식물_정보 = generateCompanionPlantCreateRequest(1L) // when val 식물_등록_요청_응답 = 반려_식물_등록_요청(반려_식물_정보, 테스터_디바이스_토큰) @@ -43,7 +40,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() { @Test fun `반려식물 삭제`() { // when - val 식물_삭제_요청_응답 = 반려_식물_삭제_요청(기록있는_테스트식물_ID, 테스터_디바이스_토큰) + val 식물_삭제_요청_응답 = 반려_식물_삭제_요청(1L, 테스터_디바이스_토큰) // then 응답_확인(식물_삭제_요청_응답, HttpStatus.NO_CONTENT) @@ -55,7 +52,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() { val 물줌_기록 = PlantHistoryRequest("WATER_CHANGE") // when - val 식물_히스토리_생성_응답 = 식물_히스토리_생성_요청(기록없는_테스트식물_ID, 물줌_기록, 테스터_디바이스_토큰) + val 식물_히스토리_생성_응답 = 식물_히스토리_생성_요청(2L, 물줌_기록, 테스터_디바이스_토큰) // then 응답_확인(식물_히스토리_생성_응답, HttpStatus.OK) @@ -76,7 +73,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() { val 데일리_기록_정보 = PlantRecordCreateRequest("오늘도 즐거운 하루~!") // when - val 데일리_기록_등록_요청_응답 = 데일리_기록_등록_요청(기록없는_테스트식물_ID, 데일리_기록_정보, 테스터_디바이스_토큰) + val 데일리_기록_등록_요청_응답 = 데일리_기록_등록_요청(2L, 데일리_기록_정보, 테스터_디바이스_토큰) // then 응답_확인(데일리_기록_등록_요청_응답, HttpStatus.OK) @@ -90,15 +87,11 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() { @Test fun `반려식물 데일리 기록 중복 등록`() { // given - 데일리_기록_등록_요청( - 기록없는_테스트식물_ID, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰 - ) + 데일리_기록_등록_요청(2L, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰) // when val 데일리_기록_등록_요청_응답 = - 데일리_기록_등록_요청( - 기록없는_테스트식물_ID, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰 - ) + 데일리_기록_등록_요청(2L, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰) // then 응답_확인(데일리_기록_등록_요청_응답, HttpStatus.CONFLICT) @@ -107,7 +100,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() { @Test fun `반려식물 데일리 기록 조회`() { // when - val 데일리_기록_조회_요청_응답 = 데일리_기록_조회_요청(기록있는_테스트식물_ID, LocalDate.now(), 테스터_디바이스_토큰) + val 데일리_기록_조회_요청_응답 = 데일리_기록_조회_요청(1L, LocalDate.now(), 테스터_디바이스_토큰) // then 데일리_기록_조회_응답_확인(데일리_기록_조회_요청_응답) @@ -116,7 +109,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() { @Test fun `반려식물 히스토리 조회`() { // when - val 히스토리_조회_요청_응답 = 히스토리_조회_요청(기록있는_테스트식물_ID, YearMonth.parse("2024-01"), 테스터_디바이스_토큰) + val 히스토리_조회_요청_응답 = 히스토리_조회_요청(1L, YearMonth.parse("2024-01"), 테스터_디바이스_토큰) // then 히스토리_조회_응답_확인(히스토리_조회_요청_응답) diff --git a/src/test/kotlin/gdsc/plantory/fixture/CompanionPlantFixture.kt b/src/test/kotlin/gdsc/plantory/fixture/CompanionPlantFixture.kt index fbfc034..816743a 100644 --- a/src/test/kotlin/gdsc/plantory/fixture/CompanionPlantFixture.kt +++ b/src/test/kotlin/gdsc/plantory/fixture/CompanionPlantFixture.kt @@ -4,60 +4,29 @@ import gdsc.plantory.plant.domain.CompanionPlant import gdsc.plantory.plant.presentation.dto.CompanionPlantCreateRequest import java.time.LocalDate -private var _기록없는_테스트식물_ID = 0L -val 기록없는_테스트식물_ID - get() = _기록없는_테스트식물_ID - -private var _기록있는_테스트식물_ID = 0L -val 기록있는_테스트식물_ID - get() = _기록있는_테스트식물_ID - - object CompanionPlantFixture { - val 덕구리난: CompanionPlant = CompanionPlant( - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _shortDescription = "덕구리난은 덕구리난과!", - _nickname = "덕구리1", - birthDate = LocalDate.of(2024, 1, 1), - nextWaterDate = LocalDate.of(2024, 1, 10), - lastWaterDate = LocalDate.of(2024, 1, 7), - waterCycle = 3, - plantInformationId = 테스트_식물정보_ID, - memberId = 테스터_ID, - ) - - fun generateTestCompanionPlantHasNoHistories(id: Long): CompanionPlant { - _기록없는_테스트식물_ID = id - + fun generateCompanionPlant( + memberId: Long = 0L, + plantInformationId: Long = 0L, + imageUrl: String = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", + shortDescription: String = "덕구리난은 덕구리난과!", + nickname: String = "테스트 식물", + nextWaterDate: LocalDate = LocalDate.of(2024, 1, 10), + lastWaterDate: LocalDate = LocalDate.of(2024, 1, 7), + waterCycle: Int = 3, + birthDate: LocalDate = LocalDate.of(2024, 1, 1), + ): CompanionPlant { return CompanionPlant( - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _shortDescription = "덕구리난은 덕구리난과!", - _nickname = "히스토리 없는 테스트식물", - birthDate = LocalDate.of(2024, 1, 1), - nextWaterDate = LocalDate.of(2024, 1, 10), - lastWaterDate = LocalDate.of(2024, 1, 7), - waterCycle = 3, - plantInformationId = 테스트_식물정보_ID, - memberId = 테스터_ID, - id = id - ) - } - - fun generateTestCompanionPlantWillHaveHistories(id: Long): CompanionPlant { - _기록있는_테스트식물_ID = id - - return CompanionPlant( - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _shortDescription = "덕구리난은 덕구리난과!", - _nickname = "히스토리 있는 테스트식물", - birthDate = LocalDate.of(2024, 1, 1), - nextWaterDate = LocalDate.of(2024, 1, 10), - lastWaterDate = LocalDate.of(2024, 1, 7), - waterCycle = 3, - plantInformationId = 테스트_식물정보_ID, - memberId = 테스터_ID, - id = id + _imageUrl = imageUrl, + _shortDescription = shortDescription, + _nickname = nickname, + nextWaterDate = nextWaterDate, + lastWaterDate = lastWaterDate, + waterCycle = waterCycle, + birthDate = birthDate, + memberId = memberId, + plantInformationId = plantInformationId, ) } diff --git a/src/test/kotlin/gdsc/plantory/fixture/MemberFixture.kt b/src/test/kotlin/gdsc/plantory/fixture/MemberFixture.kt index 788b7d4..12b42bb 100644 --- a/src/test/kotlin/gdsc/plantory/fixture/MemberFixture.kt +++ b/src/test/kotlin/gdsc/plantory/fixture/MemberFixture.kt @@ -2,20 +2,11 @@ package gdsc.plantory.fixture import gdsc.plantory.member.domain.Member -private var _테스터_ID = 0L -val 테스터_ID: Long - get() = _테스터_ID - -const val 테스터_디바이스_토큰 = "device-token" +const val 테스터_디바이스_토큰 = "tester-token" object MemberFixture { - fun generateTestMember(id: Long): Member { - _테스터_ID = id - - return Member( - deviceToken = 테스터_디바이스_토큰, - id = id - ) + fun generateMember(deviceToken: String = "device-token"): Member { + return Member(deviceToken = deviceToken) } } \ No newline at end of file diff --git a/src/test/kotlin/gdsc/plantory/fixture/PlantInformationFixture.kt b/src/test/kotlin/gdsc/plantory/fixture/PlantInformationFixture.kt index 9a82973..591c02c 100644 --- a/src/test/kotlin/gdsc/plantory/fixture/PlantInformationFixture.kt +++ b/src/test/kotlin/gdsc/plantory/fixture/PlantInformationFixture.kt @@ -2,33 +2,43 @@ package gdsc.plantory.fixture import gdsc.plantory.plantInformation.domain.PlantInformation -private var _테스트_식물정보_ID = 0L -val 테스트_식물정보_ID: Long - get() = _테스트_식물정보_ID - object PlantInformationFixture { - fun generateTestPlantInformation(id: Long): PlantInformation { - _테스트_식물정보_ID = id - + fun generatePlantInformation( + imageUrl: String = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", + species: String = "덕구리난", + familyName: String = "백합과", + requireTemp: String = "21~25℃", + minimumTemp: String = "13℃ 이상", + waterCycleSpring: Int = 4, + waterCycleSummer: Int = 3, + waterCycleAutumn: Int = 4, + waterCycleWinter: Int = 4, + smell: String = "거의 없음", + manageLevel: String = "초보자", + growSpeed: String = "느림", + requireHumidity: String = "40% 미만", + postingPlace: String = "거실 창측 (실내깊이 150~300cm),발코니 내측 (실내깊이 50~150cm),발코니 창측 (실내깊이 0~50cm)", + poison: String = "없음", + specialManageInfo: String = "적절한 환기가 필요함, 여름동안 햇볕이 잘드는 위치에 배치하는 것이 좋음.", + ): PlantInformation { return PlantInformation( - _species = "덕구리난", - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _familyName = "백합과", - smell = "거의 없음", - poison = "없음", - manageLevel = "초보자", - growSpeed = "느림", - _requireTemp = "21~25℃", - _minimumTemp = "13℃ 이상", - requireHumidity = "40% 미만", - postingPlace = "거실 창측 (실내깊이 150~300cm),발코니 내측 (실내깊이 50~150cm),발코니 창측 (실내깊이 0~50cm)", - specialManageInfo = "적절한 환기가 필요함, 여름동안 햇볕이 잘드는 위치에 배치하는 것이 좋음.", - _waterCycleSpring = 4, - _waterCycleSummer = 3, - _waterCycleAutumn = 4, - _waterCycleWinter = 4, - id = id, + _imageUrl = imageUrl, + _species = species, + _familyName = familyName, + _requireTemp = requireTemp, + _minimumTemp = minimumTemp, + _waterCycleSpring = waterCycleSpring, + _waterCycleSummer = waterCycleSummer, + _waterCycleAutumn = waterCycleAutumn, + _waterCycleWinter = waterCycleWinter, + smell = smell, + manageLevel = manageLevel, + growSpeed = growSpeed, + requireHumidity = requireHumidity, + postingPlace = postingPlace, + poison = poison, + specialManageInfo = specialManageInfo, ) } } \ No newline at end of file diff --git a/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantRepositoryTest.kt b/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantRepositoryTest.kt index bad6b4c..58550a4 100644 --- a/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantRepositoryTest.kt +++ b/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantRepositoryTest.kt @@ -1,6 +1,7 @@ package gdsc.plantory.plant.domain -import gdsc.plantory.member.domain.Member +import gdsc.plantory.fixture.CompanionPlantFixture.generateCompanionPlant +import gdsc.plantory.fixture.MemberFixture.generateMember import gdsc.plantory.member.domain.MemberRepository import gdsc.plantory.util.AcceptanceTest import org.assertj.core.api.Assertions.assertThat @@ -19,7 +20,7 @@ class CompanionPlantRepositoryTest( @Test fun `물주는 날짜가 된 반려식물의 별칭과 해당 유저의 deviceToken을 조회한다`() { // given - val member = Member("shine") + val member = generateMember(deviceToken = "shine") val savedMember = memberRepository.save(member) val memberId = savedMember.getId @@ -50,15 +51,12 @@ class CompanionPlantRepositoryTest( ) } - private fun createCompanionPlantByLastWaterDate(nextWaterDate: LocalDate, memberId: Long) = CompanionPlant( - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _shortDescription = "덕구리난은 덕구리난과!", - _nickname = nextWaterDate.toString(), - birthDate = LocalDate.of(2024, 1, 1), - nextWaterDate = nextWaterDate, - lastWaterDate = LocalDate.of(2024, 1, 4), - waterCycle = 3, - plantInformationId = 1L, - memberId = memberId, - ) + private fun createCompanionPlantByLastWaterDate(nextWaterDate: LocalDate, memberId: Long) = + generateCompanionPlant( + memberId = memberId, + nickname = nextWaterDate.toString(), + nextWaterDate = nextWaterDate, + lastWaterDate = nextWaterDate.minusDays(5), + waterCycle = 5 + ) } diff --git a/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantTest.kt b/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantTest.kt index ff97ee4..cee8dba 100644 --- a/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantTest.kt +++ b/src/test/kotlin/gdsc/plantory/plant/domain/CompanionPlantTest.kt @@ -1,7 +1,7 @@ package gdsc.plantory.plant.domain import ConflictException -import gdsc.plantory.fixture.CompanionPlantFixture +import gdsc.plantory.fixture.CompanionPlantFixture.generateCompanionPlant import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatCode import org.assertj.core.api.Assertions.assertThatThrownBy @@ -17,10 +17,12 @@ class CompanionPlantTest { @Test fun `반려식물 생성`() { + // given val waterCycle = 7L val lastWaterDate = LocalDate.now() val nextWaterDate = lastWaterDate.plusDays(waterCycle) + // when, then assertThatCode { CompanionPlant( "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", @@ -32,14 +34,10 @@ class CompanionPlantTest { @Test fun `반려식물에게 레코드 타입의 히스토리를 직접 저장하려는 경우 예외 발생`() { - val waterCycle = 7L - val lastWaterDate = LocalDate.now() - val nextWaterDate = lastWaterDate.plusDays(waterCycle) - val companionPlant = CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", "shine", nextWaterDate, lastWaterDate, waterCycle.toInt() - ) + // given + val companionPlant = generateCompanionPlant() + // when, then assertThatThrownBy { companionPlant.saveHistory(HistoryType.RECORDING, LocalDate.now()) } @@ -49,14 +47,17 @@ class CompanionPlantTest { @Test fun `물 준 주기가 맞지 않으면 예외 발생`() { + // given val waterCycle = 7L val lastWaterDate = LocalDate.now() val nextWaterDate = lastWaterDate.minusDays(1) + // when, then assertThatThrownBy { - CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", "shine", nextWaterDate, lastWaterDate, waterCycle.toInt() + generateCompanionPlant( + nextWaterDate = nextWaterDate, + lastWaterDate = lastWaterDate, + waterCycle = waterCycle.toInt() ) } .isInstanceOf(IllegalArgumentException::class.java) @@ -66,10 +67,7 @@ class CompanionPlantTest { @Test fun `데일리 기록 작성`() { // given - val companionPlant = CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", "shine", LocalDate.now().plusDays(7), LocalDate.now(), 7 - ) + val companionPlant = generateCompanionPlant() // when, then assertThatCode { @@ -84,10 +82,7 @@ class CompanionPlantTest { @Test fun `데일리 기록을 이미 등록한 날짜에 중복 등록하면 예외가 발생`() { // given - val companionPlant = CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", "shine", LocalDate.now().plusDays(7), LocalDate.now(), 7 - ) + val companionPlant = generateCompanionPlant() companionPlant.saveRecord("오늘의 기록!") // when, then @@ -100,10 +95,7 @@ class CompanionPlantTest { @Test fun `히스토리 생성`() { // given - val companionPlant = CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", "shine", LocalDate.now().plusDays(7), LocalDate.now(), 7 - ) + val companionPlant = generateCompanionPlant() // when companionPlant.saveHistory(HistoryType.WATER_CHANGE, LocalDate.now()) @@ -120,11 +112,7 @@ class CompanionPlantTest { // when, then assertThatThrownBy { - CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", tooLongNickName, LocalDate.now().plusDays(7), LocalDate.now(), - 7, LocalDate.of(2023, 1, 1) - ) + generateCompanionPlant(nickname = tooLongNickName) } .isInstanceOf(IllegalArgumentException::class.java) .hasMessageContaining("\"nickName\"은 16자를 초과할 수 없습니다.") @@ -137,11 +125,7 @@ class CompanionPlantTest { // when, then assertThatThrownBy { - CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - tooLongDescription, "shine", LocalDate.now().plusDays(7), LocalDate.now(), - 7, LocalDate.of(2023, 1, 1) - ) + generateCompanionPlant(shortDescription = tooLongDescription) } .isInstanceOf(IllegalArgumentException::class.java) .hasMessageContaining("\"shortDescription\"은 16자를 초과할 수 없습니다.") @@ -151,11 +135,7 @@ class CompanionPlantTest { @CsvSource(value = ["2023,1,1,1", "2023,1,7,7", "2023,2,1,32"]) fun `반려식물과 함께한 일수 계산`(year: Int, month: Int, day: Int, daySince: Int) { // given - val companionPlant = CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", "shine", LocalDate.now().plusDays(7), LocalDate.now(), - 7, LocalDate.of(2023, 1, 1) - ) + val companionPlant = generateCompanionPlant(birthDate = LocalDate.of(2023, 1, 1)) // when val result: Int = companionPlant.calculateDaySince(LocalDate.of(year, month, day)) @@ -167,11 +147,7 @@ class CompanionPlantTest { @Test fun `함께한날 계산시 생일 이전의 날을 입력하면 예외가 발생`() { // given - val companionPlant = CompanionPlant( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "나의 아기 선인장", "shine", LocalDate.now().plusDays(7), LocalDate.now(), - 7, LocalDate.of(2023, 1, 1) - ) + val companionPlant = generateCompanionPlant(birthDate = LocalDate.of(2023, 1, 1)) // when, then assertThatThrownBy { @@ -184,9 +160,13 @@ class CompanionPlantTest { @Test fun `물을 주면 다음에 물을 주어야 할 날짜와 마지막으로 물 준 날짜 변경`() { // given - val companionPlant: CompanionPlant = CompanionPlantFixture.덕구리난 + val companionPlant: CompanionPlant = generateCompanionPlant( + lastWaterDate = LocalDate.of(1995, 5, 25), + nextWaterDate = LocalDate.of(1995, 5, 30), + waterCycle = 5 + ) val currentWaterDate = LocalDate.now() - val nextWaterDate = currentWaterDate.plusDays(companionPlant.getWaterCycle.toLong()) + val nextWaterDate = currentWaterDate.plusDays(5) // when companionPlant.saveHistory(HistoryType.WATER_CHANGE, currentWaterDate) @@ -200,7 +180,7 @@ class CompanionPlantTest { @Test fun `당일이 아닌 날에 물을 줄려 하는 경우 예외 발생`() { // given - val companionPlant: CompanionPlant = CompanionPlantFixture.덕구리난 + val companionPlant: CompanionPlant = generateCompanionPlant() val currentWaterDate = LocalDate.of(2024, 1, 10) // when, then diff --git a/src/test/kotlin/gdsc/plantory/plant/service/PlantServiceTest.kt b/src/test/kotlin/gdsc/plantory/plant/service/PlantServiceTest.kt index 102b04b..52d4b49 100644 --- a/src/test/kotlin/gdsc/plantory/plant/service/PlantServiceTest.kt +++ b/src/test/kotlin/gdsc/plantory/plant/service/PlantServiceTest.kt @@ -1,16 +1,14 @@ package gdsc.plantory.plant.service -import gdsc.plantory.fixture.기록없는_테스트식물_ID +import gdsc.plantory.fixture.CompanionPlantFixture.generateCompanionPlant +import gdsc.plantory.fixture.PlantInformationFixture.generatePlantInformation import gdsc.plantory.fixture.테스터_디바이스_토큰 -import gdsc.plantory.plant.domain.CompanionPlant import gdsc.plantory.plant.domain.CompanionPlantRepository import gdsc.plantory.plant.domain.HistoryType -import gdsc.plantory.plantInformation.domain.PlantInformation import gdsc.plantory.plantInformation.domain.PlantInformationRepository import gdsc.plantory.util.AcceptanceTest import jakarta.persistence.EntityManager import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Assertions.assertAll import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test @@ -27,51 +25,14 @@ class PlantServiceTest( @Autowired val plantInformationRepository: PlantInformationRepository, ) : AcceptanceTest() { - @Test - fun `데일리 기록 히스토리는 직접 추가할 수 없다`() { - // when, then - assertThatThrownBy { - plantService.createPlantHistory(기록없는_테스트식물_ID, 테스터_디바이스_토큰, HistoryType.RECORDING) - } - .isInstanceOf(IllegalArgumentException::class.java) - .hasMessageContaining("데일리 기록은 히스토리 타입을 직접 추가할 수 없습니다.") - } - @Test fun `사용자는 식물의 데일리 기록을 조회하여 사진, 본문, 물준유무를 확인할 수 있다`() { // given - val plantInformation = PlantInformation( - _species = "덕구리난", - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _familyName = "백합과", - smell = "거의 없음", - poison = "없음", - manageLevel = "초보자", - growSpeed = "느림", - _requireTemp = "21~25℃", - _minimumTemp = "13℃ 이상", - requireHumidity = "40% 미만", - postingPlace = "거실 창측 (실내깊이 150~300cm),발코니 내측 (실내깊이 50~150cm),발코니 창측 (실내깊이 0~50cm)", - specialManageInfo = "적절한 환기가 필요함, 여름동안 햇볕이 잘드는 위치에 배치하는 것이 좋음.", - _waterCycleSpring = 4, - _waterCycleSummer = 3, - _waterCycleAutumn = 4, - _waterCycleWinter = 4, - ) + val plantInformation = generatePlantInformation() val savedPlantInformation = plantInformationRepository.save(plantInformation) val today = LocalDate.now() - val companionPlant = CompanionPlant( - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _shortDescription = "덕구리난은 덕구리난과!", - _nickname = "shine", - birthDate = LocalDate.of(2024, 1, 1), - nextWaterDate = today, - lastWaterDate = LocalDate.of(2024, 1, 23), - waterCycle = 3, - plantInformationId = savedPlantInformation.getId, - memberId = 1L, - ) + val companionPlant = generateCompanionPlant(memberId = 1L, plantInformationId = savedPlantInformation.getId) companionPlant.saveRecord("test-record", "https://test.com", today) companionPlant.saveHistory(HistoryType.WATER_CHANGE, today) val savedPlant = companionPlantRepository.save(companionPlant) @@ -81,7 +42,7 @@ class PlantServiceTest( // when val result = plantService.lookupPlantRecordOfDate( - savedPlant.getId, today, "device-token" + savedPlant.getId, today, 테스터_디바이스_토큰 ) // then @@ -95,37 +56,10 @@ class PlantServiceTest( @Test fun `사용자는 식물의 데일리 기록을 조회했을때 물을 주지 않았던 경우 기록에 물주는 표시가 비어있다`() { // given - val plantInformation = PlantInformation( - _species = "덕구리난", - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _familyName = "백합과", - smell = "거의 없음", - poison = "없음", - manageLevel = "초보자", - growSpeed = "느림", - _requireTemp = "21~25℃", - _minimumTemp = "13℃ 이상", - requireHumidity = "40% 미만", - postingPlace = "거실 창측 (실내깊이 150~300cm),발코니 내측 (실내깊이 50~150cm),발코니 창측 (실내깊이 0~50cm)", - specialManageInfo = "적절한 환기가 필요함, 여름동안 햇볕이 잘드는 위치에 배치하는 것이 좋음.", - _waterCycleSpring = 4, - _waterCycleSummer = 3, - _waterCycleAutumn = 4, - _waterCycleWinter = 4, - ) + val plantInformation = generatePlantInformation() val savedPlantInformation = plantInformationRepository.save(plantInformation) - val companionPlant = CompanionPlant( - _imageUrl = "https://nongsaro.go.kr/cms_contents/301/13336_MF_ATTACH_05.jpg", - _shortDescription = "덕구리난은 덕구리난과!", - _nickname = "shine", - birthDate = LocalDate.of(2024, 1, 1), - nextWaterDate = LocalDate.of(2024, 1, 25), - lastWaterDate = LocalDate.of(2024, 1, 23), - waterCycle = 3, - plantInformationId = savedPlantInformation.getId, - memberId = 1L, - ) + val companionPlant = generateCompanionPlant(memberId = 1L, plantInformationId = savedPlantInformation.getId) val today = LocalDate.now() companionPlant.saveRecord("test-record", "https://test.com", today) companionPlant.saveHistory(HistoryType.POT_CHANGE, today) @@ -136,7 +70,7 @@ class PlantServiceTest( // when val result = plantService.lookupPlantRecordOfDate( - savedPlant.getId, today, "device-token" + savedPlant.getId, today, 테스터_디바이스_토큰 ) // then diff --git a/src/test/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationTest.kt b/src/test/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationTest.kt index d064ca2..ca4653e 100644 --- a/src/test/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationTest.kt +++ b/src/test/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationTest.kt @@ -1,5 +1,6 @@ package gdsc.plantory.plantInformation.domain +import gdsc.plantory.fixture.PlantInformationFixture.generatePlantInformation import org.assertj.core.api.Assertions.assertThatCode import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test @@ -28,14 +29,7 @@ class PlantInformationTest { @CsvSource(value = ["'',Cactaceae; Juss.", "Cactaceae,''", "'',''"]) fun `Species가 공백이라면 예외를 반환`(species: String, familyName: String) { assertThrows { - PlantInformation( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - species, familyName, - "15 ~ 20", "5", - 5, 5, 4, 3, - "earthy", "caution", "slow", "40%", - "veranda", - ) + generatePlantInformation(species = species, familyName = familyName) } } @@ -43,14 +37,7 @@ class PlantInformationTest { @CsvSource(value = ["'',5", "15 ~ 20,''", "'',''"]) fun `Temperature가 공백이라면 예외를 반환`(requireTemp: String, minimumTemp: String) { assertThrows { - PlantInformation( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "Cactaceae", "Cactaceae; Juss.", - requireTemp, minimumTemp, - 5, 5, 4, 3, - "earthy", "caution", "slow", "40%", - "veranda", - ) + generatePlantInformation(requireTemp = requireTemp, minimumTemp = minimumTemp) } } @@ -60,13 +47,11 @@ class PlantInformationTest { waterCycleSpring: Int, waterCycleSummer: Int, waterCycleAutumn: Int, waterCycleWinter: Int ) { assertThrows { - PlantInformation( - "https://nongsaro.go.kr/cms_contents/301/14687_MF_ATTACH_01.jpg", - "Cactaceae", "Cactaceae; Juss.", - "15 ~ 20", "5", - waterCycleSpring, waterCycleSummer, waterCycleAutumn, waterCycleWinter, - "earthy", "caution", "slow", "40%", - "veranda", + generatePlantInformation( + waterCycleSpring = waterCycleSpring, + waterCycleSummer = waterCycleSummer, + waterCycleAutumn = waterCycleAutumn, + waterCycleWinter = waterCycleWinter ) } } diff --git a/src/test/kotlin/gdsc/plantory/util/DatabaseLoader.kt b/src/test/kotlin/gdsc/plantory/util/DatabaseLoader.kt index 4b1e9b3..415e19f 100644 --- a/src/test/kotlin/gdsc/plantory/util/DatabaseLoader.kt +++ b/src/test/kotlin/gdsc/plantory/util/DatabaseLoader.kt @@ -1,8 +1,9 @@ package gdsc.plantory.util -import gdsc.plantory.fixture.CompanionPlantFixture -import gdsc.plantory.fixture.MemberFixture -import gdsc.plantory.fixture.PlantInformationFixture +import gdsc.plantory.fixture.CompanionPlantFixture.generateCompanionPlant +import gdsc.plantory.fixture.MemberFixture.generateMember +import gdsc.plantory.fixture.PlantInformationFixture.generatePlantInformation +import gdsc.plantory.fixture.테스터_디바이스_토큰 import gdsc.plantory.member.domain.MemberRepository import gdsc.plantory.plant.domain.CompanionPlantRepository import gdsc.plantory.plant.domain.HistoryType @@ -25,18 +26,26 @@ class DatabaseLoader( fun loadData() { log.info("[call DataLoader]") - val testMember = MemberFixture.generateTestMember(1L) - val testPlantInformation = PlantInformationFixture.generateTestPlantInformation(1L) - val testCompanionPlantWillHaveHistories = CompanionPlantFixture.generateTestCompanionPlantWillHaveHistories(1L) - val testCompanionPlantHasNoHistories = CompanionPlantFixture.generateTestCompanionPlantHasNoHistories(2L) - - testCompanionPlantWillHaveHistories.saveRecord("test-record", "https://test.com") - testCompanionPlantWillHaveHistories.saveHistory(HistoryType.POT_CHANGE) - testCompanionPlantWillHaveHistories.saveHistory(HistoryType.WATER_CHANGE) - - memberRepository.save(testMember) - plantInformationRepository.save(testPlantInformation) - companionPlantRepository.saveAll(listOf(testCompanionPlantWillHaveHistories, testCompanionPlantHasNoHistories)) + val testMember = generateMember(deviceToken = 테스터_디바이스_토큰) + val savedTestMember = memberRepository.save(testMember) + + val testPlantInformation = generatePlantInformation() + val savedTestPlantInformation = plantInformationRepository.save(testPlantInformation) + + val testCompanionPlantHasHistories = generateCompanionPlant( + memberId = savedTestMember.getId, + plantInformationId = savedTestPlantInformation.getId, + ) + testCompanionPlantHasHistories.saveRecord("test-record", "https://test.com") + testCompanionPlantHasHistories.saveHistory(HistoryType.POT_CHANGE) + testCompanionPlantHasHistories.saveHistory(HistoryType.WATER_CHANGE) + val savedTestCompanionPlantHasHistories = companionPlantRepository.save(testCompanionPlantHasHistories) + + val testCompanionPlantHasNoHistories = generateCompanionPlant( + memberId = savedTestMember.getId, + plantInformationId = savedTestPlantInformation.getId, + ) + val savedTestCompanionPlantHasNoHistories = companionPlantRepository.save(testCompanionPlantHasNoHistories) log.info("[init complete DataLoader]") }