feat(gift): 선물 신청 상태를 추가한다
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
data class GiftSendEntry(
|
||||||
|
val creatorMemberId: Long,
|
||||||
|
val creatorNickname: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftSizeUiModel(
|
||||||
|
val id: String,
|
||||||
|
val title: String,
|
||||||
|
val description: String,
|
||||||
|
val pointText: String,
|
||||||
|
val selected: Boolean,
|
||||||
|
val salePriceCan: Int = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftCategoryUiModel(
|
||||||
|
val id: Long,
|
||||||
|
val name: String,
|
||||||
|
val requiresDamageWaiver: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftFormOptionsUiModel(
|
||||||
|
val sizes: List<GiftSizeUiModel>,
|
||||||
|
val categories: List<GiftCategoryUiModel>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftSendFormState(
|
||||||
|
val senderName: String,
|
||||||
|
val phoneNumber: String,
|
||||||
|
val zoneCode: String,
|
||||||
|
val address: String,
|
||||||
|
val detailAddress: String,
|
||||||
|
val selectedSizeId: String?,
|
||||||
|
val selectedSizeSalePriceCan: Int? = null,
|
||||||
|
val selectedCategoryId: Long?,
|
||||||
|
val selectedCategoryRequiresDamageWaiver: Boolean = false,
|
||||||
|
val termsAgreed: Boolean,
|
||||||
|
val privacyAgreed: Boolean,
|
||||||
|
val damageLossAgreed: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftSendCtaState(
|
||||||
|
val isEnabled: Boolean,
|
||||||
|
val priceCan: Int? = null,
|
||||||
|
val hasSenderNameError: Boolean = false,
|
||||||
|
val hasPhoneNumberError: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
data class KakaoPostcodeData(
|
||||||
|
val zonecode: String,
|
||||||
|
val userSelectedType: String,
|
||||||
|
val roadAddress: String,
|
||||||
|
val jibunAddress: String,
|
||||||
|
val address: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GiftPostcodeResult(
|
||||||
|
val zoneCode: String,
|
||||||
|
val address: String
|
||||||
|
)
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftCreateRequest
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftFormOptionsResponse
|
||||||
|
|
||||||
|
object GiftSendRequestPresenter {
|
||||||
|
|
||||||
|
fun toValidEntry(creatorMemberId: Long, creatorNickname: String): GiftSendEntry? {
|
||||||
|
if (creatorMemberId <= 0L || creatorNickname.trim().isEmpty()) return null
|
||||||
|
return GiftSendEntry(creatorMemberId, creatorNickname)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun selectDefaultSize(sizes: List<GiftSizeUiModel>): List<GiftSizeUiModel> = sizes.mapIndexed { index, size ->
|
||||||
|
size.copy(selected = index == 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasBorder(size: GiftSizeUiModel): Boolean = size.selected
|
||||||
|
|
||||||
|
fun categoryIdAt(position: Int, categories: List<GiftCategoryUiModel>): Long? {
|
||||||
|
if (position <= 0) return null
|
||||||
|
return categories.getOrNull(position - 1)?.id
|
||||||
|
}
|
||||||
|
|
||||||
|
fun categoryRequiresDamageWaiverAt(position: Int, categories: List<GiftCategoryUiModel>): Boolean {
|
||||||
|
if (position <= 0) return false
|
||||||
|
return categories.getOrNull(position - 1)?.requiresDamageWaiver == true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toOptionsUiModel(response: GiftFormOptionsResponse): GiftFormOptionsUiModel = GiftFormOptionsUiModel(
|
||||||
|
sizes = selectDefaultSize(
|
||||||
|
response.sizes.mapNotNull { size ->
|
||||||
|
val code = size.code ?: return@mapNotNull null
|
||||||
|
GiftSizeUiModel(
|
||||||
|
id = code,
|
||||||
|
title = size.name.orEmpty(),
|
||||||
|
description = if (code == SMALL_SIZE_CODE) SMALL_SIZE_DESCRIPTION else "",
|
||||||
|
pointText = "${size.salePriceCan}캔",
|
||||||
|
selected = false,
|
||||||
|
salePriceCan = size.salePriceCan
|
||||||
|
)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
categories = response.categories.mapNotNull { category ->
|
||||||
|
val id = category.id ?: return@mapNotNull null
|
||||||
|
GiftCategoryUiModel(
|
||||||
|
id = id,
|
||||||
|
name = category.name,
|
||||||
|
requiresDamageWaiver = category.requiresDamageWaiver
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
fun isValidSenderName(senderName: String): Boolean = SENDER_NAME_REGEX.matches(senderName.trim())
|
||||||
|
|
||||||
|
fun isValidPhoneNumber(phoneNumber: String): Boolean = PHONE_NUMBER_REGEX.matches(phoneNumber.trim())
|
||||||
|
|
||||||
|
fun ctaState(formState: GiftSendFormState): GiftSendCtaState {
|
||||||
|
val hasSenderNameError = formState.senderName.trim().isNotEmpty() && !isValidSenderName(formState.senderName)
|
||||||
|
val hasPhoneNumberError = formState.phoneNumber.trim().isNotEmpty() && !isValidPhoneNumber(formState.phoneNumber)
|
||||||
|
val isEnabled = listOf(
|
||||||
|
formState.senderName,
|
||||||
|
formState.phoneNumber,
|
||||||
|
formState.zoneCode,
|
||||||
|
formState.address,
|
||||||
|
formState.detailAddress
|
||||||
|
).all { it.trim().isNotEmpty() } &&
|
||||||
|
formState.selectedSizeId?.trim()?.isNotEmpty() == true &&
|
||||||
|
formState.selectedSizeSalePriceCan != null &&
|
||||||
|
formState.selectedCategoryId != null &&
|
||||||
|
formState.termsAgreed &&
|
||||||
|
formState.privacyAgreed &&
|
||||||
|
(!formState.selectedCategoryRequiresDamageWaiver || formState.damageLossAgreed) &&
|
||||||
|
!hasSenderNameError &&
|
||||||
|
!hasPhoneNumberError
|
||||||
|
return GiftSendCtaState(
|
||||||
|
isEnabled = isEnabled,
|
||||||
|
priceCan = formState.selectedSizeSalePriceCan?.takeIf { isEnabled },
|
||||||
|
hasSenderNameError = hasSenderNameError,
|
||||||
|
hasPhoneNumberError = hasPhoneNumberError
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toCreateRequest(entry: GiftSendEntry, formState: GiftSendFormState): GiftCreateRequest = GiftCreateRequest(
|
||||||
|
recipientMemberId = entry.creatorMemberId,
|
||||||
|
senderName = formState.senderName.trim(),
|
||||||
|
senderPhoneNumber = formState.phoneNumber.trim(),
|
||||||
|
senderZipCode = formState.zoneCode.trim(),
|
||||||
|
senderAddress = formState.address.trim(),
|
||||||
|
senderAddressDetail = formState.detailAddress.trim(),
|
||||||
|
sizeCode = requireNotNull(formState.selectedSizeId),
|
||||||
|
categoryId = requireNotNull(formState.selectedCategoryId),
|
||||||
|
senderTermsAgreed = formState.termsAgreed,
|
||||||
|
senderPrivacyAgreed = formState.privacyAgreed,
|
||||||
|
damageWaiverAgreed = formState.selectedCategoryRequiresDamageWaiver && formState.damageLossAgreed
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toPostcodeResult(data: KakaoPostcodeData): GiftPostcodeResult = GiftPostcodeResult(
|
||||||
|
zoneCode = data.zonecode,
|
||||||
|
address = when (data.userSelectedType) {
|
||||||
|
KAKAO_ROAD_ADDRESS_TYPE -> data.roadAddress.ifBlank { data.address }
|
||||||
|
KAKAO_JIBUN_ADDRESS_TYPE -> data.jibunAddress.ifBlank { data.address }
|
||||||
|
else -> data.address
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
private const val SMALL_SIZE_CODE = "SMALL"
|
||||||
|
private const val SMALL_SIZE_DESCRIPTION = "세 변의 합 100cm 이하 · 5kg 이하"
|
||||||
|
private const val KAKAO_ROAD_ADDRESS_TYPE = "R"
|
||||||
|
private const val KAKAO_JIBUN_ADDRESS_TYPE = "J"
|
||||||
|
private val SENDER_NAME_REGEX = Regex("^[가-힣A-Za-z0-9]+$")
|
||||||
|
private val PHONE_NUMBER_REGEX = Regex("^\\d{11}$")
|
||||||
|
}
|
||||||
@@ -0,0 +1,377 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
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.GiftFormOptionsResponse
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftSizeResponse
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class GiftSendRequestPresenterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `선물 사이즈 목록이 비어 있으면 빈 목록을 유지한다`() {
|
||||||
|
assertEquals(emptyList<GiftSizeUiModel>(), GiftSendRequestPresenter.selectDefaultSize(emptyList()))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `선물 사이즈 목록이 있으면 첫 항목만 선택한다`() {
|
||||||
|
val sizes = listOf(
|
||||||
|
size(id = "small", selected = false),
|
||||||
|
size(id = "large", selected = true)
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
size(id = "small", selected = true),
|
||||||
|
size(id = "large", selected = false)
|
||||||
|
),
|
||||||
|
GiftSendRequestPresenter.selectDefaultSize(sizes)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `선물 사이즈 border 정책은 선택 상태를 따른다`() {
|
||||||
|
assertTrue(GiftSendRequestPresenter.hasBorder(size(selected = true)))
|
||||||
|
assertFalse(GiftSendRequestPresenter.hasBorder(size(selected = false)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Spinner의 0번 sentinel은 null이고 실제 위치는 카테고리 ID를 반환한다`() {
|
||||||
|
val categories = listOf(
|
||||||
|
GiftCategoryUiModel(id = 10L, name = "음식"),
|
||||||
|
GiftCategoryUiModel(id = 20L, name = "도서")
|
||||||
|
)
|
||||||
|
|
||||||
|
assertNull(GiftSendRequestPresenter.categoryIdAt(position = 0, categories = categories))
|
||||||
|
assertEquals(10L, GiftSendRequestPresenter.categoryIdAt(position = 1, categories = categories))
|
||||||
|
assertEquals(20L, GiftSendRequestPresenter.categoryIdAt(position = 2, categories = categories))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `필수값이 모두 비어 있으면 CTA가 비활성이다`() {
|
||||||
|
assertFalse(GiftSendRequestPresenter.ctaState(emptyForm()).isEnabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `필수 입력과 세 가지 동의가 모두 완료되면 CTA가 활성이다`() {
|
||||||
|
assertTrue(GiftSendRequestPresenter.ctaState(completeForm()).isEnabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `필수 입력과 세 가지 동의가 모두 완료되면 선택 사이즈 가격을 CTA 상태로 반환한다`() {
|
||||||
|
val state = GiftSendRequestPresenter.ctaState(completeForm().copy(selectedSizeSalePriceCan = 80))
|
||||||
|
|
||||||
|
assertTrue(state.isEnabled)
|
||||||
|
assertEquals(80, state.priceCan)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `CTA가 비활성이면 선택 사이즈 가격을 표시하지 않는다`() {
|
||||||
|
val state = GiftSendRequestPresenter.ctaState(completeForm().copy(senderName = "", selectedSizeSalePriceCan = 80))
|
||||||
|
|
||||||
|
assertFalse(state.isEnabled)
|
||||||
|
assertNull(state.priceCan)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `이름은 한글 영문 숫자만 유효하다`() {
|
||||||
|
assertTrue(GiftSendRequestPresenter.isValidSenderName("홍길동abcABC123"))
|
||||||
|
assertFalse(GiftSendRequestPresenter.isValidSenderName("홍길동!"))
|
||||||
|
assertFalse(GiftSendRequestPresenter.isValidSenderName("홍길동 민수"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `휴대폰 번호는 숫자 11자리만 유효하다`() {
|
||||||
|
assertTrue(GiftSendRequestPresenter.isValidPhoneNumber("01012345678"))
|
||||||
|
assertFalse(GiftSendRequestPresenter.isValidPhoneNumber("0101234567"))
|
||||||
|
assertFalse(GiftSendRequestPresenter.isValidPhoneNumber("010123456789"))
|
||||||
|
assertFalse(GiftSendRequestPresenter.isValidPhoneNumber("010-1234-5678"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `이름이나 휴대폰 번호가 유효하지 않으면 에러 상태와 CTA 비활성을 반환한다`() {
|
||||||
|
val invalidName = GiftSendRequestPresenter.ctaState(completeForm().copy(senderName = "홍길동!"))
|
||||||
|
val invalidPhone = GiftSendRequestPresenter.ctaState(completeForm().copy(phoneNumber = "0101234567"))
|
||||||
|
|
||||||
|
assertTrue(invalidName.hasSenderNameError)
|
||||||
|
assertFalse(invalidName.isEnabled)
|
||||||
|
assertTrue(invalidPhone.hasPhoneNumberError)
|
||||||
|
assertFalse(invalidPhone.isEnabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `이름과 휴대폰 번호가 정상 입력이면 에러 상태를 반환하지 않는다`() {
|
||||||
|
val state = GiftSendRequestPresenter.ctaState(completeForm())
|
||||||
|
|
||||||
|
assertFalse(state.hasSenderNameError)
|
||||||
|
assertFalse(state.hasPhoneNumberError)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `필수 텍스트가 공백이면 CTA가 비활성이다`() {
|
||||||
|
val forms = listOf(
|
||||||
|
completeForm().copy(senderName = " "),
|
||||||
|
completeForm().copy(phoneNumber = "\t"),
|
||||||
|
completeForm().copy(zoneCode = " "),
|
||||||
|
completeForm().copy(address = "\n"),
|
||||||
|
completeForm().copy(detailAddress = " \t ")
|
||||||
|
)
|
||||||
|
|
||||||
|
forms.forEach { form ->
|
||||||
|
assertFalse(GiftSendRequestPresenter.ctaState(form).isEnabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `각 필수값이 하나씩 빠지면 CTA가 비활성이다`() {
|
||||||
|
val forms = listOf(
|
||||||
|
completeForm().copy(senderName = ""),
|
||||||
|
completeForm().copy(phoneNumber = ""),
|
||||||
|
completeForm().copy(zoneCode = ""),
|
||||||
|
completeForm().copy(address = ""),
|
||||||
|
completeForm().copy(detailAddress = ""),
|
||||||
|
completeForm().copy(selectedSizeId = null),
|
||||||
|
completeForm().copy(selectedSizeSalePriceCan = null),
|
||||||
|
completeForm().copy(selectedCategoryId = null)
|
||||||
|
)
|
||||||
|
|
||||||
|
forms.forEach { form ->
|
||||||
|
assertFalse(GiftSendRequestPresenter.ctaState(form).isEnabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `세 가지 동의가 각각 해제되면 CTA가 비활성이다`() {
|
||||||
|
val forms = listOf(
|
||||||
|
completeForm().copy(termsAgreed = false),
|
||||||
|
completeForm().copy(privacyAgreed = false),
|
||||||
|
completeForm().copy(damageLossAgreed = false)
|
||||||
|
)
|
||||||
|
|
||||||
|
forms.forEach { form ->
|
||||||
|
assertFalse(GiftSendRequestPresenter.ctaState(form).isEnabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `서버 옵션은 첫 사이즈 기본 선택과 SMALL 설명 및 캔 가격으로 변환된다`() {
|
||||||
|
val options = GiftSendRequestPresenter.toOptionsUiModel(
|
||||||
|
GiftFormOptionsResponse(
|
||||||
|
sizes = listOf(
|
||||||
|
GiftSizeResponse(code = "SMALL", name = "소형", salePriceCan = 100),
|
||||||
|
GiftSizeResponse(code = "MEDIUM", name = "중형", salePriceCan = 300)
|
||||||
|
),
|
||||||
|
categories = emptyList()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
GiftSizeUiModel(
|
||||||
|
id = "SMALL",
|
||||||
|
title = "소형",
|
||||||
|
description = "세 변의 합 100cm 이하 · 5kg 이하",
|
||||||
|
pointText = "100캔",
|
||||||
|
selected = true,
|
||||||
|
salePriceCan = 100
|
||||||
|
),
|
||||||
|
GiftSizeUiModel(
|
||||||
|
id = "MEDIUM",
|
||||||
|
title = "중형",
|
||||||
|
description = "",
|
||||||
|
pointText = "300캔",
|
||||||
|
selected = false,
|
||||||
|
salePriceCan = 300
|
||||||
|
)
|
||||||
|
),
|
||||||
|
options.sizes
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `서버 size code가 null이면 제출 불가능한 옵션이므로 제외한다`() {
|
||||||
|
val options = GiftSendRequestPresenter.toOptionsUiModel(
|
||||||
|
GiftFormOptionsResponse(
|
||||||
|
sizes = listOf(
|
||||||
|
GiftSizeResponse(code = null, name = "코드 없음", salePriceCan = 100),
|
||||||
|
GiftSizeResponse(code = "SMALL", name = "소형", salePriceCan = 200)
|
||||||
|
),
|
||||||
|
categories = emptyList()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(listOf("SMALL"), options.sizes.map { it.id })
|
||||||
|
assertTrue(options.sizes.single().selected)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `실제 form-options 응답 JSON은 size와 category UI 모델로 변환된다`() {
|
||||||
|
val response = Gson().fromJson(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"sizes": [
|
||||||
|
{
|
||||||
|
"sizeCode": "SMALL",
|
||||||
|
"name": "소형",
|
||||||
|
"basePriceCan": 100,
|
||||||
|
"salePriceCan": 80
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"categories": [
|
||||||
|
{
|
||||||
|
"categoryId": 1,
|
||||||
|
"name": "아크릴",
|
||||||
|
"requiresDamageWaiver": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent(),
|
||||||
|
GiftFormOptionsResponse::class.java
|
||||||
|
)
|
||||||
|
|
||||||
|
val options = GiftSendRequestPresenter.toOptionsUiModel(response)
|
||||||
|
|
||||||
|
assertEquals(listOf("SMALL"), options.sizes.map { it.id })
|
||||||
|
assertEquals(listOf("80캔"), options.sizes.map { it.pointText })
|
||||||
|
assertEquals(listOf(1L), options.categories.map { it.id })
|
||||||
|
assertTrue(options.categories.single().requiresDamageWaiver)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `카테고리 면책 조건은 UI 모델과 CTA 필수 조건에 반영된다`() {
|
||||||
|
val options = GiftSendRequestPresenter.toOptionsUiModel(
|
||||||
|
GiftFormOptionsResponse(
|
||||||
|
sizes = emptyList(),
|
||||||
|
categories = listOf(
|
||||||
|
GiftCategoryResponse(id = 10L, name = "일반", requiresDamageWaiver = false),
|
||||||
|
GiftCategoryResponse(id = 20L, name = "파손위험", requiresDamageWaiver = true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
GiftCategoryUiModel(id = 10L, name = "일반", requiresDamageWaiver = false),
|
||||||
|
GiftCategoryUiModel(id = 20L, name = "파손위험", requiresDamageWaiver = true)
|
||||||
|
),
|
||||||
|
options.categories
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
GiftSendRequestPresenter.ctaState(
|
||||||
|
completeForm().copy(
|
||||||
|
selectedCategoryId = 10L,
|
||||||
|
selectedCategoryRequiresDamageWaiver = false,
|
||||||
|
damageLossAgreed = false
|
||||||
|
)
|
||||||
|
).isEnabled
|
||||||
|
)
|
||||||
|
assertFalse(
|
||||||
|
GiftSendRequestPresenter.ctaState(
|
||||||
|
completeForm().copy(
|
||||||
|
selectedCategoryId = 20L,
|
||||||
|
selectedCategoryRequiresDamageWaiver = true,
|
||||||
|
damageLossAgreed = false
|
||||||
|
)
|
||||||
|
).isEnabled
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `폼 상태는 선물 신청 request body로 변환된다`() {
|
||||||
|
val entry = GiftSendEntry(creatorMemberId = 99L, creatorNickname = "크리에이터")
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
GiftCreateRequest(
|
||||||
|
recipientMemberId = 99L,
|
||||||
|
senderName = "홍길동",
|
||||||
|
senderPhoneNumber = "01000000000",
|
||||||
|
senderZipCode = "00000",
|
||||||
|
senderAddress = "기본 주소",
|
||||||
|
senderAddressDetail = "상세 주소",
|
||||||
|
sizeCode = "small",
|
||||||
|
categoryId = 10L,
|
||||||
|
senderTermsAgreed = true,
|
||||||
|
senderPrivacyAgreed = true,
|
||||||
|
damageWaiverAgreed = false
|
||||||
|
),
|
||||||
|
GiftSendRequestPresenter.toCreateRequest(
|
||||||
|
entry = entry,
|
||||||
|
formState = completeForm().copy(
|
||||||
|
selectedCategoryId = 10L,
|
||||||
|
selectedCategoryRequiresDamageWaiver = false,
|
||||||
|
damageLossAgreed = false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Kakao 우편번호 결과는 사용자가 선택한 주소 타입에 맞춰 변환된다`() {
|
||||||
|
assertEquals(
|
||||||
|
GiftPostcodeResult(zoneCode = "12345", address = "서울 도로명 1"),
|
||||||
|
GiftSendRequestPresenter.toPostcodeResult(
|
||||||
|
KakaoPostcodeData(
|
||||||
|
zonecode = "12345",
|
||||||
|
userSelectedType = "R",
|
||||||
|
roadAddress = "서울 도로명 1",
|
||||||
|
jibunAddress = "서울 지번 2",
|
||||||
|
address = "서울 기본 3"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
GiftPostcodeResult(zoneCode = "54321", address = "서울 지번 2"),
|
||||||
|
GiftSendRequestPresenter.toPostcodeResult(
|
||||||
|
KakaoPostcodeData(
|
||||||
|
zonecode = "54321",
|
||||||
|
userSelectedType = "J",
|
||||||
|
roadAddress = "서울 도로명 1",
|
||||||
|
jibunAddress = "서울 지번 2",
|
||||||
|
address = "서울 기본 3"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun size(id: String = "small", selected: Boolean): GiftSizeUiModel = GiftSizeUiModel(
|
||||||
|
id = id,
|
||||||
|
title = "선물 사이즈 $id",
|
||||||
|
description = "설명",
|
||||||
|
pointText = "100P",
|
||||||
|
selected = selected
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun emptyForm(): GiftSendFormState = GiftSendFormState(
|
||||||
|
senderName = "",
|
||||||
|
phoneNumber = "",
|
||||||
|
zoneCode = "",
|
||||||
|
address = "",
|
||||||
|
detailAddress = "",
|
||||||
|
selectedSizeId = null,
|
||||||
|
selectedCategoryId = null,
|
||||||
|
selectedCategoryRequiresDamageWaiver = false,
|
||||||
|
termsAgreed = false,
|
||||||
|
privacyAgreed = false,
|
||||||
|
damageLossAgreed = false
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun completeForm(): GiftSendFormState = GiftSendFormState(
|
||||||
|
senderName = "홍길동",
|
||||||
|
phoneNumber = "01000000000",
|
||||||
|
zoneCode = "00000",
|
||||||
|
address = "기본 주소",
|
||||||
|
detailAddress = "상세 주소",
|
||||||
|
selectedSizeId = "small",
|
||||||
|
selectedSizeSalePriceCan = 100,
|
||||||
|
selectedCategoryId = 10L,
|
||||||
|
selectedCategoryRequiresDamageWaiver = true,
|
||||||
|
termsAgreed = true,
|
||||||
|
privacyAgreed = true,
|
||||||
|
damageLossAgreed = true
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user