Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 경험 도메인 테스트 코드 작성(#169) #170

Merged
merged 7 commits into from
May 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TagDeleteService(
experienceReader.readByUserIdAndParentTagId(getAuthenticationPrincipal(), deleteTag.id)
.forEach { experienceRemover.remove(it.id) }
}else {
experienceReader.readByChildTag(tagId).forEach {
experienceReader.readByChildTagId(tagId).forEach {
experienceRemover.remove(it.id)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class Experience(
init {
require(title.length < 50) { "제목의 글자 수는 50자 제한입니다." }
require(startedAt <= endedAt) { "활동 시작일은 종료일보다 빨라야 합니다."}
require(strongPoints.isNotEmpty()) { "최소 1개 이상의 역량 키워드를 선택해야 합니다."}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ class ExperienceReader(
}.contains(true)
}.map { it.id }
}

fun readByYear(year: Int): List<Experience> {
return experienceRepository.findByYear(year)
}

fun readByChildTag(childTag: UUID): List<Experience> {
return experienceRepository.findByChildTagId(childTag)
fun readByChildTagId(childTagId: UUID): List<Experience> {
return experienceRepository.findByChildTagId(childTagId)
}

fun readIdsByTagIds(tagIds: List<UUID>) : List<UUID> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,40 @@ class ExperienceTest : FunSpec({
)
}
}

test("역량 키워드 최소 개수 제한 테스트") {
val title = "경험 제목"
val parentTagId: UUID = UUID.randomUUID()
val childTagId: UUID = UUID.randomUUID()
val contents = arrayListOf(
ExperienceContent(
question = "질문 1",
answer = "대답 1"
),
ExperienceContent(
question = "질문 2",
answer = "대답 2"
)
)
val userId : UUID = UUID.randomUUID()
val startedAt = LocalDateTime.now()
val endedAt = startedAt.plusDays(1)

val experienceStrongPoints = emptyList<ExperienceStrongPoint>()

val exception = shouldThrow<IllegalArgumentException> {
Experience.create(
title = title,
userId = userId,
parentTagId = parentTagId,
childTagId = childTagId,
contents = contents,
experienceStrongPoints = experienceStrongPoints,
startedAt = startedAt,
endedAt = endedAt,
)
}

assert(exception.message == "최소 1개 이상의 역량 키워드를 선택해야 합니다.")
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.bamyanggang.domainmodule.domain.experience.service

import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceContent
import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceStrongPoint
import com.bamyanggang.domainmodule.domain.experience.repository.ExperienceRepository
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
import io.mockk.verify
import java.time.LocalDateTime
import java.util.*

class ExperienceAppenderTest : BehaviorSpec({
val experienceRepository = mockk<ExperienceRepository>(relaxed = true)
val experienceAppender = ExperienceAppender(experienceRepository)

Given("경험 등록 데이터들이 주어졌을 때") {
val title = "경험 제목"
val parentTagId: UUID = UUID.randomUUID()
val childTagId: UUID = UUID.randomUUID()
val contents = arrayListOf(
ExperienceContent(
question = "질문 1",
answer = "대답 1"
),
ExperienceContent(
question = "질문 2",
answer = "대답 2"
)
)

val experienceStrongPoints: List<ExperienceStrongPoint> = arrayListOf(
ExperienceStrongPoint.create(
UUID.randomUUID()
),
ExperienceStrongPoint.create(
UUID.randomUUID()
)
)
val startedAt: LocalDateTime = LocalDateTime.now()
val endedAt: LocalDateTime = startedAt.plusDays(1)
val userId = UUID.randomUUID()

When("ExperienceAppender.appendExperience를 호출하면") {
val newExperience = experienceAppender.appendExperience(
title = title,
parentTagId = parentTagId,
childTagId = childTagId,
contents = contents,
experienceStrongPoints = experienceStrongPoints,
userId = userId,
startedAt = startedAt,
endedAt = endedAt
)

Then("experienceRepository.save가 호출된다.") {
verify { experienceRepository.save(newExperience) }
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.bamyanggang.domainmodule.domain.experience.service

import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceContent
import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceStrongPoint
import com.bamyanggang.domainmodule.domain.experience.repository.ExperienceRepository
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
import io.mockk.verify
import java.time.LocalDateTime
import java.util.*

class ExperienceModifierTest : BehaviorSpec({
val experienceRepository = mockk<ExperienceRepository>(relaxed = true)
val experienceModifier = ExperienceModifier(experienceRepository)

Given("수정할 경험 등록 데이터들이 주어졌을 때") {
val experienceId = UUID.randomUUID()
val title = "수정한 경험 제목"
val parentTagId: UUID = UUID.randomUUID()
val childTagId: UUID = UUID.randomUUID()
val contents = arrayListOf(
ExperienceContent(
question = "수정한 질문 1",
answer = "수정한 대답 1"
),
ExperienceContent(
question = "수정한 질문 2",
answer = "수정한 대답 2"
)
)

val experienceStrongPoints: List<ExperienceStrongPoint> = arrayListOf(
ExperienceStrongPoint.create(
UUID.randomUUID()
),
ExperienceStrongPoint.create(
UUID.randomUUID()
)
)
val startedAt: LocalDateTime = LocalDateTime.now()
val endedAt: LocalDateTime = startedAt.plusDays(1)
val userId = UUID.randomUUID()

When("ExperienceModifier.modifyExperience 호출하면") {
val editExperience = experienceModifier.modifyExperience(
experienceId = experienceId,
title = title,
parentTagId = parentTagId,
childTagId = childTagId,
contents = contents,
experienceStrongPoints = experienceStrongPoints,
userId = userId,
startedAt = startedAt,
endedAt = endedAt
)

Then("experienceRepository.save가 호출된다.") {
verify { experienceRepository.save(editExperience) }
}
}
}
})
Loading
Loading