feat(gift): 배송지 상태와 취소일을 반영한다
This commit is contained in:
@@ -17,6 +17,7 @@ data class GiftInboxCardUiModel(
|
||||
val sizeName: String,
|
||||
val categoryName: String,
|
||||
val addressRequired: Boolean,
|
||||
val addressDeadlineDays: Int?,
|
||||
val counterpartMemberId: Long,
|
||||
val counterpartNickname: String,
|
||||
val counterpartProfileImageUrl: String?
|
||||
|
||||
@@ -5,8 +5,12 @@ import kr.co.vividnext.sodalive.common.ToastMessage
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxItemResponse
|
||||
|
||||
object GiftInboxPresenter {
|
||||
fun toCard(item: GiftInboxItemResponse): GiftInboxCardUiModel {
|
||||
fun toCard(
|
||||
item: GiftInboxItemResponse,
|
||||
nowMillis: Long = System.currentTimeMillis()
|
||||
): GiftInboxCardUiModel {
|
||||
val received = item.direction == "RECEIVED"
|
||||
val addressRequired = received && item.status != "UNDELIVERABLE" && !item.recipientAddressRegistered
|
||||
val statusRes = if (received) {
|
||||
when (item.status) {
|
||||
"TRACKING_REGISTERED" -> R.string.gift_inbox_address_required
|
||||
@@ -43,11 +47,22 @@ object GiftInboxPresenter {
|
||||
direction = if (received) GiftInboxDirection.RECEIVED else GiftInboxDirection.SENT,
|
||||
status = if (statusRes != null) ToastMessage(resId = statusRes) else ToastMessage(message = item.statusName),
|
||||
subtitleRes = subtitle,
|
||||
createdDate = item.createdAt?.substringBefore('T')?.replace('-', '.').orEmpty(),
|
||||
dateLabelRes = R.string.gift_inbox_applied_date,
|
||||
createdDate = GiftDetailPresenter.formatCardDate(
|
||||
if (item.status == "CANCELED") item.canceledAt ?: item.createdAt else item.createdAt
|
||||
).orEmpty(),
|
||||
dateLabelRes = if (item.status == "CANCELED") {
|
||||
R.string.gift_inbox_canceled_date
|
||||
} else {
|
||||
R.string.gift_inbox_applied_date
|
||||
},
|
||||
sizeName = item.sizeName,
|
||||
categoryName = item.categoryName,
|
||||
addressRequired = received && item.status == "TRACKING_REGISTERED",
|
||||
addressRequired = addressRequired,
|
||||
addressDeadlineDays = if (addressRequired) {
|
||||
GiftDateTime.remainingDays(item.recipientAddressDeadlineAt, nowMillis)
|
||||
} else {
|
||||
null
|
||||
},
|
||||
counterpartMemberId = item.counterpartMemberId,
|
||||
counterpartNickname = item.counterpartNickname,
|
||||
counterpartProfileImageUrl = item.counterpartProfileImageUrl?.takeIf { it.isNotBlank() }
|
||||
@@ -59,9 +74,12 @@ object GiftInboxPresenter {
|
||||
viewMode: GiftInboxViewMode,
|
||||
isCreator: Boolean,
|
||||
isAppending: Boolean = false,
|
||||
canRetry: Boolean = false
|
||||
canRetry: Boolean = false,
|
||||
nowMillis: Long = System.currentTimeMillis()
|
||||
): List<GiftInboxRow> {
|
||||
val cards = items.filter { viewMode == GiftInboxViewMode.ALL || it.direction == viewMode.name }.map(::toCard)
|
||||
val cards = items
|
||||
.filter { viewMode == GiftInboxViewMode.ALL || it.direction == viewMode.name }
|
||||
.map { toCard(it, nowMillis) }
|
||||
val rows = if (cards.isEmpty()) {
|
||||
val received = viewMode == GiftInboxViewMode.RECEIVED || (viewMode == GiftInboxViewMode.ALL && isCreator)
|
||||
listOf(if (received) GiftInboxRow.EmptyReceived else GiftInboxRow.Notice(false))
|
||||
|
||||
@@ -24,7 +24,10 @@ data class GiftInboxItemResponse(
|
||||
@SerializedName("createdAt") val createdAt: String?,
|
||||
@SerializedName("counterpartMemberId") val counterpartMemberId: Long,
|
||||
@SerializedName("counterpartNickname") val counterpartNickname: String,
|
||||
@SerializedName("counterpartProfileImageUrl") val counterpartProfileImageUrl: String?
|
||||
@SerializedName("counterpartProfileImageUrl") val counterpartProfileImageUrl: String?,
|
||||
@SerializedName("recipientAddressRegistered") val recipientAddressRegistered: Boolean,
|
||||
@SerializedName("recipientAddressDeadlineAt") val recipientAddressDeadlineAt: String?,
|
||||
@SerializedName("canceledAt") val canceledAt: String?
|
||||
)
|
||||
|
||||
@Keep
|
||||
|
||||
@@ -7,25 +7,35 @@ import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.util.TimeZone
|
||||
|
||||
class GiftInboxPresenterTest {
|
||||
@Test
|
||||
fun `보낸 선물 상태 일곱 개를 표시 문구에 매핑한다`() {
|
||||
val expected = mapOf(
|
||||
"RECEIVED" to R.string.gift_inbox_tracking_required,
|
||||
"TRACKING_REGISTERED" to R.string.gift_inbox_sent_confirmed,
|
||||
"ARRIVED_AT_MAILBOX" to R.string.gift_inbox_arrived,
|
||||
"INSPECTION_COMPLETED" to R.string.gift_inbox_inspected,
|
||||
"DELIVERED" to R.string.gift_inbox_delivered,
|
||||
"UNDELIVERABLE" to R.string.gift_inbox_undeliverable,
|
||||
"CANCELED" to R.string.gift_inbox_canceled
|
||||
)
|
||||
expected.forEach { (status, label) ->
|
||||
val card = GiftInboxPresenter.toCard(inboxItem(status = status))
|
||||
assertEquals(GiftInboxDirection.SENT, card.direction)
|
||||
assertEquals(label, card.status.resId)
|
||||
assertEquals("2026.09.18", card.createdDate)
|
||||
assertEquals(R.string.gift_inbox_applied_date, card.dateLabelRes)
|
||||
val originalTimeZone = TimeZone.getDefault()
|
||||
try {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
|
||||
val expected = mapOf(
|
||||
"RECEIVED" to R.string.gift_inbox_tracking_required,
|
||||
"TRACKING_REGISTERED" to R.string.gift_inbox_sent_confirmed,
|
||||
"ARRIVED_AT_MAILBOX" to R.string.gift_inbox_arrived,
|
||||
"INSPECTION_COMPLETED" to R.string.gift_inbox_inspected,
|
||||
"DELIVERED" to R.string.gift_inbox_delivered,
|
||||
"UNDELIVERABLE" to R.string.gift_inbox_undeliverable,
|
||||
"CANCELED" to R.string.gift_inbox_canceled
|
||||
)
|
||||
expected.forEach { (status, label) ->
|
||||
val card = GiftInboxPresenter.toCard(inboxItem(status = status))
|
||||
assertEquals(GiftInboxDirection.SENT, card.direction)
|
||||
assertEquals(label, card.status.resId)
|
||||
assertEquals("2026.09.18", card.createdDate)
|
||||
assertEquals(
|
||||
if (status == "CANCELED") R.string.gift_inbox_canceled_date else R.string.gift_inbox_applied_date,
|
||||
card.dateLabelRes
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
TimeZone.setDefault(originalTimeZone)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +121,10 @@ class GiftInboxPresenterTest {
|
||||
|
||||
@Test
|
||||
fun `혼합 목록은 안내 뒤 서버 아이템 순서와 문의를 유지하고 섹션 제목을 만들지 않는다`() {
|
||||
val items = listOf(inboxItem("z"), inboxItem("a", "RECEIVED", "TRACKING_REGISTERED"))
|
||||
val items = listOf(
|
||||
inboxItem("z"),
|
||||
inboxItem("a", "RECEIVED", "TRACKING_REGISTERED", recipientAddressRegistered = false)
|
||||
)
|
||||
val rows = GiftInboxPresenter.toUiModels(items, GiftInboxViewMode.ALL, false)
|
||||
assertEquals(
|
||||
listOf("NOTICE", "NOTICE", "SENT", "ADDRESS", "INQUIRY"),
|
||||
@@ -136,7 +149,7 @@ class GiftInboxPresenterTest {
|
||||
@Test
|
||||
fun `배송지 입력 필요 선물 한 건은 일반 카드 없이 address 아이템으로 표시한다`() {
|
||||
val rows = GiftInboxPresenter.toUiModels(
|
||||
listOf(inboxItem("one", "RECEIVED", "TRACKING_REGISTERED")),
|
||||
listOf(inboxItem("one", "RECEIVED", "TRACKING_REGISTERED", recipientAddressRegistered = false)),
|
||||
GiftInboxViewMode.RECEIVED,
|
||||
true
|
||||
)
|
||||
@@ -152,7 +165,10 @@ class GiftInboxPresenterTest {
|
||||
@Test
|
||||
fun `배송지 입력 필요 선물 여러 건은 각각 address 아이템으로 표시한다`() {
|
||||
val rows = GiftInboxPresenter.toUiModels(
|
||||
listOf(inboxItem("one", "RECEIVED", "TRACKING_REGISTERED"), inboxItem("two", "RECEIVED", "TRACKING_REGISTERED")),
|
||||
listOf(
|
||||
inboxItem("one", "RECEIVED", "TRACKING_REGISTERED", recipientAddressRegistered = false),
|
||||
inboxItem("two", "RECEIVED", "TRACKING_REGISTERED", recipientAddressRegistered = false)
|
||||
),
|
||||
GiftInboxViewMode.ALL,
|
||||
true
|
||||
)
|
||||
@@ -167,8 +183,8 @@ class GiftInboxPresenterTest {
|
||||
fun `배송지 입력 필요와 완료 선물은 서버 순서대로 서로 다른 아이템으로 표시한다`() {
|
||||
val rows = GiftInboxPresenter.toUiModels(
|
||||
listOf(
|
||||
inboxItem("pending", "RECEIVED", "TRACKING_REGISTERED"),
|
||||
inboxItem("completed", "RECEIVED", "ARRIVED_AT_MAILBOX")
|
||||
inboxItem("pending", "RECEIVED", "TRACKING_REGISTERED", recipientAddressRegistered = false),
|
||||
inboxItem("completed", "RECEIVED", "ARRIVED_AT_MAILBOX", recipientAddressRegistered = true)
|
||||
),
|
||||
GiftInboxViewMode.RECEIVED,
|
||||
true
|
||||
@@ -182,6 +198,107 @@ class GiftInboxPresenterTest {
|
||||
assertEquals("completed", (rows[2] as GiftInboxRow.Card).card.applicationNo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `배송지 미등록 받은 선물은 상태와 관계없이 전달 불가를 제외하고 address 아이템으로 표시한다`() {
|
||||
val rows = GiftInboxPresenter.toUiModels(
|
||||
listOf(
|
||||
inboxItem("arrived-address", "RECEIVED", "ARRIVED_AT_MAILBOX", recipientAddressRegistered = false),
|
||||
inboxItem("arrived-card", "RECEIVED", "ARRIVED_AT_MAILBOX", recipientAddressRegistered = true),
|
||||
inboxItem("inspected-address", "RECEIVED", "INSPECTION_COMPLETED", recipientAddressRegistered = false),
|
||||
inboxItem("inspected-card", "RECEIVED", "INSPECTION_COMPLETED", recipientAddressRegistered = true),
|
||||
inboxItem("undeliverable", "RECEIVED", "UNDELIVERABLE", recipientAddressRegistered = false)
|
||||
),
|
||||
GiftInboxViewMode.RECEIVED,
|
||||
true
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
listOf(
|
||||
GiftInboxRowType.NOTICE,
|
||||
GiftInboxRowType.ADDRESS,
|
||||
GiftInboxRowType.RECEIVED,
|
||||
GiftInboxRowType.ADDRESS,
|
||||
GiftInboxRowType.RECEIVED,
|
||||
GiftInboxRowType.RECEIVED,
|
||||
GiftInboxRowType.INQUIRY
|
||||
),
|
||||
rows.map { it.type }
|
||||
)
|
||||
assertEquals(
|
||||
listOf("arrived-address", "inspected-address"),
|
||||
rows.filterIsInstance<GiftInboxRow.Address>().map { it.card.applicationNo }
|
||||
)
|
||||
assertEquals(
|
||||
listOf("arrived-card", "inspected-card", "undeliverable"),
|
||||
rows.filterIsInstance<GiftInboxRow.Card>().map { it.card.applicationNo }
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `배송지 경고는 미등록 받은 선물의 유효한 마감일에만 남은 일수를 보존한다`() {
|
||||
val nowMillis = 1_789_689_601_000L
|
||||
val address = GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
direction = "RECEIVED",
|
||||
status = "ARRIVED_AT_MAILBOX",
|
||||
recipientAddressRegistered = false,
|
||||
recipientAddressDeadlineAt = "2026-09-20T00:00:00Z"
|
||||
),
|
||||
nowMillis
|
||||
)
|
||||
val registered = GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
direction = "RECEIVED",
|
||||
recipientAddressRegistered = true,
|
||||
recipientAddressDeadlineAt = null
|
||||
),
|
||||
nowMillis
|
||||
)
|
||||
val inputNotRequired = GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
direction = "SENT",
|
||||
recipientAddressRegistered = false,
|
||||
recipientAddressDeadlineAt = null
|
||||
),
|
||||
nowMillis
|
||||
)
|
||||
|
||||
assertTrue(address.addressRequired)
|
||||
assertEquals(2, address.addressDeadlineDays)
|
||||
assertFalse(registered.addressRequired)
|
||||
assertNull(registered.addressDeadlineDays)
|
||||
assertFalse(inputNotRequired.addressRequired)
|
||||
assertNull(inputNotRequired.addressDeadlineDays)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `취소 선물은 취소일을 우선하고 없으면 신청일을 기기 시간대로 표시한다`() {
|
||||
val originalTimeZone = TimeZone.getDefault()
|
||||
try {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
|
||||
val canceled = GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
status = "CANCELED",
|
||||
createdAt = "2026-09-17T00:30:00Z",
|
||||
canceledAt = "2026-09-19T00:30:00Z"
|
||||
)
|
||||
)
|
||||
val fallback = GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
status = "CANCELED",
|
||||
createdAt = "2026-09-19T00:30:00Z",
|
||||
canceledAt = null
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals("2026.09.18", canceled.createdDate)
|
||||
assertEquals(R.string.gift_inbox_canceled_date, canceled.dateLabelRes)
|
||||
assertEquals("2026.09.18", fallback.createdDate)
|
||||
} finally {
|
||||
TimeZone.setDefault(originalTimeZone)
|
||||
}
|
||||
}
|
||||
|
||||
private fun rows(mode: GiftInboxViewMode, creator: Boolean) =
|
||||
GiftInboxPresenter.toUiModels(emptyList(), mode, creator).map { it.type }
|
||||
|
||||
@@ -202,7 +319,10 @@ internal fun inboxItem(
|
||||
createdAt: String? = "2026-09-18T03:00:00Z",
|
||||
counterpartMemberId: Long = 1L,
|
||||
counterpartNickname: String = "상대방",
|
||||
counterpartProfileImageUrl: String? = null
|
||||
counterpartProfileImageUrl: String? = null,
|
||||
recipientAddressRegistered: Boolean = true,
|
||||
recipientAddressDeadlineAt: String? = null,
|
||||
canceledAt: String? = null
|
||||
) = GiftInboxItemResponse(
|
||||
id,
|
||||
direction,
|
||||
@@ -214,5 +334,8 @@ internal fun inboxItem(
|
||||
createdAt,
|
||||
counterpartMemberId,
|
||||
counterpartNickname,
|
||||
counterpartProfileImageUrl
|
||||
counterpartProfileImageUrl,
|
||||
recipientAddressRegistered,
|
||||
recipientAddressDeadlineAt,
|
||||
canceledAt
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user