Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
refactor: Test Fixture 활용, imports 순서 조정 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldentrash authored Jan 31, 2024
1 parent cecb28f commit ea98159
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 278 deletions.
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,7 +28,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() {
@Test
fun `반려식물 등록`() {
// given
val 반려_식물_정보 = generateCompanionPlantCreateRequest(테스트_식물정보_ID)
val 반려_식물_정보 = generateCompanionPlantCreateRequest(1L)

// when
val 식물_등록_요청_응답 = 반려_식물_등록_요청(반려_식물_정보, 테스터_디바이스_토큰)
Expand All @@ -43,7 +40,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() {
@Test
fun `반려식물 삭제`() {
// when
val 식물_삭제_요청_응답 = 반려_식물_삭제_요청(기록있는_테스트식물_ID, 테스터_디바이스_토큰)
val 식물_삭제_요청_응답 = 반려_식물_삭제_요청(1L, 테스터_디바이스_토큰)

// then
응답_확인(식물_삭제_요청_응답, HttpStatus.NO_CONTENT)
Expand All @@ -55,7 +52,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() {
val 물줌_기록 = PlantHistoryRequest("WATER_CHANGE")

// when
val 식물_히스토리_생성_응답 = 식물_히스토리_생성_요청(기록없는_테스트식물_ID, 물줌_기록, 테스터_디바이스_토큰)
val 식물_히스토리_생성_응답 = 식물_히스토리_생성_요청(2L, 물줌_기록, 테스터_디바이스_토큰)

// then
응답_확인(식물_히스토리_생성_응답, HttpStatus.OK)
Expand All @@ -76,7 +73,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() {
val 데일리_기록_정보 = PlantRecordCreateRequest("오늘도 즐거운 하루~!")

// when
val 데일리_기록_등록_요청_응답 = 데일리_기록_등록_요청(기록없는_테스트식물_ID, 데일리_기록_정보, 테스터_디바이스_토큰)
val 데일리_기록_등록_요청_응답 = 데일리_기록_등록_요청(2L, 데일리_기록_정보, 테스터_디바이스_토큰)

// then
응답_확인(데일리_기록_등록_요청_응답, HttpStatus.OK)
Expand All @@ -90,15 +87,11 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() {
@Test
fun `반려식물 데일리 기록 중복 등록`() {
// given
데일리_기록_등록_요청(
기록없는_테스트식물_ID, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰
)
데일리_기록_등록_요청(2L, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰)

// when
val 데일리_기록_등록_요청_응답 =
데일리_기록_등록_요청(
기록없는_테스트식물_ID, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰
)
데일리_기록_등록_요청(2L, PlantRecordCreateRequest("오늘도 즐거운 하루~!"), 테스터_디바이스_토큰)

// then
응답_확인(데일리_기록_등록_요청_응답, HttpStatus.CONFLICT)
Expand All @@ -107,7 +100,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() {
@Test
fun `반려식물 데일리 기록 조회`() {
// when
val 데일리_기록_조회_요청_응답 = 데일리_기록_조회_요청(기록있는_테스트식물_ID, LocalDate.now(), 테스터_디바이스_토큰)
val 데일리_기록_조회_요청_응답 = 데일리_기록_조회_요청(1L, LocalDate.now(), 테스터_디바이스_토큰)

// then
데일리_기록_조회_응답_확인(데일리_기록_조회_요청_응답)
Expand All @@ -116,7 +109,7 @@ class CompanionPlantAcceptanceTest : AcceptanceTest() {
@Test
fun `반려식물 히스토리 조회`() {
// when
val 히스토리_조회_요청_응답 = 히스토리_조회_요청(기록있는_테스트식물_ID, YearMonth.parse("2024-01"), 테스터_디바이스_토큰)
val 히스토리_조회_요청_응답 = 히스토리_조회_요청(1L, YearMonth.parse("2024-01"), 테스터_디바이스_토큰)

// then
히스토리_조회_응답_확인(히스토리_조회_요청_응답)
Expand Down
71 changes: 20 additions & 51 deletions src/test/kotlin/gdsc/plantory/fixture/CompanionPlantFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}

Expand Down
15 changes: 3 additions & 12 deletions src/test/kotlin/gdsc/plantory/fixture/MemberFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
58 changes: 34 additions & 24 deletions src/test/kotlin/gdsc/plantory/fixture/PlantInformationFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
)
}
Loading

0 comments on commit ea98159

Please sign in to comment.