Test #464

Merged
klaus merged 8 commits from test into main 2026-11-01 06:23:24 +00:00
3 changed files with 44 additions and 21 deletions
Showing only changes of commit fe59d5c1f7 - Show all commits
@@ -33,6 +33,7 @@ import org.hamcrest.Matchers.nullValue
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource
import org.junit.jupiter.params.provider.ValueSource
import org.mockito.Mockito
import org.springframework.beans.factory.annotation.Autowired
@@ -222,12 +223,13 @@ class GiftControllerTest @Autowired constructor(
.andExpect(jsonPath("$.data.statusTimeline[1].occurredAt").value("2026-09-30T12:00:00Z"))
}
@Test
@ParameterizedTest
@EnumSource(value = GiftStatus::class, names = ["DELIVERED", "UNDELIVERABLE"])
@DisplayName("배송 개인정보가 지워져도 보낸 선물과 받은 선물의 상세 응답 계약을 유지한다")
fun shouldReturnCompatibleErasedGiftDetailsForSenderAndRecipient() {
fun shouldReturnCompatibleErasedGiftDetailsForSenderAndRecipient(giftStatus: GiftStatus) {
val sender = memberRepository.save(Member(password = "password", nickname = "erased-fan"))
val recipient = memberRepository.save(Member(password = "password", nickname = "erased-creator"))
val gift = saveGift("G-CONTROLLER-ERASED", sender.id!!, recipient.id!!, GiftStatus.DELIVERED)
val gift = saveGift("ERASE-$giftStatus", sender.id!!, recipient.id!!, giftStatus)
val delivery = GiftDelivery(
giftId = gift.id!!,
senderName = null,
@@ -236,7 +238,9 @@ class GiftControllerTest @Autowired constructor(
senderAddress = null,
trackingDeadlineAt = LocalDateTime.of(2026, 10, 2, 12, 0),
recipientAddressDeadlineAt = LocalDateTime.of(2026, 10, 7, 12, 0),
deliveredAt = LocalDateTime.of(2026, 10, 3, 12, 0)
deliveredAt = LocalDateTime.of(2026, 10, 3, 12, 0).takeIf { giftStatus == GiftStatus.DELIVERED },
undeliverableAt = LocalDateTime.of(2026, 10, 3, 12, 0).takeIf { giftStatus == GiftStatus.UNDELIVERABLE },
undeliverableReason = "검수 실패".takeIf { giftStatus == GiftStatus.UNDELIVERABLE }
)
giftDeliveryRepository.saveAndFlush(delivery)
@@ -244,7 +248,7 @@ class GiftControllerTest @Autowired constructor(
.andExpect(status().isOk)
.andExpect(jsonPath("$.success").value(true))
.andExpect(jsonPath("$.data.direction").value("SENT"))
.andExpect(jsonPath("$.data.status").value("DELIVERED"))
.andExpect(jsonPath("$.data.status").value(giftStatus.name))
.andExpect(jsonPath("$.data.senderInfo").isMap)
.andExpect(jsonPath("$.data.senderInfo.name").value(""))
.andExpect(jsonPath("$.data.senderInfo.phoneNumber").value(""))
@@ -255,7 +259,15 @@ class GiftControllerTest @Autowired constructor(
.andExpect(jsonPath("$.data.trackingRequired").value(false))
.andExpect(jsonPath("$.data.recipientAddressRequired").value(false))
.andExpect(jsonPath("$.data.mailbox").value(nullValue()))
.andExpect(jsonPath("$.data.statusTimeline[4].occurredAt").value("2026-10-03T12:00:00Z"))
.andExpect(
jsonPath("$.data.statusTimeline[4].occurredAt")
.value("2026-10-03T12:00:00Z".takeIf { giftStatus == GiftStatus.DELIVERED })
)
.andExpect(
jsonPath("$.data.delivery.undeliverableAt")
.value("2026-10-03T12:00:00Z".takeIf { giftStatus == GiftStatus.UNDELIVERABLE })
)
.andExpect(jsonPath("$.data.delivery.undeliverableReason").value(delivery.undeliverableReason))
mockMvc.perform(get("/api/v2/gifts/{applicationNo}", gift.applicationNo).with(user(MemberAdapter(recipient))))
.andExpect(status().isOk)
@@ -18,6 +18,7 @@ import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource
import org.junit.jupiter.params.provider.NullAndEmptySource
import org.junit.jupiter.params.provider.ValueSource
import org.springframework.beans.factory.annotation.Autowired
@@ -130,12 +131,13 @@ class GiftAdminQueryServiceTest @Autowired constructor(
assertEquals(listOf("COMPLETE_INSPECTION", "MARK_UNDELIVERABLE"), result.availableActions)
}
@Test
@ParameterizedTest
@EnumSource(value = GiftStatus::class, names = ["DELIVERED", "UNDELIVERABLE"])
@DisplayName("개인정보가 지워진 관리자 선물 응답은 닉네임과 종료 상태 액션을 유지한다")
fun shouldMapErasedDeliveryStringsWithoutChangingActions() {
fun shouldMapErasedDeliveryStringsWithoutChangingActions(status: GiftStatus) {
val sender = saveMember("fan-alpha")
val recipient = saveMember("creator-alpha")
val gift = saveGift("A-ERASED-DETAIL", sender, recipient, saveCategory(), GiftStatus.DELIVERED)
val gift = saveGift("A-ERASED-DETAIL", sender, recipient, saveCategory(), status)
requireNotNull(deliveryRepository.findByGiftId(gift.id!!)).apply {
senderName = null
senderPhoneNumber = null
@@ -147,16 +149,17 @@ class GiftAdminQueryServiceTest @Autowired constructor(
entityManager.clear()
val detail = service().getGiftDetail(gift.applicationNo)
val item = service().getGifts(GiftStatus.DELIVERED, null, null, 0, 20).items.single()
val item = service().getGifts(status, null, null, 0, 20).items.single()
assertEquals(AdminGiftMemberInfoResult("fan-alpha", "", "", ""), detail.senderInfo)
assertEquals(AdminGiftMemberInfoResult("creator-alpha", "", "", ""), detail.recipientInfo)
assertNull(detail.inboundDeliveryInfo.courierCompanyName)
assertNull(detail.inboundDeliveryInfo.trackingNumber)
assertEquals(GiftStatus.DELIVERED, detail.status)
assertEquals(status, detail.status)
assertEquals(emptyList<String>(), detail.availableActions)
assertEquals("fan-alpha", item.senderNickname)
assertEquals("creator-alpha", item.recipientNickname)
assertEquals(status, item.status)
assertNull(item.courierCompanyName)
assertNull(item.trackingNumber)
assertEquals(emptyList<String>(), item.availableActions)
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource
import org.junit.jupiter.params.provider.NullAndEmptySource
import org.junit.jupiter.params.provider.ValueSource
import org.springframework.beans.factory.annotation.Autowired
@@ -318,14 +319,15 @@ class GiftQueryServiceTest @Autowired constructor(
assertNull(result.statusTimeline[1].occurredAt)
}
@Test
@ParameterizedTest
@EnumSource(value = GiftStatus::class, names = ["DELIVERED", "UNDELIVERABLE"])
@DisplayName("개인정보가 지워진 보낸 선물은 발신자 객체와 빈 문자열을 유지한다")
fun shouldMapErasedSentSenderDetailsToEmptyStrings() {
fun shouldMapErasedSentSenderDetailsToEmptyStrings(status: GiftStatus) {
val sender = saveMember("fan")
val recipient = saveMember("creator", "profile/creator.png")
val gift = saveGift("G-ERASED-SENT", sender.id!!, recipient.id!!, GiftStatus.DELIVERED)
val gift = saveGift("G-ERASED-SENT", sender.id!!, recipient.id!!, status)
saveDelivery(gift).apply {
applyStatusTimes(GiftStatus.DELIVERED)
applyStatusTimes(status)
recipientAddressDeadlineAt = NOW.plusDays(7)
senderName = null
senderPhoneNumber = null
@@ -340,7 +342,7 @@ class GiftQueryServiceTest @Autowired constructor(
val item = queryService().getGifts(sender.id!!, GiftListType.SENT, 0, 20, Lang.KO).items.single()
assertEquals(GiftDirection.SENT, result.direction)
assertEquals(GiftStatus.DELIVERED, result.status)
assertEquals(status, result.status)
assertEquals(GiftAddressResult("", "", ""), result.senderInfo)
assertNull(result.recipientAddress)
assertNull(result.giftInfo.tracking)
@@ -348,21 +350,24 @@ class GiftQueryServiceTest @Autowired constructor(
assertEquals("creator", result.giftInfo.recipientCreatorNickname)
assertEquals(false, result.trackingRequired)
assertEquals(false, result.recipientAddressRequired)
assertEquals(NOW.plusHours(4), result.statusTimeline.last().occurredAt)
assertEquals(NOW.plusHours(4).takeIf { status == GiftStatus.DELIVERED }, result.statusTimeline.last().occurredAt)
assertEquals(NOW.plusHours(4).takeIf { status == GiftStatus.UNDELIVERABLE }, result.delivery.undeliverableAt)
assertEquals("검수 실패".takeIf { status == GiftStatus.UNDELIVERABLE }, result.delivery.undeliverableReason)
assertEquals("creator", item.counterpartNickname)
assertEquals("https://cdn.test/profile/creator.png", item.counterpartProfileImageUrl)
assertEquals(false, item.recipientAddressRegistered)
assertEquals(NOW.plusDays(7), item.recipientAddressDeadlineAt)
}
@Test
@ParameterizedTest
@EnumSource(value = GiftStatus::class, names = ["DELIVERED", "UNDELIVERABLE"])
@DisplayName("개인정보가 지워진 받은 선물은 발신자 정보와 수신자 배송지를 null로 유지한다")
fun shouldKeepReceivedSenderInfoNullAndRecipientAddressNullWhenErased() {
fun shouldKeepReceivedSenderInfoNullAndRecipientAddressNullWhenErased(status: GiftStatus) {
val sender = saveMember("fan", "profile/fan.png")
val recipient = saveMember("creator")
val gift = saveGift("G-ERASED-RECEIVED", sender.id!!, recipient.id!!, GiftStatus.DELIVERED)
val gift = saveGift("G-ERASED-RECEIVED", sender.id!!, recipient.id!!, status)
saveDelivery(gift).apply {
applyStatusTimes(GiftStatus.DELIVERED)
applyStatusTimes(status)
recipientAddressDeadlineAt = NOW.plusDays(7)
senderName = null
senderPhoneNumber = null
@@ -377,12 +382,15 @@ class GiftQueryServiceTest @Autowired constructor(
val item = queryService().getGifts(recipient.id!!, GiftListType.RECEIVED, 0, 20, Lang.KO).items.single()
assertEquals(GiftDirection.RECEIVED, result.direction)
assertEquals(status, result.status)
assertNull(result.senderInfo)
assertNull(result.recipientAddress)
assertNull(result.giftInfo.tracking)
assertEquals("fan", result.giftInfo.senderNickname)
assertEquals(false, result.trackingRequired)
assertEquals(false, result.recipientAddressRequired)
assertEquals(NOW.plusHours(4).takeIf { status == GiftStatus.UNDELIVERABLE }, result.delivery.undeliverableAt)
assertEquals("검수 실패".takeIf { status == GiftStatus.UNDELIVERABLE }, result.delivery.undeliverableReason)
assertEquals(NOW.plusDays(7), result.recipientAddressDeadlineAt)
assertEquals("fan", item.counterpartNickname)
assertEquals("https://cdn.test/profile/fan.png", item.counterpartProfileImageUrl)