feat(gift): 운송장 입력 표시 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftAddressResponse
|
||||
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.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.util.TimeZone
|
||||
|
||||
class GiftTrackingPresenterTest {
|
||||
@Test
|
||||
fun `택배사는 API 없이 정확한 한글명 열네 개를 지정 순서로 제공한다`() {
|
||||
assertEquals(
|
||||
listOf(
|
||||
"CJ대한통운", "우체국택배", "GS25 편의점택배", "CU 편의점택배",
|
||||
"한진택배", "롯데택배", "로젠택배", "경동택배", "대신택배", "일양로지스",
|
||||
"천일택배", "합동택배", "건영택배", "농협택배"
|
||||
),
|
||||
giftCourierCompanyNames
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `등록 필요 여부와 보낸 방향과 사서함이 모두 충족되어야 등록 가능하다`() {
|
||||
listOf(true, false).forEach { required ->
|
||||
listOf("SENT", "RECEIVED").forEach { direction ->
|
||||
listOf(detail().mailbox, null).forEach { mailbox ->
|
||||
val model = GiftTrackingPresenter.present(
|
||||
detail().copy(trackingRequired = required, direction = direction, mailbox = mailbox)
|
||||
)
|
||||
assertEquals(required && direction == "SENT" && mailbox != null, model.isEligible)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `신청 요약은 상세 정보와 접수 이력의 기기 시간대 날짜를 사용한다`() {
|
||||
val previousTimeZone = TimeZone.getDefault()
|
||||
try {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"))
|
||||
val model: GiftTrackingUiModel = GiftTrackingPresenter.present(detail())
|
||||
assertTrue(model.isEligible)
|
||||
assertEquals("GIFT-1", model.applicationNo)
|
||||
assertEquals("크리에이터", model.recipientCreatorNickname)
|
||||
assertEquals("소형", model.sizeName)
|
||||
assertEquals("잡화", model.categoryName)
|
||||
assertEquals(200, model.paidCan)
|
||||
assertEquals("2026.10.02", model.applicationDate)
|
||||
} finally {
|
||||
TimeZone.setDefault(previousTimeZone)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `사서함은 수신 주소와 혼합하거나 대체하지 않는다`() {
|
||||
val source = detail()
|
||||
assertEquals(
|
||||
GiftDetailAddress("가상 사서함", "000-0000-0000", "가상 사서함 주소"),
|
||||
GiftTrackingPresenter.present(source).mailbox
|
||||
)
|
||||
val withoutMailbox = GiftTrackingPresenter.present(source.copy(mailbox = null))
|
||||
assertNull(withoutMailbox.mailbox)
|
||||
assertFalse(withoutMailbox.isEligible)
|
||||
assertEquals(
|
||||
GiftTrackingPresenter.present(source),
|
||||
GiftTrackingPresenter.present(source.copy(recipientAddress = null))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `접수 이력이 없거나 날짜가 잘못되면 다른 날짜로 대체하지 않는다`() {
|
||||
assertNull(GiftTrackingPresenter.present(detail().copy(statusTimeline = emptyList())).applicationDate)
|
||||
listOf(null, "", "bad").forEach { date ->
|
||||
val source = detail().copy(statusTimeline = listOf(GiftStatusTimelineResponse("RECEIVED", "접수", date)))
|
||||
assertNull(GiftTrackingPresenter.present(source).applicationDate)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `선택 정보가 없는 신청 요약은 임의 값으로 대체하지 않는다`() {
|
||||
val source = detail()
|
||||
val model = GiftTrackingPresenter.present(
|
||||
source.copy(giftInfo = source.giftInfo.copy(recipientCreatorNickname = null, paidCan = null))
|
||||
)
|
||||
assertNull(model.recipientCreatorNickname)
|
||||
assertNull(model.paidCan)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `택배사와 ASCII 숫자 10에서 14자리 번호가 모두 있어야 제출을 활성화한다`() {
|
||||
listOf(null, "", " \t\n", "한진택배").forEach { courier ->
|
||||
listOf(
|
||||
"",
|
||||
"1",
|
||||
"123456789",
|
||||
"0123456789",
|
||||
"00123456789012",
|
||||
"123456789012345",
|
||||
" 0123456789",
|
||||
"0123456789 ",
|
||||
"01234 56789",
|
||||
"01234-56789",
|
||||
"012345678a",
|
||||
"1234567890",
|
||||
"١٢٣٤٥٦٧٨٩٠",
|
||||
" \t\n"
|
||||
).forEach { number ->
|
||||
assertEquals(
|
||||
"$courier / $number",
|
||||
courier == "한진택배" && number in listOf("0123456789", "00123456789012"),
|
||||
GiftTrackingPresenter.isSubmitEnabled(courier, number)
|
||||
)
|
||||
}
|
||||
}
|
||||
assertFalse(GiftTrackingPresenter.isSubmitEnabled("한진택배", "1".repeat(1000)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `빈 입력은 오류가 없고 잘못된 번호를 고치면 오류가 해제된다`() {
|
||||
listOf(
|
||||
"" to false,
|
||||
"1" to true,
|
||||
"123456789" to true,
|
||||
"0123456789" to false,
|
||||
"123456789012345" to true,
|
||||
"00123456789012" to false,
|
||||
" " to true,
|
||||
"01234-56789" to true,
|
||||
"012345678a" to true,
|
||||
"1234567890" to true,
|
||||
"١٢٣٤٥٦٧٨٩٠" to true,
|
||||
"" to false
|
||||
).forEach { (number, error) ->
|
||||
assertEquals(number, error, GiftTrackingPresenter.hasTrackingNumberError(number))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `모든 택배사 표시명과 선행 0을 포함한 번호 원문을 그대로 보낸다`() {
|
||||
giftCourierCompanyNames.forEach { courier ->
|
||||
val request = GiftTrackingPresenter.toRequest(courier, "00123456789012")
|
||||
assertEquals(courier, request.courierCompanyName)
|
||||
assertEquals("00123456789012", request.trackingNumber)
|
||||
}
|
||||
}
|
||||
|
||||
private fun detail() = GiftDetailResponse(
|
||||
applicationNo = "GIFT-1",
|
||||
direction = "SENT",
|
||||
status = "RECEIVED",
|
||||
statusName = "접수 완료",
|
||||
giftInfo = GiftDetailInfoResponse(
|
||||
"크리에이터",
|
||||
"보낸팬",
|
||||
"소형",
|
||||
"잡화",
|
||||
"INFO-1",
|
||||
200,
|
||||
null,
|
||||
"2026-09-01T00:00:00Z"
|
||||
),
|
||||
senderInfo = null,
|
||||
recipientAddress = GiftAddressResponse("가상 수신인", "000-1111-1111", "가상 수신 주소"),
|
||||
mailbox = GiftAddressResponse("가상 사서함", "000-0000-0000", "가상 사서함 주소"),
|
||||
trackingRequired = true,
|
||||
recipientAddressRequired = false,
|
||||
recipientAddressDeadlineAt = null,
|
||||
delivery = GiftDeliveryResponse(null, null, null),
|
||||
statusTimeline = listOf(
|
||||
GiftStatusTimelineResponse("TRACKING_REGISTERED", "등록", "2026-10-03T00:00:00Z"),
|
||||
GiftStatusTimelineResponse("RECEIVED", "접수", "2026-10-01T18:30:00Z")
|
||||
)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user