fix(gift): 전달 완료 전 사서함 주소를 노출한다

This commit is contained in:
2026-10-02 11:33:55 +09:00
parent 3fb822a096
commit 77a66ee02c
3 changed files with 131 additions and 55 deletions
@@ -251,7 +251,7 @@ class GiftQueryService(
}
private fun mailboxFor(direction: GiftDirection, status: GiftStatus): GiftMailboxResult? {
if (direction != GiftDirection.SENT || status != GiftStatus.RECEIVED) return null
if (direction != GiftDirection.SENT || status in TERMINAL_STATUSES) return null
return giftMailboxRepository.findByIdOrNull(GiftMailbox.SINGLETON_ID)?.let {
GiftMailboxResult(
name = it.name,
@@ -194,15 +194,32 @@ class GiftControllerTest @Autowired constructor(
}
@Test
@DisplayName("발신자는 운송장 등록 전 선물 상세에서 받을 주소를 조회한다")
fun shouldGetMailboxForSentReceivedGiftDetail() {
@DisplayName("발신자는 전달 완료 전 정상 진행 선물 상세에서 받을 주소를 조회한다")
fun shouldGetMailboxForSentNormalProgressGiftDetailBeforeDelivered() {
val sender = memberRepository.save(Member(password = "password", nickname = "fan"))
val recipient = memberRepository.save(Member(password = "password", nickname = "creator"))
giftMailboxRepository.save(
GiftMailbox(
name = "소다라이브 선물 담당자",
phoneNumber = "01012345678",
zipCode = "06234",
address = "서울시 강남구",
addressDetail = "3층 선물 접수처"
)
)
val statuses = listOf(
GiftStatus.RECEIVED,
GiftStatus.TRACKING_REGISTERED,
GiftStatus.ARRIVED_AT_MAILBOX,
GiftStatus.INSPECTION_COMPLETED
)
statuses.forEachIndexed { index, giftStatus ->
val gift = saveGift(
applicationNo = "G-CONTROLLER-MAILBOX",
applicationNo = "G-C-MBOX-$index",
senderMemberId = sender.id!!,
recipientMemberId = recipient.id!!,
status = GiftStatus.RECEIVED
status = giftStatus
)
giftDeliveryRepository.save(
GiftDelivery(
@@ -213,16 +230,7 @@ class GiftControllerTest @Autowired constructor(
senderAddress = "서울시 강남구",
trackingDeadlineAt = LocalDateTime.of(2026, 10, 2, 12, 0)
)
)
giftMailboxRepository.save(
GiftMailbox(
name = "소다라이브 선물 담당자",
phoneNumber = "01012345678",
zipCode = "06234",
address = "서울시 강남구",
addressDetail = "3층 선물 접수처"
)
)
).applyStatusTimes(giftStatus)
mockMvc.perform(
get("/api/v2/gifts/{applicationNo}", gift.applicationNo)
@@ -234,6 +242,7 @@ class GiftControllerTest @Autowired constructor(
.andExpect(jsonPath("$.data.mailbox.phoneNumber").value("01012345678"))
.andExpect(jsonPath("$.data.mailbox.address").value("(06234) 서울시 강남구, 3층 선물 접수처"))
}
}
@Test
@DisplayName("팬은 POST /api/v2/gifts로 선물을 신청하고 접수 결과를 받는다")
@@ -508,6 +517,18 @@ class GiftControllerTest @Autowired constructor(
isActive = isActive
)
private fun GiftDelivery.applyStatusTimes(status: GiftStatus) {
if (status.ordinal >= GiftStatus.TRACKING_REGISTERED.ordinal) {
trackingRegisteredAt = LocalDateTime.of(2026, 9, 30, 12, 0)
}
if (status.ordinal >= GiftStatus.ARRIVED_AT_MAILBOX.ordinal) {
arrivedAtMailboxAt = LocalDateTime.of(2026, 10, 1, 12, 0)
}
if (status.ordinal >= GiftStatus.INSPECTION_COMPLETED.ordinal) {
inspectionCompletedAt = LocalDateTime.of(2026, 10, 2, 12, 0)
}
}
private companion object {
const val SENDER_ID = 1L
const val RECIPIENT_ID = 2L
@@ -234,24 +234,10 @@ class GiftQueryServiceTest @Autowired constructor(
}
@Test
@DisplayName("보낸 선물의 운송장 등록 전 상세만 받을 주소를 반환한다")
fun shouldReturnMailboxOnlyForSentReceivedGiftDetail() {
@DisplayName("보낸 선물의 전달 완료 전 정상 진행 상세는 받을 주소를 반환한다")
fun shouldReturnMailboxForSentNormalProgressGiftDetailBeforeDelivered() {
val sender = saveMember("fan")
val recipient = saveMember("creator")
val receivedGift = saveGift(
applicationNo = "G-MAILBOX-RECEIVED",
senderMemberId = sender.id!!,
recipientMemberId = recipient.id!!,
status = GiftStatus.RECEIVED
)
saveDelivery(receivedGift)
val trackingGift = saveGift(
applicationNo = "G-MAILBOX-TRACKING",
senderMemberId = sender.id!!,
recipientMemberId = recipient.id!!,
status = GiftStatus.TRACKING_REGISTERED
)
saveDelivery(trackingGift).trackingRegisteredAt = NOW
giftMailboxRepository.save(
GiftMailbox(
name = "소다라이브 선물 담당자",
@@ -262,20 +248,77 @@ class GiftQueryServiceTest @Autowired constructor(
)
)
val service = queryService()
val allowedStatuses = listOf(
GiftStatus.RECEIVED,
GiftStatus.TRACKING_REGISTERED,
GiftStatus.ARRIVED_AT_MAILBOX,
GiftStatus.INSPECTION_COMPLETED
)
val receivedResult = service.getGiftDetail(sender.id!!, receivedGift.applicationNo)
val trackingSenderResult = service.getGiftDetail(sender.id!!, trackingGift.applicationNo)
val trackingRecipientResult = service.getGiftDetail(recipient.id!!, trackingGift.applicationNo)
allowedStatuses.forEachIndexed { index, status ->
val gift = saveGift(
applicationNo = "G-MAILBOX-ALLOWED-$index",
senderMemberId = sender.id!!,
recipientMemberId = recipient.id!!,
status = status
)
saveDelivery(gift).applyStatusTimes(status)
assertEquals("소다라이브 선물 담당자", receivedResult.mailbox?.name)
assertEquals("01012345678", receivedResult.mailbox?.phoneNumber)
assertEquals("(06234) 서울시 강남구, 3층 선물 접수처", receivedResult.mailbox?.address)
assertNull(trackingSenderResult.mailbox)
assertNull(trackingRecipientResult.mailbox)
val result = service.getGiftDetail(sender.id!!, gift.applicationNo)
assertEquals("소다라이브 선물 담당자", result.mailbox?.name)
assertEquals("01012345678", result.mailbox?.phoneNumber)
assertEquals("(06234) 서울시 강남구, 3층 선물 접수처", result.mailbox?.address)
assertEquals(status == GiftStatus.RECEIVED, result.trackingRequired)
}
}
@Test
@DisplayName("받을 주소가 없으면 운송장 등록 전 상세도 mailbox가 null이다")
@DisplayName("보낸 선물의 종료 상태와 받은 선물 상세는 받을 주소를 반환하지 않는다")
fun shouldReturnNullMailboxForTerminalOrReceivedGiftDetail() {
val sender = saveMember("fan")
val recipient = saveMember("creator")
giftMailboxRepository.save(
GiftMailbox(
name = "소다라이브 선물 담당자",
phoneNumber = "01012345678",
zipCode = "06234",
address = "서울시 강남구",
addressDetail = "3층 선물 접수처"
)
)
val service = queryService()
val terminalStatuses = listOf(GiftStatus.DELIVERED, GiftStatus.UNDELIVERABLE, GiftStatus.CANCELED)
terminalStatuses.forEachIndexed { index, status ->
val gift = saveGift(
applicationNo = "G-MAILBOX-TERMINAL-$index",
senderMemberId = sender.id!!,
recipientMemberId = recipient.id!!,
status = status
)
saveDelivery(gift).applyStatusTimes(status)
val result = service.getGiftDetail(sender.id!!, gift.applicationNo)
assertNull(result.mailbox)
}
val receivedGift = saveGift(
applicationNo = "G-MAILBOX-RECIPIENT",
senderMemberId = sender.id!!,
recipientMemberId = recipient.id!!,
status = GiftStatus.TRACKING_REGISTERED
)
saveDelivery(receivedGift).applyStatusTimes(GiftStatus.TRACKING_REGISTERED)
val recipientResult = service.getGiftDetail(recipient.id!!, receivedGift.applicationNo)
assertNull(recipientResult.mailbox)
}
@Test
@DisplayName("받을 주소가 없으면 전달 완료 전 정상 진행 상세도 mailbox가 null이다")
fun shouldReturnNullMailboxWhenMailboxNotConfigured() {
val sender = saveMember("fan")
val recipient = saveMember("creator")
@@ -283,9 +326,9 @@ class GiftQueryServiceTest @Autowired constructor(
applicationNo = "G-MAILBOX-EMPTY",
senderMemberId = sender.id!!,
recipientMemberId = recipient.id!!,
status = GiftStatus.RECEIVED
status = GiftStatus.INSPECTION_COMPLETED
)
saveDelivery(gift)
saveDelivery(gift).applyStatusTimes(GiftStatus.INSPECTION_COMPLETED)
val result = queryService().getGiftDetail(sender.id!!, gift.applicationNo)
@@ -506,6 +549,18 @@ class GiftQueryServiceTest @Autowired constructor(
)
)
private fun GiftDelivery.applyStatusTimes(status: GiftStatus) {
if (status.ordinal >= GiftStatus.TRACKING_REGISTERED.ordinal) trackingRegisteredAt = NOW.plusHours(1)
if (status.ordinal >= GiftStatus.ARRIVED_AT_MAILBOX.ordinal) arrivedAtMailboxAt = NOW.plusHours(2)
if (status.ordinal >= GiftStatus.INSPECTION_COMPLETED.ordinal) inspectionCompletedAt = NOW.plusHours(3)
if (status == GiftStatus.DELIVERED) deliveredAt = NOW.plusHours(4)
if (status == GiftStatus.UNDELIVERABLE) {
undeliverableAt = NOW.plusHours(4)
undeliverableReason = "검수 실패"
}
if (status == GiftStatus.CANCELED) canceledAt = NOW.plusHours(1)
}
private fun queryService() = GiftQueryService(
categoryRepository,
sizePriceRepository,