fix(gift): 카테고리 접수 코드 중복을 허용한다

This commit is contained in:
2026-10-08 21:00:01 +09:00
parent c899ed7e21
commit 31167cba1b
3 changed files with 14 additions and 6 deletions
@@ -126,3 +126,5 @@ CREATE TABLE gift_application_no_sequence (
UNIQUE KEY uk_gift_application_no_sequence_category_date (category_id, sequence_date), UNIQUE KEY uk_gift_application_no_sequence_category_date (category_id, sequence_date),
CONSTRAINT fk_gift_application_no_sequence_category FOREIGN KEY (category_id) REFERENCES gift_category (id) CONSTRAINT fk_gift_application_no_sequence_category FOREIGN KEY (category_id) REFERENCES gift_category (id)
) COMMENT='선물 신청번호 날짜별 채번'; ) COMMENT='선물 신청번호 날짜별 채번';
ALTER TABLE gift_category DROP INDEX uk_gift_category_receipt_code;
@@ -11,8 +11,7 @@ import javax.persistence.UniqueConstraint
name = "gift_category", name = "gift_category",
uniqueConstraints = [ uniqueConstraints = [
UniqueConstraint(name = "uk_gift_category_classification_number", columnNames = ["classification_number"]), UniqueConstraint(name = "uk_gift_category_classification_number", columnNames = ["classification_number"]),
UniqueConstraint(name = "uk_gift_category_code", columnNames = ["category_code"]), UniqueConstraint(name = "uk_gift_category_code", columnNames = ["category_code"])
UniqueConstraint(name = "uk_gift_category_receipt_code", columnNames = ["receipt_code"])
] ]
) )
class GiftCategory( class GiftCategory(
@@ -92,7 +92,7 @@ class GiftEntityMappingTest @Autowired constructor(
} }
@Test @Test
@DisplayName("신청번호와 카테고리 unique 값과 리뷰 선물 ID는 중복 저장할 수 없다") @DisplayName("신청번호와 카테고리 분류번호 및 코드와 리뷰 선물 ID는 중복 저장할 수 없다")
fun shouldRejectDuplicateUniqueValues() { fun shouldRejectDuplicateUniqueValues() {
val category = giftCategoryRepository.save(giftCategory("100", "DOLL", "A")) val category = giftCategoryRepository.save(giftCategory("100", "DOLL", "A"))
val gift = giftRepository.save(gift(category.id!!, "G20260929000001")) val gift = giftRepository.save(gift(category.id!!, "G20260929000001"))
@@ -108,14 +108,21 @@ class GiftEntityMappingTest @Autowired constructor(
assertThrows(DataIntegrityViolationException::class.java) { assertThrows(DataIntegrityViolationException::class.java) {
giftCategoryRepository.saveAndFlush(giftCategory("100", "TOY", "B")) giftCategoryRepository.saveAndFlush(giftCategory("100", "TOY", "B"))
} }
assertThrows(DataIntegrityViolationException::class.java) {
giftCategoryRepository.saveAndFlush(giftCategory("101", "TOY", "A"))
}
assertThrows(DataIntegrityViolationException::class.java) { assertThrows(DataIntegrityViolationException::class.java) {
giftReviewRepository.saveAndFlush(GiftReview(giftId = gift.id!!, senderMemberId = 1L, rating = 4)) giftReviewRepository.saveAndFlush(GiftReview(giftId = gift.id!!, senderMemberId = 1L, rating = 4))
} }
} }
@Test
@DisplayName("카테고리 접수 코드는 중복 저장할 수 있다")
fun shouldAllowDuplicateReceiptCode() {
val first = giftCategoryRepository.saveAndFlush(giftCategory("100", "DOLL", "A"))
val second = giftCategoryRepository.saveAndFlush(giftCategory("101", "TOY", "A"))
assertNotNull(first.id)
assertNotNull(second.id)
}
@Test @Test
@DisplayName("카테고리와 날짜별 신청번호 채번 sequence를 저장한다") @DisplayName("카테고리와 날짜별 신청번호 채번 sequence를 저장한다")
fun shouldSaveApplicationNoSequence() { fun shouldSaveApplicationNoSequence() {