feat(gift): 선물 상세 API 계약을 추가한다

This commit is contained in:
2026-10-02 18:30:15 +09:00
parent d907d2cdc2
commit 1931e6fda3
5 changed files with 339 additions and 0 deletions
@@ -5,6 +5,7 @@ import kr.co.vividnext.sodalive.common.ApiResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Path
import retrofit2.http.POST
import retrofit2.http.Query
@@ -27,4 +28,23 @@ interface GiftApi {
@Body request: GiftCreateRequest,
@Header("Authorization") authHeader: String
): Single<ApiResponse<Any>>
@GET("/api/v2/gifts/{applicationNo}")
fun getGiftDetail(
@Path("applicationNo") applicationNo: String,
@Header("Authorization") authHeader: String
): Single<ApiResponse<GiftDetailResponse>>
@POST("/api/v2/gifts/{applicationNo}/tracking")
fun registerGiftTracking(
@Path("applicationNo") applicationNo: String,
@Body request: GiftTrackingRequest,
@Header("Authorization") authHeader: String
): Single<ApiResponse<GiftTrackingResponse>>
@POST("/api/v2/gifts/{applicationNo}/cancel")
fun cancelGift(
@Path("applicationNo") applicationNo: String,
@Header("Authorization") authHeader: String
): Single<ApiResponse<GiftCancelResponse>>
}
@@ -62,3 +62,79 @@ data class GiftCreateRequest(
@SerializedName("senderPrivacyAgreed") val senderPrivacyAgreed: Boolean,
@SerializedName("damageWaiverAgreed") val damageWaiverAgreed: Boolean
)
@Keep
data class GiftDetailResponse(
@SerializedName("applicationNo") val applicationNo: String,
@SerializedName("direction") val direction: String,
@SerializedName("status") val status: String,
@SerializedName("statusName") val statusName: String,
@SerializedName("giftInfo") val giftInfo: GiftDetailInfoResponse,
@SerializedName("senderInfo") val senderInfo: GiftAddressResponse?,
@SerializedName("recipientAddress") val recipientAddress: GiftAddressResponse?,
@SerializedName("mailbox") val mailbox: GiftAddressResponse?,
@SerializedName("trackingRequired") val trackingRequired: Boolean,
@SerializedName("recipientAddressRequired") val recipientAddressRequired: Boolean,
@SerializedName("recipientAddressDeadlineAt") val recipientAddressDeadlineAt: String?,
@SerializedName("delivery") val delivery: GiftDeliveryResponse,
@SerializedName("statusTimeline") val statusTimeline: List<GiftStatusTimelineResponse>
)
@Keep
data class GiftDetailInfoResponse(
@SerializedName("recipientCreatorNickname") val recipientCreatorNickname: String?,
@SerializedName("senderNickname") val senderNickname: String?,
@SerializedName("sizeName") val sizeName: String,
@SerializedName("categoryName") val categoryName: String,
@SerializedName("applicationNo") val applicationNo: String?,
@SerializedName("paidCan") val paidCan: Int?,
@SerializedName("tracking") val tracking: String?,
@SerializedName("shippingRequestedAt") val shippingRequestedAt: String?
)
@Keep
data class GiftAddressResponse(
@SerializedName("name") val name: String,
@SerializedName("phoneNumber") val phoneNumber: String,
@SerializedName("address") val address: String
)
@Keep
data class GiftDeliveryResponse(
@SerializedName("canceledAt") val canceledAt: String?,
@SerializedName("undeliverableAt") val undeliverableAt: String?,
@SerializedName("undeliverableReason") val undeliverableReason: String?
)
@Keep
data class GiftStatusTimelineResponse(
@SerializedName("status") val status: String,
@SerializedName("statusName") val statusName: String,
@SerializedName("occurredAt") val occurredAt: String?
)
@Keep
data class GiftTrackingRequest(
@SerializedName("courierCompanyName") val courierCompanyName: String,
@SerializedName("trackingNumber") val trackingNumber: String
)
@Keep
data class GiftTrackingResponse(
@SerializedName("applicationNo") val applicationNo: String,
@SerializedName("status") val status: String,
@SerializedName("statusName") val statusName: String,
@SerializedName("courierCompanyName") val courierCompanyName: String,
@SerializedName("trackingNumber") val trackingNumber: String,
@SerializedName("trackingRegisteredAt") val trackingRegisteredAt: String,
@SerializedName("recipientAddressDeadlineAt") val recipientAddressDeadlineAt: String
)
@Keep
data class GiftCancelResponse(
@SerializedName("applicationNo") val applicationNo: String,
@SerializedName("status") val status: String,
@SerializedName("statusName") val statusName: String,
@SerializedName("priceCan") val priceCan: Int,
@SerializedName("canceledAt") val canceledAt: String
)
@@ -14,4 +14,21 @@ class GiftRepository(private val api: GiftApi) {
request = request,
authHeader = token
)
fun getGiftDetail(applicationNo: String, token: String) = api.getGiftDetail(
applicationNo = applicationNo,
authHeader = token
)
fun registerGiftTracking(applicationNo: String, request: GiftTrackingRequest, token: String) =
api.registerGiftTracking(
applicationNo = applicationNo,
request = request,
authHeader = token
)
fun cancelGift(applicationNo: String, token: String) = api.cancelGift(
applicationNo = applicationNo,
authHeader = token
)
}
@@ -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())
}
}