Skip to content

Commit

Permalink
Merge pull request #170 from KUSITMS-29th-TEAM-B/test/flight-169
Browse files Browse the repository at this point in the history
test: 경험 도메인 테스트 코드 작성(#169)
  • Loading branch information
whereami2048 authored May 23, 2024
2 parents 7785e68 + 1e4350f commit f5b58e4
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 3 deletions.
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

0 comments on commit f5b58e4

Please sign in to comment.