feat(gift): 선물 배송과 리뷰 저장소를 추가한다
This commit is contained in:
+137
@@ -0,0 +1,137 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence
|
||||
|
||||
import kr.co.vividnext.sodalive.configs.QueryDslConfig
|
||||
import kr.co.vividnext.sodalive.v2.gift.domain.GiftSize
|
||||
import kr.co.vividnext.sodalive.v2.gift.domain.GiftStatus
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.dao.DataIntegrityViolationException
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@DataJpaTest(
|
||||
properties = [
|
||||
"spring.cache.type=none",
|
||||
"spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;NON_KEYWORDS=VALUE"
|
||||
]
|
||||
)
|
||||
@Import(QueryDslConfig::class)
|
||||
@DisplayName("선물 엔티티 매핑 테스트")
|
||||
class GiftEntityMappingTest @Autowired constructor(
|
||||
private val giftRepository: GiftRepository,
|
||||
private val giftDeliveryRepository: GiftDeliveryRepository,
|
||||
private val giftCategoryRepository: GiftCategoryRepository,
|
||||
private val giftSizePriceRepository: GiftSizePriceRepository,
|
||||
private val giftReviewRepository: GiftReviewRepository,
|
||||
private val giftApplicationNoSequenceRepository: GiftApplicationNoSequenceRepository
|
||||
) {
|
||||
@Test
|
||||
@DisplayName("선물 엔티티와 배송 정보를 저장하고 조회한다")
|
||||
fun shouldSaveAndFindGiftWithDelivery() {
|
||||
val category = giftCategoryRepository.save(
|
||||
GiftCategory(
|
||||
categoryCode = "DOLL",
|
||||
name = "인형",
|
||||
requiresDamageWaiver = true
|
||||
)
|
||||
)
|
||||
giftSizePriceRepository.save(
|
||||
GiftSizePrice(
|
||||
sizeCode = GiftSize.SMALL,
|
||||
basePriceCan = 100,
|
||||
salePriceCan = 80
|
||||
)
|
||||
)
|
||||
val gift = giftRepository.save(
|
||||
Gift(
|
||||
applicationNo = "G20260929000001",
|
||||
senderMemberId = 1L,
|
||||
recipientMemberId = 2L,
|
||||
status = GiftStatus.RECEIVED,
|
||||
sizeCode = GiftSize.SMALL,
|
||||
categoryId = category.id!!,
|
||||
categoryNameSnapshot = category.name,
|
||||
salePriceCan = 80,
|
||||
canUsageId = 10L,
|
||||
senderTermsAgreed = true,
|
||||
senderPrivacyAgreed = true,
|
||||
senderTermsAgreedAt = LocalDateTime.of(2026, 9, 29, 12, 0),
|
||||
senderPrivacyAgreedAt = LocalDateTime.of(2026, 9, 29, 12, 0),
|
||||
damageWaiverAgreed = true
|
||||
)
|
||||
)
|
||||
|
||||
giftDeliveryRepository.save(
|
||||
GiftDelivery(
|
||||
giftId = gift.id!!,
|
||||
senderName = "홍길동",
|
||||
senderPhoneNumber = "01012345678",
|
||||
senderZipCode = "06234",
|
||||
senderAddress = "서울시 강남구",
|
||||
senderAddressDetail = "101동 1001호",
|
||||
trackingDeadlineAt = LocalDateTime.of(2026, 10, 2, 12, 0)
|
||||
)
|
||||
)
|
||||
|
||||
val saved = giftRepository.findByApplicationNo("G20260929000001")
|
||||
val delivery = giftDeliveryRepository.findByGiftId(gift.id!!)
|
||||
|
||||
assertNotNull(saved)
|
||||
assertEquals(GiftStatus.RECEIVED, saved!!.status)
|
||||
assertEquals("홍길동", delivery!!.senderName)
|
||||
assertNotNull(saved.createdAt)
|
||||
assertNotNull(saved.updatedAt)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("신청번호와 카테고리 코드와 리뷰 선물 ID는 중복 저장할 수 없다")
|
||||
fun shouldRejectDuplicateUniqueValues() {
|
||||
val category = giftCategoryRepository.save(GiftCategory(categoryCode = "DOLL", name = "인형"))
|
||||
val gift = giftRepository.save(gift(category.id!!, "G20260929000001"))
|
||||
giftRepository.saveAndFlush(gift(category.id!!, "G20260929000002"))
|
||||
giftReviewRepository.saveAndFlush(GiftReview(giftId = gift.id!!, senderMemberId = 1L, rating = 5))
|
||||
|
||||
assertThrows(DataIntegrityViolationException::class.java) {
|
||||
giftRepository.saveAndFlush(gift(category.id!!, "G20260929000001"))
|
||||
}
|
||||
assertThrows(DataIntegrityViolationException::class.java) {
|
||||
giftCategoryRepository.saveAndFlush(GiftCategory(categoryCode = "DOLL", name = "중복"))
|
||||
}
|
||||
assertThrows(DataIntegrityViolationException::class.java) {
|
||||
giftReviewRepository.saveAndFlush(GiftReview(giftId = gift.id!!, senderMemberId = 1L, rating = 4))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("날짜별 신청번호 채번 sequence를 저장한다")
|
||||
fun shouldSaveApplicationNoSequence() {
|
||||
val sequence = giftApplicationNoSequenceRepository.save(
|
||||
GiftApplicationNoSequence(sequenceDate = "20260929", lastSequence = 1)
|
||||
)
|
||||
|
||||
assertEquals("20260929", sequence.sequenceDate)
|
||||
assertEquals(1, sequence.lastSequence)
|
||||
}
|
||||
|
||||
private fun gift(categoryId: Long, applicationNo: String) = Gift(
|
||||
applicationNo = applicationNo,
|
||||
senderMemberId = 1L,
|
||||
recipientMemberId = 2L,
|
||||
status = GiftStatus.RECEIVED,
|
||||
sizeCode = GiftSize.SMALL,
|
||||
categoryId = categoryId,
|
||||
categoryNameSnapshot = "인형",
|
||||
salePriceCan = 80,
|
||||
canUsageId = 10L,
|
||||
senderTermsAgreed = true,
|
||||
senderPrivacyAgreed = true,
|
||||
senderTermsAgreedAt = LocalDateTime.of(2026, 9, 29, 12, 0),
|
||||
senderPrivacyAgreedAt = LocalDateTime.of(2026, 9, 29, 12, 0),
|
||||
damageWaiverAgreed = true
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user