feat(gift): 배송지 상태와 취소일을 반영한다
This commit is contained in:
@@ -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