Skip to content

Commit

Permalink
fix : tag 수정시 에러 메시지 개선 (#170)
Browse files Browse the repository at this point in the history
* fix : tag 수정시 에러 메시지 개선

* fix test

* fix lint

* add test
  • Loading branch information
kshired authored Jan 7, 2024
1 parent 6be6c36 commit cb85ac4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.csbroker.apiserver.service.problem.admin

import io.csbroker.apiserver.common.enums.ErrorCode
import io.csbroker.apiserver.common.exception.ConditionConflictException
import io.csbroker.apiserver.common.exception.EntityNotFoundException
import io.csbroker.apiserver.model.Problem
import io.csbroker.apiserver.model.ProblemTag
import io.csbroker.apiserver.model.Tag
Expand Down Expand Up @@ -59,14 +58,21 @@ class TagUpserter(
}

private fun checkEveryTagExist(
tags: List<Tag>,
existTags: List<Tag>,
tagNames: List<String>,
) {
if (tags.size != tagNames.size) {
if (existTags.size != tagNames.size) {
val notExistTags = tagNames.filter {
it !in tags.map { tag -> tag.name }
it !in existTags.map { tag -> tag.name }
}
throw EntityNotFoundException("$notExistTags 태그가 존재하지 않습니다.")
throw ConditionConflictException(
ErrorCode.CONDITION_NOT_FULFILLED,
if (notExistTags.isNotEmpty()) {
"$notExistTags 태그가 존재하지 않습니다."
} else {
"중복된 태그가 존재합니다."
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.csbroker.apiserver.service.problem.admin

import io.csbroker.apiserver.auth.ProviderType
import io.csbroker.apiserver.common.exception.ConditionConflictException
import io.csbroker.apiserver.common.exception.EntityNotFoundException
import io.csbroker.apiserver.model.LongProblem
import io.csbroker.apiserver.model.ProblemTag
import io.csbroker.apiserver.model.Tag
Expand Down Expand Up @@ -81,7 +80,7 @@ class TagUpserterTest {
every { tagRepository.findTagsByNameIn(tagNames) } returns tags

// when, then
assertThrows<EntityNotFoundException> { tagUpserter.setTags(problem, tagNames) }
assertThrows<ConditionConflictException> { tagUpserter.setTags(problem, tagNames) }
}

@Test
Expand All @@ -93,7 +92,19 @@ class TagUpserterTest {
every { tagRepository.findTagsByNameIn(tagNames) } returns tags

// when, then
assertThrows<EntityNotFoundException> { tagUpserter.updateTags(problem, tagNames.toMutableList()) }
assertThrows<ConditionConflictException> { tagUpserter.updateTags(problem, tagNames.toMutableList()) }
}

@Test
fun `중복된 태그를 포함하여 업데이트하려고 하면 예외가 발생한다`() {
// given
val problem = getLongProblem()
val tagNames = listOf("tag1", "tag1", "tag2")
val tags = listOf(Tag(name = "tag1"), Tag(name = "tag1"))
every { tagRepository.findTagsByNameIn(tagNames) } returns tags

// when, then
assertThrows<ConditionConflictException> { tagUpserter.updateTags(problem, tagNames.toMutableList()) }
}

private fun getLongProblem(): LongProblem = LongProblem(
Expand Down

0 comments on commit cb85ac4

Please sign in to comment.