feat(gift): 선물 상세 표시 모델을 추가한다
This commit is contained in:
@@ -0,0 +1,73 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
sealed interface GiftDetailText {
|
||||||
|
enum class Key : GiftDetailText {
|
||||||
|
RECEIVED_LABEL,
|
||||||
|
RECEIVED_TITLE,
|
||||||
|
RECEIVED_BODY,
|
||||||
|
TRACKING_REGISTERED_LABEL,
|
||||||
|
TRACKING_REGISTERED_TITLE,
|
||||||
|
ARRIVED_AT_MAILBOX_LABEL,
|
||||||
|
ARRIVED_AT_MAILBOX_TITLE,
|
||||||
|
INSPECTION_COMPLETED_LABEL,
|
||||||
|
INSPECTION_COMPLETED_TITLE,
|
||||||
|
DELIVERED_LABEL,
|
||||||
|
DELIVERED_TITLE,
|
||||||
|
UNDELIVERABLE_LABEL,
|
||||||
|
UNDELIVERABLE_TITLE,
|
||||||
|
UNDELIVERABLE_BODY,
|
||||||
|
CANCELED_LABEL,
|
||||||
|
CANCELED_TITLE,
|
||||||
|
CANCELED_BODY,
|
||||||
|
DISPOSAL_NON_RETURN_GUIDANCE
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Raw(val value: String) : GiftDetailText
|
||||||
|
data class CancellationBody(val creatorNickname: String?, val applicationNo: String) : GiftDetailText
|
||||||
|
data class CanAmount(val amount: Int) : GiftDetailText
|
||||||
|
}
|
||||||
|
|
||||||
|
data class GiftDetailUiModel(
|
||||||
|
val applicationNo: String,
|
||||||
|
val status: String,
|
||||||
|
val hero: GiftDetailHero,
|
||||||
|
val timeline: List<GiftDetailTimelineStep>,
|
||||||
|
val progressSegments: List<GiftDetailTimelineStep>,
|
||||||
|
val showProgress: Boolean,
|
||||||
|
val cancellationRows: List<GiftDetailInfoRow>,
|
||||||
|
val giftInfo: GiftDetailInfo,
|
||||||
|
val senderInfo: GiftDetailAddress?,
|
||||||
|
val mailbox: GiftDetailAddress?,
|
||||||
|
val recipientAddress: GiftDetailAddress?,
|
||||||
|
val undeliverable: GiftDetailUndeliverable?,
|
||||||
|
val cancellation: GiftDetailCancellation?,
|
||||||
|
val actions: Set<GiftDetailAction>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftDetailHero(val chip: GiftDetailText?, val title: GiftDetailText, val body: GiftDetailText?)
|
||||||
|
|
||||||
|
data class GiftDetailInfoRow(val label: Int, val value: GiftDetailText)
|
||||||
|
|
||||||
|
data class GiftDetailTimelineStep(val status: String, val title: GiftDetailText, val date: String?) {
|
||||||
|
val completed: Boolean get() = date != null
|
||||||
|
}
|
||||||
|
|
||||||
|
data class GiftDetailInfo(
|
||||||
|
val counterpartNickname: String?,
|
||||||
|
val sizeName: String,
|
||||||
|
val categoryName: String,
|
||||||
|
val paidCan: Int?,
|
||||||
|
val tracking: String?,
|
||||||
|
val shippingRequestedDate: String?,
|
||||||
|
val inspectionDate: String?,
|
||||||
|
val deliveredDate: String?,
|
||||||
|
val canceledDate: String?
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftDetailAddress(val name: String, val phoneNumber: String, val address: String)
|
||||||
|
|
||||||
|
data class GiftDetailUndeliverable(val title: GiftDetailText, val guidance: GiftDetailText)
|
||||||
|
|
||||||
|
data class GiftDetailCancellation(val date: String?, val refundCan: Int?)
|
||||||
|
|
||||||
|
enum class GiftDetailAction { TRACKING, CANCEL, INQUIRY }
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.R
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.GiftDetailText.Key
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.GiftDetailText.Raw
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftAddressResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftCancelResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftDetailResponse
|
||||||
|
import java.text.ParsePosition
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
object GiftDetailPresenter {
|
||||||
|
private val normalStates = linkedMapOf(
|
||||||
|
"RECEIVED" to Key.RECEIVED_LABEL,
|
||||||
|
"TRACKING_REGISTERED" to Key.TRACKING_REGISTERED_LABEL,
|
||||||
|
"ARRIVED_AT_MAILBOX" to Key.ARRIVED_AT_MAILBOX_LABEL,
|
||||||
|
"INSPECTION_COMPLETED" to Key.INSPECTION_COMPLETED_LABEL,
|
||||||
|
"DELIVERED" to Key.DELIVERED_LABEL
|
||||||
|
)
|
||||||
|
private val knownStates = normalStates.keys + setOf("UNDELIVERABLE", "CANCELED")
|
||||||
|
private val utcPattern = Regex("([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2})(?:\\.[0-9]{1,9})?(?:Z|\\+00:00)")
|
||||||
|
|
||||||
|
fun present(detail: GiftDetailResponse, cancel: GiftCancelResponse? = null): GiftDetailUiModel {
|
||||||
|
val status = if (cancel != null) "CANCELED" else detail.status
|
||||||
|
val info = detail.giftInfo
|
||||||
|
val history = detail.statusTimeline.associateBy { it.status }
|
||||||
|
val canceledDate = formatCardDate(if (cancel != null) cancel.canceledAt else detail.delivery.canceledAt)
|
||||||
|
val timeline = normalStates.map { (state, title) ->
|
||||||
|
val entry = history[state]
|
||||||
|
GiftDetailTimelineStep(state, entry?.statusName?.let(::Raw) ?: title, formatProgressDate(entry?.occurredAt))
|
||||||
|
}
|
||||||
|
val cancellation = if (status == "CANCELED") {
|
||||||
|
GiftDetailCancellation(canceledDate, cancel?.priceCan ?: info.paidCan)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
return GiftDetailUiModel(
|
||||||
|
applicationNo = detail.applicationNo,
|
||||||
|
status = status,
|
||||||
|
hero = hero(status, detail.statusName).let {
|
||||||
|
if (cancellation == null) {
|
||||||
|
it
|
||||||
|
} else {
|
||||||
|
it.copy(body = GiftDetailText.CancellationBody(info.recipientCreatorNickname, detail.applicationNo))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
timeline = timeline,
|
||||||
|
progressSegments = timeline.filter { it.status != "INSPECTION_COMPLETED" }.map { step ->
|
||||||
|
step.copy(
|
||||||
|
title = normalStates.getValue(step.status),
|
||||||
|
date = if (step.status == "ARRIVED_AT_MAILBOX") {
|
||||||
|
step.date ?: timeline.first { it.status == "INSPECTION_COMPLETED" }.date
|
||||||
|
} else {
|
||||||
|
step.date
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
showProgress = status in normalStates.keys - "RECEIVED",
|
||||||
|
cancellationRows = if (cancellation == null) {
|
||||||
|
emptyList()
|
||||||
|
} else {
|
||||||
|
listOfNotNull(
|
||||||
|
info.recipientCreatorNickname?.let { GiftDetailInfoRow(R.string.gift_detail_creator, Raw(it)) },
|
||||||
|
GiftDetailInfoRow(R.string.gift_send_size, Raw(info.sizeName)),
|
||||||
|
GiftDetailInfoRow(R.string.gift_send_category, Raw(info.categoryName)),
|
||||||
|
GiftDetailInfoRow(R.string.gift_detail_application_no, Raw(detail.applicationNo)),
|
||||||
|
formatCardDate(history["RECEIVED"]?.occurredAt)?.let {
|
||||||
|
GiftDetailInfoRow(R.string.gift_tracking_application_date, Raw(it))
|
||||||
|
},
|
||||||
|
canceledDate?.let { GiftDetailInfoRow(R.string.gift_detail_canceled_date, Raw(it)) },
|
||||||
|
cancellation.refundCan?.let {
|
||||||
|
GiftDetailInfoRow(R.string.gift_detail_refund, GiftDetailText.CanAmount(it))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
giftInfo = GiftDetailInfo(
|
||||||
|
counterpartNickname = if (detail.direction == "RECEIVED") info.senderNickname else info.recipientCreatorNickname,
|
||||||
|
sizeName = info.sizeName,
|
||||||
|
categoryName = info.categoryName,
|
||||||
|
paidCan = info.paidCan,
|
||||||
|
tracking = info.tracking,
|
||||||
|
shippingRequestedDate = formatCardDate(info.shippingRequestedAt),
|
||||||
|
inspectionDate = formatCardDate(history["INSPECTION_COMPLETED"]?.occurredAt),
|
||||||
|
deliveredDate = formatCardDate(history["DELIVERED"]?.occurredAt),
|
||||||
|
canceledDate = canceledDate
|
||||||
|
),
|
||||||
|
senderInfo = detail.senderInfo?.toUiModel(),
|
||||||
|
mailbox = detail.mailbox?.toUiModel(),
|
||||||
|
recipientAddress = if (detail.direction == "RECEIVED") detail.recipientAddress?.toUiModel() else null,
|
||||||
|
undeliverable = if (status == "UNDELIVERABLE") {
|
||||||
|
GiftDetailUndeliverable(
|
||||||
|
title = detail.delivery.undeliverableReason?.let(::Raw) ?: Key.UNDELIVERABLE_LABEL,
|
||||||
|
guidance = Key.DISPOSAL_NON_RETURN_GUIDANCE
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
|
cancellation = cancellation,
|
||||||
|
actions = buildSet {
|
||||||
|
if (status in knownStates && detail.trackingRequired) add(GiftDetailAction.TRACKING)
|
||||||
|
if (detail.direction == "SENT" && status == "RECEIVED") add(GiftDetailAction.CANCEL)
|
||||||
|
add(GiftDetailAction.INQUIRY)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun showsTrackingAction(state: GiftDetailUiState): Boolean {
|
||||||
|
val detail = (state as? GiftDetailUiState.Content)?.detail ?: return false
|
||||||
|
val model = present(detail)
|
||||||
|
return model.cancellation == null && GiftDetailAction.TRACKING in model.actions
|
||||||
|
}
|
||||||
|
|
||||||
|
fun formatProgressDate(occurredAt: String?): String? = formatDate(occurredAt, "MM.dd")
|
||||||
|
|
||||||
|
fun formatCardDate(occurredAt: String?): String? = formatDate(occurredAt, "yyyy.MM.dd")
|
||||||
|
|
||||||
|
private fun formatDate(occurredAt: String?, pattern: String): String? {
|
||||||
|
val seconds = occurredAt?.let { utcPattern.matchEntire(it)?.groupValues?.get(1) } ?: return null
|
||||||
|
val parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US).apply {
|
||||||
|
isLenient = false
|
||||||
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
|
}
|
||||||
|
val date = parser.parse(seconds, ParsePosition(0)) ?: return null
|
||||||
|
return SimpleDateFormat(pattern, Locale.US).format(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun GiftAddressResponse.toUiModel() = GiftDetailAddress(name, phoneNumber, address)
|
||||||
|
|
||||||
|
private fun hero(status: String, statusName: String): GiftDetailHero = when (status) {
|
||||||
|
"RECEIVED" -> GiftDetailHero(null, Key.RECEIVED_TITLE, Key.RECEIVED_BODY)
|
||||||
|
"TRACKING_REGISTERED" -> GiftDetailHero(Key.TRACKING_REGISTERED_LABEL, Key.TRACKING_REGISTERED_TITLE, null)
|
||||||
|
"ARRIVED_AT_MAILBOX" -> GiftDetailHero(Key.ARRIVED_AT_MAILBOX_LABEL, Key.ARRIVED_AT_MAILBOX_TITLE, null)
|
||||||
|
"INSPECTION_COMPLETED" -> GiftDetailHero(Key.INSPECTION_COMPLETED_LABEL, Key.INSPECTION_COMPLETED_TITLE, null)
|
||||||
|
"DELIVERED" -> GiftDetailHero(Key.DELIVERED_LABEL, Key.DELIVERED_TITLE, null)
|
||||||
|
"UNDELIVERABLE" -> GiftDetailHero(
|
||||||
|
Key.UNDELIVERABLE_LABEL,
|
||||||
|
Key.UNDELIVERABLE_TITLE,
|
||||||
|
Key.UNDELIVERABLE_BODY
|
||||||
|
)
|
||||||
|
"CANCELED" -> GiftDetailHero(Key.CANCELED_LABEL, Key.CANCELED_TITLE, Key.CANCELED_BODY)
|
||||||
|
else -> GiftDetailHero(null, Raw(statusName), null)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,344 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.GiftDetailText.Key
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.GiftDetailText.Raw
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftAddressResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftCancelResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftDeliveryResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftDetailInfoResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftDetailResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftStatusTimelineResponse
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
class GiftDetailPresenterTest {
|
||||||
|
private val originalTimeZone = TimeZone.getDefault()
|
||||||
|
private val date = "2026-10-01T18:30:00Z"
|
||||||
|
private val normalStates = listOf(
|
||||||
|
"RECEIVED",
|
||||||
|
"TRACKING_REGISTERED",
|
||||||
|
"ARRIVED_AT_MAILBOX",
|
||||||
|
"INSPECTION_COMPLETED",
|
||||||
|
"DELIVERED"
|
||||||
|
)
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() { TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")) }
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun tearDown() { TimeZone.setDefault(originalTimeZone) }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `일곱 상태의 칩 제목 본문을 지역화 키로 매핑한다`() {
|
||||||
|
val heroes = mapOf(
|
||||||
|
"RECEIVED" to GiftDetailHero(null, Key.RECEIVED_TITLE, Key.RECEIVED_BODY),
|
||||||
|
"TRACKING_REGISTERED" to GiftDetailHero(Key.TRACKING_REGISTERED_LABEL, Key.TRACKING_REGISTERED_TITLE, null),
|
||||||
|
"ARRIVED_AT_MAILBOX" to GiftDetailHero(Key.ARRIVED_AT_MAILBOX_LABEL, Key.ARRIVED_AT_MAILBOX_TITLE, null),
|
||||||
|
"INSPECTION_COMPLETED" to GiftDetailHero(Key.INSPECTION_COMPLETED_LABEL, Key.INSPECTION_COMPLETED_TITLE, null),
|
||||||
|
"DELIVERED" to GiftDetailHero(Key.DELIVERED_LABEL, Key.DELIVERED_TITLE, null),
|
||||||
|
"UNDELIVERABLE" to GiftDetailHero(
|
||||||
|
Key.UNDELIVERABLE_LABEL,
|
||||||
|
Key.UNDELIVERABLE_TITLE,
|
||||||
|
Key.UNDELIVERABLE_BODY
|
||||||
|
),
|
||||||
|
"CANCELED" to GiftDetailHero(
|
||||||
|
Key.CANCELED_LABEL,
|
||||||
|
Key.CANCELED_TITLE,
|
||||||
|
GiftDetailText.CancellationBody("크리에이터", "GIFT-1")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
heroes.forEach { (status, hero) -> assertEquals(hero, present(status).hero) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `순서가 뒤섞인 이력은 정상 다섯 단계로 정렬하고 유효 날짜만 완료 처리한다`() {
|
||||||
|
val timeline = normalStates.reversed().map {
|
||||||
|
GiftStatusTimelineResponse(it, "서버 $it", if (it == "DELIVERED") null else date)
|
||||||
|
}
|
||||||
|
val rows = GiftDetailPresenter.present(detail().copy(statusTimeline = timeline)).timeline
|
||||||
|
assertEquals(normalStates, rows.map { it.status })
|
||||||
|
assertEquals(normalStates.map { Raw("서버 $it") }, rows.map { it.title })
|
||||||
|
assertEquals(listOf(true, true, true, true, false), rows.map { it.completed })
|
||||||
|
assertEquals(listOf("10.02", "10.02", "10.02", "10.02", null), rows.map { it.date })
|
||||||
|
val malformed = GiftStatusTimelineResponse("RECEIVED", "접수", "2026-02-30T00:00:00Z")
|
||||||
|
val invalid = GiftDetailPresenter.present(detail().copy(statusTimeline = listOf(malformed))).timeline
|
||||||
|
assertTrue(invalid.all { !it.completed && it.date == null })
|
||||||
|
assertEquals(normalStates, invalid.map { it.status })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `누락된 정상 다섯 단계 제목만 지역화 키를 사용한다`() {
|
||||||
|
val keys = listOf(
|
||||||
|
Key.RECEIVED_LABEL,
|
||||||
|
Key.TRACKING_REGISTERED_LABEL,
|
||||||
|
Key.ARRIVED_AT_MAILBOX_LABEL,
|
||||||
|
Key.INSPECTION_COMPLETED_LABEL,
|
||||||
|
Key.DELIVERED_LABEL
|
||||||
|
)
|
||||||
|
assertEquals(keys, present("RECEIVED").timeline.map { it.title })
|
||||||
|
val source = detail().copy(statusTimeline = listOf(GiftStatusTimelineResponse("RECEIVED", "", null)))
|
||||||
|
assertEquals(listOf(Raw("")) + keys.drop(1), GiftDetailPresenter.present(source).timeline.map { it.title })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `종료 상태는 정상 이력을 보존하며 추가 단계가 되지 않는다`() {
|
||||||
|
listOf("UNDELIVERABLE", "CANCELED").forEach { status ->
|
||||||
|
val history = listOf(
|
||||||
|
GiftStatusTimelineResponse(status, "종료", date),
|
||||||
|
GiftStatusTimelineResponse("RECEIVED", "접수됨", date)
|
||||||
|
)
|
||||||
|
val model = GiftDetailPresenter.present(detail(status).copy(statusTimeline = history))
|
||||||
|
assertEquals(normalStates, model.timeline.map { it.status })
|
||||||
|
assertTrue(model.timeline.first().completed)
|
||||||
|
assertEquals(Raw("접수됨"), model.timeline.first().title)
|
||||||
|
assertTrue(model.timeline.drop(1).all { !it.completed })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `보낸 선물은 모든 상태에서 수신 주소를 모델 어디에도 보존하지 않는다`() {
|
||||||
|
(normalStates + listOf("UNDELIVERABLE", "CANCELED", "FUTURE")).forEach { status ->
|
||||||
|
val source = detail(status).copy(recipientAddress = GiftAddressResponse("비밀이름", "비밀전화", "비밀주소"))
|
||||||
|
val model = GiftDetailPresenter.present(source)
|
||||||
|
assertNull(model.recipientAddress)
|
||||||
|
assertFalse(model.toString().contains("비밀"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `받은 선물의 본인 주소와 보낸 사람 사서함은 대체 없이 구분한다`() {
|
||||||
|
val source = detail().copy(
|
||||||
|
senderInfo = GiftAddressResponse("신청자", "01000000001", "발송지"),
|
||||||
|
mailbox = GiftAddressResponse("사서함", "01000000002", "사서함주소"),
|
||||||
|
recipientAddress = GiftAddressResponse("수신자", "01000000003", "수신주소")
|
||||||
|
)
|
||||||
|
val sent = GiftDetailPresenter.present(source)
|
||||||
|
assertEquals("발송지", sent.senderInfo?.address)
|
||||||
|
assertEquals("사서함주소", sent.mailbox?.address)
|
||||||
|
assertEquals("크리에이터", sent.giftInfo.counterpartNickname)
|
||||||
|
val received = GiftDetailPresenter.present(source.copy(direction = "RECEIVED"))
|
||||||
|
assertEquals(GiftDetailAddress("수신자", "01000000003", "수신주소"), received.recipientAddress)
|
||||||
|
assertEquals("보낸팬", received.giftInfo.counterpartNickname)
|
||||||
|
assertNull(GiftDetailPresenter.present(source.copy(direction = "RECEIVED", recipientAddress = null)).recipientAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `없는 정보와 날짜는 임의 값이나 주소 대체 없이 비운다`() {
|
||||||
|
val model = present("CANCELED")
|
||||||
|
assertNull(model.senderInfo)
|
||||||
|
assertNull(model.mailbox)
|
||||||
|
assertNull(model.recipientAddress)
|
||||||
|
assertNull(model.giftInfo.paidCan)
|
||||||
|
assertNull(model.giftInfo.tracking)
|
||||||
|
assertNull(model.giftInfo.shippingRequestedDate)
|
||||||
|
assertNull(model.giftInfo.inspectionDate)
|
||||||
|
assertNull(model.giftInfo.deliveredDate)
|
||||||
|
assertNull(model.giftInfo.canceledDate)
|
||||||
|
assertNull(model.cancellation?.date)
|
||||||
|
assertNull(model.cancellation?.refundCan)
|
||||||
|
assertNull(model.undeliverable)
|
||||||
|
assertEquals("소형", model.giftInfo.sizeName)
|
||||||
|
assertEquals("잡화", model.giftInfo.categoryName)
|
||||||
|
assertEquals("GIFT-1", model.applicationNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `정보 카드의 선택 값과 검수 전달 날짜는 각 이력에서 가져온다`() {
|
||||||
|
val source = detail().copy(
|
||||||
|
giftInfo = detail().giftInfo.copy(paidCan = 0, tracking = "택배 123", shippingRequestedAt = date),
|
||||||
|
delivery = GiftDeliveryResponse(date, null, null),
|
||||||
|
statusTimeline = listOf(
|
||||||
|
GiftStatusTimelineResponse("INSPECTION_COMPLETED", "검수", date),
|
||||||
|
GiftStatusTimelineResponse("DELIVERED", "전달", "2026-10-02T18:30:00Z")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val info = GiftDetailPresenter.present(source).giftInfo
|
||||||
|
assertEquals(0, info.paidCan)
|
||||||
|
assertEquals("택배 123", info.tracking)
|
||||||
|
assertEquals("2026.10.02", info.shippingRequestedDate)
|
||||||
|
assertEquals("2026.10.02", info.inspectionDate)
|
||||||
|
assertEquals("2026.10.03", info.deliveredDate)
|
||||||
|
assertEquals("2026.10.02", info.canceledDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `전달 불가 서버 사유는 원문이며 기본 제목과 폐기 미반송 안내는 지역화 키다`() {
|
||||||
|
val source = detail("UNDELIVERABLE")
|
||||||
|
val fallback = GiftDetailPresenter.present(source).undeliverable!!
|
||||||
|
assertEquals(Key.UNDELIVERABLE_LABEL, fallback.title)
|
||||||
|
assertEquals(Key.DISPOSAL_NON_RETURN_GUIDANCE, fallback.guidance)
|
||||||
|
listOf("금지 품목", "").forEach { serverReason ->
|
||||||
|
val reason = GiftDetailPresenter.present(
|
||||||
|
source.copy(delivery = source.delivery.copy(undeliverableReason = serverReason))
|
||||||
|
)
|
||||||
|
assertEquals(Raw(serverReason), reason.undeliverable?.title)
|
||||||
|
assertEquals(Key.DISPOSAL_NON_RETURN_GUIDANCE, reason.undeliverable?.guidance)
|
||||||
|
}
|
||||||
|
assertNull(present("RECEIVED").undeliverable)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `취소 응답이 이전 상세보다 우선하고 직접 조회는 상세 값으로 완료 표시한다`() {
|
||||||
|
val source = detail().copy(
|
||||||
|
giftInfo = detail().giftInfo.copy(paidCan = 100),
|
||||||
|
delivery = GiftDeliveryResponse(date, null, null)
|
||||||
|
)
|
||||||
|
val direct = GiftDetailPresenter.present(source.copy(status = "CANCELED"))
|
||||||
|
assertEquals(GiftDetailCancellation("2026.10.02", 100), direct.cancellation)
|
||||||
|
val cancel = GiftCancelResponse("GIFT-1", "CANCELED", "취소", 200, "2026-10-03T18:30:00Z")
|
||||||
|
val result = GiftDetailPresenter.present(source, cancel)
|
||||||
|
assertEquals(direct.hero, result.hero)
|
||||||
|
assertEquals("CANCELED", result.status)
|
||||||
|
assertEquals(GiftDetailCancellation("2026.10.04", 200), result.cancellation)
|
||||||
|
assertEquals("2026.10.04", result.giftInfo.canceledDate)
|
||||||
|
assertEquals(setOf(GiftDetailAction.INQUIRY), result.actions)
|
||||||
|
assertNull(GiftDetailPresenter.present(source, cancel.copy(canceledAt = "bad")).cancellation?.date)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `액션은 운송장 필요와 보낸 접수 조건만 허용하고 미지원 상태는 문의만 허용한다`() {
|
||||||
|
val knownStates = normalStates + listOf("UNDELIVERABLE", "CANCELED")
|
||||||
|
(knownStates + "FUTURE").forEach { status ->
|
||||||
|
listOf("SENT", "RECEIVED").forEach { direction ->
|
||||||
|
listOf(false, true).forEach { required ->
|
||||||
|
val model = GiftDetailPresenter.present(
|
||||||
|
detail(status).copy(direction = direction, trackingRequired = required)
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"$status $direction trackingRequired=$required",
|
||||||
|
status in knownStates && required,
|
||||||
|
GiftDetailAction.TRACKING in model.actions
|
||||||
|
)
|
||||||
|
assertEquals(direction == "SENT" && status == "RECEIVED", GiftDetailAction.CANCEL in model.actions)
|
||||||
|
assertTrue(GiftDetailAction.INQUIRY in model.actions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(GiftDetailHero(null, Raw("서버 상태"), null), present("FUTURE").hero)
|
||||||
|
assertEquals(setOf("TRACKING", "CANCEL", "INQUIRY"), GiftDetailAction.entries.map { it.name }.toSet())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `운송장 액션은 허용된 상세 콘텐츠 상태에서만 표시한다`() {
|
||||||
|
val detail = detail().copy(trackingRequired = true)
|
||||||
|
assertTrue(GiftDetailPresenter.showsTrackingAction(GiftDetailUiState.Content(detail)))
|
||||||
|
assertFalse(GiftDetailPresenter.showsTrackingAction(GiftDetailUiState.Loading))
|
||||||
|
assertFalse(GiftDetailPresenter.showsTrackingAction(GiftDetailUiState.Error("조회 실패")))
|
||||||
|
assertFalse(GiftDetailPresenter.showsTrackingAction(GiftDetailUiState.Canceled(detail, null)))
|
||||||
|
assertFalse(
|
||||||
|
GiftDetailPresenter.showsTrackingAction(
|
||||||
|
GiftDetailUiState.Content(detail("CANCELED").copy(trackingRequired = true))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `UTC 날짜는 기기 시간대로 변환하고 잘못된 날짜는 숨긴다`() {
|
||||||
|
listOf(date, "2026-10-01T18:30:00.123456Z", "2026-10-01T18:30:00+00:00").forEach {
|
||||||
|
assertEquals("10.02", GiftDetailPresenter.formatProgressDate(it))
|
||||||
|
assertEquals("2026.10.02", GiftDetailPresenter.formatCardDate(it))
|
||||||
|
}
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
|
||||||
|
assertEquals("10.01", GiftDetailPresenter.formatProgressDate(date))
|
||||||
|
assertEquals("2026.10.01", GiftDetailPresenter.formatCardDate(date))
|
||||||
|
listOf(null, "", "bad", "2026-02-30T00:00:00Z", "2026-10-01", "2026-10-01T25:00:00Z", "$date junk").forEach {
|
||||||
|
assertNull(GiftDetailPresenter.formatProgressDate(it))
|
||||||
|
assertNull(GiftDetailPresenter.formatCardDate(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `진행 표시는 다섯 이력을 유지하며 도착 우선의 네 구간만 제공한다`() {
|
||||||
|
val source = detail("INSPECTION_COMPLETED").copy(
|
||||||
|
statusTimeline = listOf(
|
||||||
|
GiftStatusTimelineResponse("INSPECTION_COMPLETED", "검수", "2026-10-03T00:00:00Z"),
|
||||||
|
GiftStatusTimelineResponse("ARRIVED_AT_MAILBOX", "도착", date)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val model = GiftDetailPresenter.present(source)
|
||||||
|
assertEquals(normalStates, model.timeline.map { it.status })
|
||||||
|
assertEquals(normalStates.filter { it != "INSPECTION_COMPLETED" }, model.progressSegments.map { it.status })
|
||||||
|
assertEquals(listOf(false, false, true, false), model.progressSegments.map { it.completed })
|
||||||
|
assertEquals("10.02", model.progressSegments[2].date)
|
||||||
|
assertEquals("2026.10.03", model.giftInfo.inspectionDate)
|
||||||
|
val fallback = GiftDetailPresenter.present(source.copy(statusTimeline = source.statusTimeline.take(1)))
|
||||||
|
assertEquals("10.03", fallback.progressSegments[2].date)
|
||||||
|
assertEquals(Key.ARRIVED_AT_MAILBOX_LABEL, fallback.progressSegments[2].title)
|
||||||
|
assertTrue(present("RECEIVED").progressSegments.none { it.completed })
|
||||||
|
val invalid = source.copy(
|
||||||
|
statusTimeline = source.statusTimeline.map {
|
||||||
|
if (it.status == "ARRIVED_AT_MAILBOX") it.copy(occurredAt = "bad") else it
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assertEquals("10.03", GiftDetailPresenter.present(invalid).progressSegments[2].date)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `접수와 종료 상태는 진행 표시를 숨기고 진행 중 네 상태만 표시한다`() {
|
||||||
|
(normalStates + listOf("CANCELED", "UNDELIVERABLE", "FUTURE")).forEach { status ->
|
||||||
|
assertEquals(status in normalStates.drop(1), present(status).showProgress)
|
||||||
|
}
|
||||||
|
assertNull(present("RECEIVED").hero.chip)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `취소 본문은 수신 크리에이터와 최상위 번호를 쓰고 일곱 행에 영 환불을 보존한다`() {
|
||||||
|
val source = detail("CANCELED").copy(
|
||||||
|
direction = "RECEIVED",
|
||||||
|
giftInfo = detail().giftInfo.copy(applicationNo = "중첩번호", paidCan = 0),
|
||||||
|
delivery = GiftDeliveryResponse(date, null, null),
|
||||||
|
statusTimeline = listOf(GiftStatusTimelineResponse("RECEIVED", "접수", date))
|
||||||
|
)
|
||||||
|
val model = GiftDetailPresenter.present(source)
|
||||||
|
assertEquals(GiftDetailText.CancellationBody("크리에이터", "GIFT-1"), model.hero.body)
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
kr.co.vividnext.sodalive.R.string.gift_detail_creator,
|
||||||
|
kr.co.vividnext.sodalive.R.string.gift_send_size,
|
||||||
|
kr.co.vividnext.sodalive.R.string.gift_send_category,
|
||||||
|
kr.co.vividnext.sodalive.R.string.gift_detail_application_no,
|
||||||
|
kr.co.vividnext.sodalive.R.string.gift_tracking_application_date,
|
||||||
|
kr.co.vividnext.sodalive.R.string.gift_detail_canceled_date,
|
||||||
|
kr.co.vividnext.sodalive.R.string.gift_detail_refund
|
||||||
|
),
|
||||||
|
model.cancellationRows.map { it.label }
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
Raw("크리에이터"),
|
||||||
|
Raw("소형"),
|
||||||
|
Raw("잡화"),
|
||||||
|
Raw("GIFT-1"),
|
||||||
|
Raw("2026.10.02"),
|
||||||
|
Raw("2026.10.02"),
|
||||||
|
GiftDetailText.CanAmount(0)
|
||||||
|
),
|
||||||
|
model.cancellationRows.map { it.value }
|
||||||
|
)
|
||||||
|
val missing = GiftDetailPresenter.present(
|
||||||
|
detail("CANCELED").copy(
|
||||||
|
giftInfo = detail().giftInfo.copy(recipientCreatorNickname = null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertEquals(GiftDetailText.CancellationBody(null, "GIFT-1"), missing.hero.body)
|
||||||
|
assertEquals(listOf(Raw("소형"), Raw("잡화"), Raw("GIFT-1")), missing.cancellationRows.map { it.value })
|
||||||
|
val cancel = GiftCancelResponse("GIFT-1", "CANCELED", "취소", 200, "2026-10-03T18:30:00Z")
|
||||||
|
val replaced = GiftDetailPresenter.present(source, cancel).cancellationRows
|
||||||
|
assertEquals(Raw("2026.10.04"), replaced[5].value)
|
||||||
|
assertEquals(GiftDetailText.CanAmount(200), replaced[6].value)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun present(status: String) = GiftDetailPresenter.present(detail(status))
|
||||||
|
|
||||||
|
private fun detail(status: String = "RECEIVED") = GiftDetailResponse(
|
||||||
|
"GIFT-1", "SENT", status, "서버 상태",
|
||||||
|
GiftDetailInfoResponse("크리에이터", "보낸팬", "소형", "잡화", null, null, null, null),
|
||||||
|
null, null, null, false, false, null, GiftDeliveryResponse(null, null, null), emptyList()
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user