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

feat: 경험 날짜 입력 예외 처리(#159) #160

Merged
merged 6 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ data class Experience(

init {
require(title.length < 50) { "제목의 글자 수는 50자 제한입니다." }
require(startedAt.isBefore(endedAt)) { "활동 시작일은 종료일보다 빨라야 합니다."}
}

companion object {
fun create(
title: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ data class ExperienceContent(
val answer: String,
) : DomainEntity {


companion object {
fun create(question: String, answer: String): ExperienceContent {
return ExperienceContent(question = question, answer = answer)
}

fun toDomain(id: UUID, question: String, answer: String): ExperienceContent {
return ExperienceContent(id, question, answer)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface ExperienceRepository {
fun findByIds(experienceIds: List<UUID>): List<Experience>
fun findByUserIdAndTitleContains(userId: UUID, search: String): List<Experience>
fun findByUserIdAndParentTagId(userId: UUID, parentTagId: UUID): List<Experience>
fun findByUserIdAndParentTagIdAndYearDesc(year: Int, parentTagId: UUID, userId: UUID): List<Experience>
fun findByYear(year: Int): List<Experience>
fun findByChildTagId(childTag: UUID) : List<Experience>
fun findByTagIds(tagIds: List<UUID>) : List<Experience>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ class ExperienceReader(
return experienceRepository.findByUserIdAndParentTagId(userId, parentTagId)
}

fun readByUserIdAndParentTagIdAndYearDesc(year: Int, parentTagId: UUID, userId: UUID): List<Experience> {
return experienceRepository.findByUserIdAndParentTagIdAndYearDesc(year, parentTagId, userId)
}

fun readByChildTagIdAndYear(year: Int, childTagId: UUID): List<Experience> {
return experienceRepository.findByYearAndChildTagId(year, childTagId)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bamyanggang.domainmodule.domain.tag.aggregate

import com.bamyanggang.domainmodule.common.entity.DomainEntity
import com.bamyanggang.domainmodule.domain.tag.exception.TagException
import com.example.uuid.UuidCreator
import java.util.*

Expand All @@ -11,6 +12,10 @@ data class Tag(
val userId: UUID
) : DomainEntity{

init {
require(name.isNotEmpty()) { TagException.EmptyName().message }
}

fun isDuplicatedName(name: String): Boolean = this.name == name

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ sealed class TagException(
class NotFoundTag(message: String = "존재하지 않는 태그 입니다.") :
TagException(errorCode = 3, message = message)

class EmptyName(message: String = "태그 이름은 공백일 수 없습니다.") :
TagException(errorCode = 4, message = message)

companion object {
const val CODE_PREFIX = "TAG"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bamyanggang.domainmodule.domain.experience.aggregate

import com.bamyanggang.commonmodule.fixture.generateBasicTypeFixture
import com.bamyanggang.commonmodule.fixture.generateFixture
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
Expand All @@ -9,15 +8,33 @@ import java.time.LocalDateTime
import java.util.*

class ExperienceTest : FunSpec({

test("Experience 정상 생성 테스트"){
val title: String = generateBasicTypeFixture(15)
val parentTagId: UUID = generateFixture()
val childTagId: UUID = generateFixture()
val contents: List<ExperienceContent> = generateFixture()
val experienceStrongPoints: List<ExperienceStrongPoint> = generateFixture()
val startedAt: LocalDateTime = generateFixture()
val endedAt: LocalDateTime = generateFixture()
val userId : UUID = generateFixture()
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()

val newExperience = Experience.create(
title = title,
Expand Down Expand Up @@ -56,4 +73,29 @@ class ExperienceTest : FunSpec({
)
}
}

test("날짜 입력 예외 처리 테스트") {
val title = "경험 제목"
val parentTagId: UUID = UUID.randomUUID()
val childTagId: UUID = UUID.randomUUID()
val contents: List<ExperienceContent> = generateFixture()
val experienceStrongPoints: List<ExperienceStrongPoint> = generateFixture()
val userId : UUID = generateFixture()

val startedAt = LocalDateTime.now()
val endedAt = startedAt.minusDays(1)

shouldThrow<IllegalArgumentException> {
Experience.create(
title = title,
userId = userId,
parentTagId = parentTagId,
childTagId = childTagId,
contents = contents,
experienceStrongPoints = experienceStrongPoints,
startedAt = startedAt,
endedAt = endedAt,
)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class JobDescriptionTest : FunSpec({

test("JobDescription 생성") {
// arrange
val enterpriseName: String = "기업 명"
val title: String = "제목"
val content: String = "내용"
val link: String = "링크"
val enterpriseName = "기업 명"
val title = "제목"
val content = "내용"
val link = "링크"
val startedAt: LocalDateTime = LocalDateTime.now()
val endedAt: LocalDateTime = startedAt.plusDays(1)
val userId : UUID = UUID.randomUUID()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bamyanggang.domainmodule.domain.strongpoint.service

import com.bamyanggang.commonmodule.fixture.generateFixture
import com.bamyanggang.domainmodule.domain.strongpoint.repository.StrongPointRepository
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
Expand All @@ -12,8 +11,8 @@ class StrongPointAppenderTest : BehaviorSpec({
val strongPointAppender = StrongPointAppender(strongPointRepository)

Given("역량 키워드 입력 값이 주어졌을 때") {
val name: String = generateFixture()
val userId: UUID = generateFixture()
val name: String = "역량 키워드 이름"
val userId: UUID = UUID.randomUUID()

When("StrongPointAppender.appendStrongPoint 함수가 호출되면") {
strongPointAppender.appendStrongPoint(name, userId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bamyanggang.domainmodule.domain.tag

import com.bamyanggang.domainmodule.domain.tag.aggregate.Tag
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -28,5 +29,15 @@ class TagTest: DescribeSpec({
originTag.isDuplicatedName(newTag.name) shouldBe false
}
}

context("태그 이름으로 공백이 넘어오면") {
it("IllegalmentArgumentException을 발생시킨다.") {
val emptyTitle = ""
shouldThrow<IllegalArgumentException> {
Tag.create(emptyTitle, null, UUID.randomUUID())
Tag.create(emptyTitle, UUID.randomUUID(), UUID.randomUUID())
}
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ public List<Experience> findByUserIdAndParentTagId(UUID userId, UUID parentTagId
return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList();
}

@Override
public List<Experience> findByUserIdAndParentTagIdAndYearDesc(int year, UUID parentTagId, UUID userId) {
LocalDateTime startYear = LocalDateTime.of(year, 1, 1, 0, 0);
LocalDateTime endYear = LocalDateTime.of(year, 12, 31, 23, 59);

List<ExperienceJpaEntity> experienceJpaEntities = experienceJpaRepository
.findByUserIdAndParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(
userId, parentTagId, startYear, endYear);
return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList();
}

@Override
public List<Experience> findByYear(int year) {
LocalDateTime startYear = LocalDateTime.of(year, 1, 1, 0, 0);
Expand Down
Loading