feat(gift): 선물 상세 API 계약을 추가한다
This commit is contained in:
@@ -14,11 +14,15 @@ import io.reactivex.rxjava3.subjects.SingleSubject
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftApi
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftCancelResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftCategoryResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftCreateRequest
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftDetailResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftFormOptionsResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftRepository
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftSizeResponse
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingRequest
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingResponse
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
@@ -171,6 +175,22 @@ class GiftSendRequestViewModelTest {
|
||||
): Single<ApiResponse<kr.co.vividnext.sodalive.v2.gift.data.GiftInboxResponse>> =
|
||||
Single.error(UnsupportedOperationException())
|
||||
|
||||
override fun getGiftDetail(
|
||||
applicationNo: String,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftDetailResponse>> = Single.error(UnsupportedOperationException())
|
||||
|
||||
override fun registerGiftTracking(
|
||||
applicationNo: String,
|
||||
request: GiftTrackingRequest,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftTrackingResponse>> = Single.error(UnsupportedOperationException())
|
||||
|
||||
override fun cancelGift(
|
||||
applicationNo: String,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftCancelResponse>> = Single.error(UnsupportedOperationException())
|
||||
|
||||
private val formOptionsResponses = ArrayDeque<Single<ApiResponse<GiftFormOptionsResponse>>>()
|
||||
private val createGiftResponses = ArrayDeque<Single<ApiResponse<Any>>>()
|
||||
var lastAuthHeader: String? = null
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift.data
|
||||
|
||||
import com.google.gson.Gson
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GiftRepositoryTest {
|
||||
|
||||
@Test
|
||||
fun `상세 응답은 nullable 주소와 delivery 및 다섯 timeline을 보존한다`() {
|
||||
val response = Gson().fromJson(
|
||||
"""
|
||||
{
|
||||
"applicationNo": "GIFT-FAKE-001",
|
||||
"direction": "SENT",
|
||||
"status": "RECEIVED",
|
||||
"statusName": "접수 완료",
|
||||
"giftInfo": {
|
||||
"recipientCreatorNickname": "가상크리에이터",
|
||||
"senderNickname": "가상팬",
|
||||
"sizeName": "소형",
|
||||
"categoryName": "가상 카테고리",
|
||||
"applicationNo": "GIFT-FAKE-001",
|
||||
"paidCan": 120,
|
||||
"tracking": null,
|
||||
"shippingRequestedAt": null
|
||||
},
|
||||
"senderInfo": {
|
||||
"name": "가상 보낸이",
|
||||
"phoneNumber": "01000000000",
|
||||
"address": "가상 주소 1"
|
||||
},
|
||||
"recipientAddress": null,
|
||||
"mailbox": {
|
||||
"name": "SODALIVE 사서함",
|
||||
"phoneNumber": "01011112222",
|
||||
"address": "가상 사서함 주소"
|
||||
},
|
||||
"trackingRequired": true,
|
||||
"recipientAddressRequired": false,
|
||||
"recipientAddressDeadlineAt": null,
|
||||
"delivery": {
|
||||
"canceledAt": "2026-10-02T03:00:00Z",
|
||||
"undeliverableAt": "2026-10-02T04:00:00Z",
|
||||
"undeliverableReason": "가상 배송 사유"
|
||||
},
|
||||
"statusTimeline": [
|
||||
{"status": "RECEIVED", "statusName": "접수 완료", "occurredAt": "2026-10-02T01:00:00Z"},
|
||||
{"status": "TRACKING_REGISTERED", "statusName": "발송 확인", "occurredAt": null},
|
||||
{"status": "ARRIVED_AT_MAILBOX", "statusName": "사서함 도착", "occurredAt": null},
|
||||
{"status": "INSPECTION_COMPLETED", "statusName": "검수 완료", "occurredAt": null},
|
||||
{"status": "DELIVERED", "statusName": "전달 완료", "occurredAt": null}
|
||||
]
|
||||
}
|
||||
""".trimIndent(),
|
||||
GiftDetailResponse::class.java
|
||||
)
|
||||
|
||||
assertEquals("GIFT-FAKE-001", response.applicationNo)
|
||||
assertEquals("가상크리에이터", response.giftInfo.recipientCreatorNickname)
|
||||
assertEquals(120, response.giftInfo.paidCan)
|
||||
assertNull(response.recipientAddress)
|
||||
assertEquals("가상 사서함 주소", response.mailbox?.address)
|
||||
assertTrue(response.trackingRequired)
|
||||
assertEquals(
|
||||
GiftDeliveryResponse(
|
||||
canceledAt = "2026-10-02T03:00:00Z",
|
||||
undeliverableAt = "2026-10-02T04:00:00Z",
|
||||
undeliverableReason = "가상 배송 사유"
|
||||
),
|
||||
response.delivery
|
||||
)
|
||||
assertEquals(
|
||||
listOf(
|
||||
GiftStatusTimelineResponse("RECEIVED", "접수 완료", "2026-10-02T01:00:00Z"),
|
||||
GiftStatusTimelineResponse("TRACKING_REGISTERED", "발송 확인", null),
|
||||
GiftStatusTimelineResponse("ARRIVED_AT_MAILBOX", "사서함 도착", null),
|
||||
GiftStatusTimelineResponse("INSPECTION_COMPLETED", "검수 완료", null),
|
||||
GiftStatusTimelineResponse("DELIVERED", "전달 완료", null)
|
||||
),
|
||||
response.statusTimeline
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `tracking request는 계약된 JSON key로 직렬화된다`() {
|
||||
val json = Gson().toJson(GiftTrackingRequest("가상택배사", "123456789012"))
|
||||
|
||||
assertEquals(
|
||||
"{\"courierCompanyName\":\"가상택배사\",\"trackingNumber\":\"123456789012\"}",
|
||||
json
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cancel response는 priceCan과 canceledAt을 보존한다`() {
|
||||
val response = Gson().fromJson(
|
||||
"""
|
||||
{"applicationNo":"GIFT-FAKE-002","status":"CANCELED","statusName":"신청 취소","priceCan":77,"canceledAt":"2026-10-02T02:00:00Z"}
|
||||
""".trimIndent(),
|
||||
GiftCancelResponse::class.java
|
||||
)
|
||||
|
||||
assertEquals(77, response.priceCan)
|
||||
assertEquals("2026-10-02T02:00:00Z", response.canceledAt)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `상세 repository는 신청번호와 인증을 변경 없이 전달한다`() {
|
||||
val api = RepositoryFakeGiftApi()
|
||||
|
||||
GiftRepository(api).getGiftDetail("GIFT-DETAIL-001", "Bearer detail-token")
|
||||
.test()
|
||||
.assertError(UnsupportedOperationException::class.java)
|
||||
|
||||
assertEquals(
|
||||
DetailCall(applicationNo = "GIFT-DETAIL-001", authHeader = "Bearer detail-token"),
|
||||
api.detailCall
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `운송장 repository는 신청번호 요청 본문 인증을 변경 없이 전달한다`() {
|
||||
val api = RepositoryFakeGiftApi()
|
||||
val request = GiftTrackingRequest("가상택배", "123456789012")
|
||||
|
||||
GiftRepository(api).registerGiftTracking("GIFT-TRACKING-001", request, "Bearer tracking-token")
|
||||
.test()
|
||||
.assertError(UnsupportedOperationException::class.java)
|
||||
|
||||
assertEquals("GIFT-TRACKING-001", api.trackingCall?.applicationNo)
|
||||
assertSame(request, api.trackingCall?.request)
|
||||
assertEquals("Bearer tracking-token", api.trackingCall?.authHeader)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `취소 repository는 신청번호와 인증을 변경 없이 전달한다`() {
|
||||
val api = RepositoryFakeGiftApi()
|
||||
|
||||
GiftRepository(api).cancelGift("GIFT-CANCEL-001", "Bearer cancel-token")
|
||||
.test()
|
||||
.assertError(UnsupportedOperationException::class.java)
|
||||
|
||||
assertEquals(
|
||||
DetailCall(applicationNo = "GIFT-CANCEL-001", authHeader = "Bearer cancel-token"),
|
||||
api.cancelCall
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private data class DetailCall(val applicationNo: String, val authHeader: String)
|
||||
|
||||
private data class TrackingCall(
|
||||
val applicationNo: String,
|
||||
val request: GiftTrackingRequest,
|
||||
val authHeader: String
|
||||
)
|
||||
|
||||
private class RepositoryFakeGiftApi : GiftApi {
|
||||
var detailCall: DetailCall? = null
|
||||
var trackingCall: TrackingCall? = null
|
||||
var cancelCall: DetailCall? = null
|
||||
|
||||
override fun getGiftInbox(
|
||||
type: String,
|
||||
page: Int,
|
||||
size: Int,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftInboxResponse>> = Single.error(UnsupportedOperationException())
|
||||
|
||||
override fun getFormOptions(authHeader: String): Single<ApiResponse<GiftFormOptionsResponse>> =
|
||||
Single.error(UnsupportedOperationException())
|
||||
|
||||
override fun createGift(request: GiftCreateRequest, authHeader: String): Single<ApiResponse<Any>> =
|
||||
Single.error(UnsupportedOperationException())
|
||||
|
||||
override fun getGiftDetail(
|
||||
applicationNo: String,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftDetailResponse>> {
|
||||
detailCall = DetailCall(applicationNo, authHeader)
|
||||
return Single.error(UnsupportedOperationException())
|
||||
}
|
||||
|
||||
override fun registerGiftTracking(
|
||||
applicationNo: String,
|
||||
request: GiftTrackingRequest,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftTrackingResponse>> {
|
||||
trackingCall = TrackingCall(applicationNo, request, authHeader)
|
||||
return Single.error(UnsupportedOperationException())
|
||||
}
|
||||
|
||||
override fun cancelGift(
|
||||
applicationNo: String,
|
||||
authHeader: String
|
||||
): Single<ApiResponse<GiftCancelResponse>> {
|
||||
cancelCall = DetailCall(applicationNo, authHeader)
|
||||
return Single.error(UnsupportedOperationException())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user