feat(gift): 배송지 API 계약을 추가한다

This commit is contained in:
2026-10-02 23:54:21 +09:00
parent 688921d4d1
commit ee76011d9e
6 changed files with 159 additions and 0 deletions
@@ -42,6 +42,13 @@ interface GiftApi {
@Header("Authorization") authHeader: String
): Single<ApiResponse<GiftTrackingResponse>>
@POST("/api/v2/gifts/{applicationNo}/recipient-address")
fun registerRecipientAddress(
@Path("applicationNo") applicationNo: String,
@Body request: GiftRecipientAddressRequest,
@Header("Authorization") authHeader: String
): Single<ApiResponse<GiftRecipientAddressResponse>>
@POST("/api/v2/gifts/{applicationNo}/cancel")
fun cancelGift(
@Path("applicationNo") applicationNo: String,
@@ -130,6 +130,25 @@ data class GiftTrackingResponse(
@SerializedName("recipientAddressDeadlineAt") val recipientAddressDeadlineAt: String
)
@Keep
data class GiftRecipientAddressRequest(
@SerializedName("recipientName") val recipientName: String,
@SerializedName("recipientPhoneNumber") val recipientPhoneNumber: String,
@SerializedName("recipientZipCode") val recipientZipCode: String,
@SerializedName("recipientAddress") val recipientAddress: String,
@SerializedName("recipientAddressDetail") val recipientAddressDetail: String,
@SerializedName("recipientTermsAgreed") val recipientTermsAgreed: Boolean,
@SerializedName("recipientPrivacyAgreed") val recipientPrivacyAgreed: Boolean
)
@Keep
data class GiftRecipientAddressResponse(
@SerializedName("applicationNo") val applicationNo: String,
@SerializedName("status") val status: String,
@SerializedName("statusName") val statusName: String,
@SerializedName("recipientAddressRegisteredAt") val recipientAddressRegisteredAt: String
)
@Keep
data class GiftCancelResponse(
@SerializedName("applicationNo") val applicationNo: String,
@@ -27,6 +27,13 @@ class GiftRepository(private val api: GiftApi) {
authHeader = token
)
fun registerRecipientAddress(applicationNo: String, request: GiftRecipientAddressRequest, token: String) =
api.registerRecipientAddress(
applicationNo = applicationNo,
request = request,
authHeader = token
)
fun cancelGift(applicationNo: String, token: String) = api.cancelGift(
applicationNo = applicationNo,
authHeader = token
@@ -17,6 +17,8 @@ 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.GiftInboxResponse
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxItemResponse
import kr.co.vividnext.sodalive.v2.gift.data.GiftRecipientAddressRequest
import kr.co.vividnext.sodalive.v2.gift.data.GiftRecipientAddressResponse
import kr.co.vividnext.sodalive.v2.gift.data.GiftRepository
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingRequest
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingResponse
@@ -237,6 +239,12 @@ internal class InboxFakeApi : GiftApi {
authHeader: String
): Single<ApiResponse<GiftTrackingResponse>> = Single.error(UnsupportedOperationException())
override fun registerRecipientAddress(
applicationNo: String,
request: GiftRecipientAddressRequest,
authHeader: String
): Single<ApiResponse<GiftRecipientAddressResponse>> = Single.error(UnsupportedOperationException())
override fun cancelGift(applicationNo: String, authHeader: String): Single<ApiResponse<GiftCancelResponse>> =
Single.error(UnsupportedOperationException())
}
@@ -19,6 +19,8 @@ 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.GiftRecipientAddressRequest
import kr.co.vividnext.sodalive.v2.gift.data.GiftRecipientAddressResponse
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
@@ -186,6 +188,12 @@ class GiftSendRequestViewModelTest {
authHeader: String
): Single<ApiResponse<GiftTrackingResponse>> = Single.error(UnsupportedOperationException())
override fun registerRecipientAddress(
applicationNo: String,
request: GiftRecipientAddressRequest,
authHeader: String
): Single<ApiResponse<GiftRecipientAddressResponse>> = Single.error(UnsupportedOperationException())
override fun cancelGift(
applicationNo: String,
authHeader: String
@@ -8,6 +8,11 @@ import org.junit.Assert.assertNull
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Path
import java.lang.reflect.ParameterizedType
class GiftRepositoryTest {
@@ -97,6 +102,73 @@ class GiftRepositoryTest {
)
}
@Test
fun `수신 주소 request는 계약된 JSON key로만 직렬화된다`() {
val json = Gson().toJson(
GiftRecipientAddressRequest(
recipientName = "가상수신자",
recipientPhoneNumber = "01012345678",
recipientZipCode = "01234",
recipientAddress = "가상시 가상로 1",
recipientAddressDetail = "101호",
recipientTermsAgreed = true,
recipientPrivacyAgreed = false
)
)
assertEquals(
"{\"recipientName\":\"가상수신자\",\"recipientPhoneNumber\":\"01012345678\"," +
"\"recipientZipCode\":\"01234\",\"recipientAddress\":\"가상시 가상로 1\"," +
"\"recipientAddressDetail\":\"101호\",\"recipientTermsAgreed\":true," +
"\"recipientPrivacyAgreed\":false}",
json
)
}
@Test
fun `수신 주소 응답은 신청 번호와 상태 및 등록 시각을 보존한다`() {
val response = Gson().fromJson(
"""
{"applicationNo":"GIFT-ADDRESS-001","status":"ADDRESS_REGISTERED","statusName":"배송지 입력 완료","recipientAddressRegisteredAt":"2026-10-11T23:30:00Z"}
""".trimIndent(),
GiftRecipientAddressResponse::class.java
)
assertEquals(
GiftRecipientAddressResponse(
applicationNo = "GIFT-ADDRESS-001",
status = "ADDRESS_REGISTERED",
statusName = "배송지 입력 완료",
recipientAddressRegisteredAt = "2026-10-11T23:30:00Z"
),
response
)
}
@Test
fun `수신 주소 API는 신청 번호 본문 인증과 응답 계약을 제공한다`() {
val method = GiftApi::class.java.getDeclaredMethod(
"registerRecipientAddress",
String::class.java,
GiftRecipientAddressRequest::class.java,
String::class.java
)
assertEquals(
"/api/v2/gifts/{applicationNo}/recipient-address",
requireNotNull(method.getAnnotation(POST::class.java)).value
)
assertEquals("applicationNo", method.parameterAnnotations[0].filterIsInstance<Path>().single().value)
assertTrue(method.parameterAnnotations[1].any { it is Body })
assertEquals("Authorization", method.parameterAnnotations[2].filterIsInstance<Header>().single().value)
val singleType = method.genericReturnType as ParameterizedType
assertEquals(Single::class.java, singleType.rawType)
val responseType = singleType.actualTypeArguments.single() as ParameterizedType
assertEquals(ApiResponse::class.java, responseType.rawType)
assertEquals(GiftRecipientAddressResponse::class.java, responseType.actualTypeArguments.single())
}
@Test
fun `cancel response는 priceCan과 canceledAt을 보존한다`() {
val response = Gson().fromJson(
@@ -138,6 +210,28 @@ class GiftRepositoryTest {
assertEquals("Bearer tracking-token", api.trackingCall?.authHeader)
}
@Test
fun `수신 주소 repository는 신청번호 요청 본문 인증을 변경 없이 전달한다`() {
val api = RepositoryFakeGiftApi()
val request = GiftRecipientAddressRequest(
"가상수신자",
"01012345678",
"01234",
"가상시 가상로 1",
"101호",
true,
true
)
GiftRepository(api).registerRecipientAddress("GIFT-ADDRESS-001", request, "Bearer address-token")
.test()
.assertError(UnsupportedOperationException::class.java)
assertEquals("GIFT-ADDRESS-001", api.recipientAddressCall?.applicationNo)
assertSame(request, api.recipientAddressCall?.request)
assertEquals("Bearer address-token", api.recipientAddressCall?.authHeader)
}
@Test
fun `취소 repository는 신청번호와 인증을 변경 없이 전달한다`() {
val api = RepositoryFakeGiftApi()
@@ -161,9 +255,16 @@ private data class TrackingCall(
val authHeader: String
)
private data class RecipientAddressCall(
val applicationNo: String,
val request: GiftRecipientAddressRequest,
val authHeader: String
)
private class RepositoryFakeGiftApi : GiftApi {
var detailCall: DetailCall? = null
var trackingCall: TrackingCall? = null
var recipientAddressCall: RecipientAddressCall? = null
var cancelCall: DetailCall? = null
override fun getGiftInbox(
@@ -196,6 +297,15 @@ private class RepositoryFakeGiftApi : GiftApi {
return Single.error(UnsupportedOperationException())
}
override fun registerRecipientAddress(
applicationNo: String,
request: GiftRecipientAddressRequest,
authHeader: String
): Single<ApiResponse<GiftRecipientAddressResponse>> {
recipientAddressCall = RecipientAddressCall(applicationNo, request, authHeader)
return Single.error(UnsupportedOperationException())
}
override fun cancelGift(
applicationNo: String,
authHeader: String