Updated on 2026-08-14
This commit is contained in:
parent
5c293e71ec
commit
6caeea3576
22 changed files with 243 additions and 135 deletions
|
|
@ -2,16 +2,29 @@ package com.tangem.data.pay.converter
|
|||
|
||||
import com.tangem.datasource.api.pay.models.response.CustomerMeResponse
|
||||
import com.tangem.domain.models.account.TangemPayTariffPlan
|
||||
import java.util.Locale
|
||||
|
||||
internal object TangemPayTariffPlanConverter {
|
||||
|
||||
fun convert(value: CustomerMeResponse.TariffPlan?): TangemPayTariffPlan? {
|
||||
val id = value?.id ?: return null
|
||||
val name = value.name ?: return null
|
||||
val programName = value.programName ?: return null
|
||||
|
||||
// We cannot base our logic on knowledge what exact tier type is it.
|
||||
// Use it only as identifier to get data from other responses
|
||||
val tierId = value.type ?: return null
|
||||
|
||||
// Basic tier is a default tier. We can base some features on it.
|
||||
// Other tiers are adjusted from admin panel. It is not guaranteed to have it in future
|
||||
val isBasicTier = tierId.uppercase(Locale.US) == "BASIC"
|
||||
|
||||
return TangemPayTariffPlan(
|
||||
id = id,
|
||||
type = TangemPayTariffPlan.Type.fromString(value.type),
|
||||
tierId = tierId,
|
||||
isBasicTier = isBasicTier,
|
||||
name = name,
|
||||
programName = programName,
|
||||
descriptionItems = value.descriptionItems.orEmpty().mapNotNull(::convertDescriptionItem),
|
||||
images = value.images.orEmpty().mapNotNull(::convertImage),
|
||||
fees = value.fees.orEmpty().mapNotNull(::convertFee),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,30 @@ internal class TangemPayTariffPlanConverterTest {
|
|||
assertThat(TangemPayTariffPlanConverter.convert(value)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN missing type WHEN convert THEN returns null`() {
|
||||
val value = tariffPlan(type = null)
|
||||
|
||||
assertThat(TangemPayTariffPlanConverter.convert(value)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN missing programName WHEN convert THEN returns null`() {
|
||||
val value = tariffPlan(programName = null)
|
||||
|
||||
assertThat(TangemPayTariffPlanConverter.convert(value)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN basic tier in mixed case WHEN convert THEN isBasicTier is true`() {
|
||||
val value = tariffPlan(type = "Basic")
|
||||
|
||||
val result = TangemPayTariffPlanConverter.convert(value)
|
||||
|
||||
assertThat(result?.tierId).isEqualTo("Basic")
|
||||
assertThat(result?.isBasicTier).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN full valid plan WHEN convert THEN maps all fields`() {
|
||||
// GIVEN
|
||||
|
|
@ -58,8 +82,10 @@ internal class TangemPayTariffPlanConverterTest {
|
|||
// THEN
|
||||
val expected = TangemPayTariffPlan(
|
||||
id = PLAN_ID,
|
||||
type = TangemPayTariffPlan.Type.PLUS,
|
||||
tierId = "PLUS",
|
||||
isBasicTier = false,
|
||||
name = PLAN_NAME,
|
||||
programName = PROGRAM_NAME,
|
||||
descriptionItems = listOf(
|
||||
TangemPayTariffPlan.DescriptionItem(
|
||||
section = TangemPayTariffPlan.Section.PLAN_RELATED,
|
||||
|
|
@ -110,8 +136,10 @@ internal class TangemPayTariffPlanConverterTest {
|
|||
// THEN
|
||||
val expected = TangemPayTariffPlan(
|
||||
id = PLAN_ID,
|
||||
type = TangemPayTariffPlan.Type.UNKNOWN,
|
||||
tierId = "SOMETHING_NEW",
|
||||
isBasicTier = false,
|
||||
name = PLAN_NAME,
|
||||
programName = PROGRAM_NAME,
|
||||
descriptionItems = listOf(
|
||||
TangemPayTariffPlan.DescriptionItem(
|
||||
section = TangemPayTariffPlan.Section.UNKNOWN,
|
||||
|
|
@ -168,6 +196,7 @@ internal class TangemPayTariffPlanConverterTest {
|
|||
id: String? = PLAN_ID,
|
||||
type: String? = "BASIC",
|
||||
name: String? = PLAN_NAME,
|
||||
programName: String? = PROGRAM_NAME,
|
||||
descriptionItems: List<CustomerMeResponse.DescriptionItem>? = null,
|
||||
images: List<CustomerMeResponse.Image>? = null,
|
||||
fees: List<CustomerMeResponse.Fee>? = null,
|
||||
|
|
@ -175,6 +204,7 @@ internal class TangemPayTariffPlanConverterTest {
|
|||
id = id,
|
||||
type = type,
|
||||
name = name,
|
||||
programName = programName,
|
||||
descriptionItems = descriptionItems,
|
||||
images = images,
|
||||
fees = fees,
|
||||
|
|
@ -183,5 +213,6 @@ internal class TangemPayTariffPlanConverterTest {
|
|||
private companion object {
|
||||
const val PLAN_ID = "plan-1"
|
||||
const val PLAN_NAME = "Plus"
|
||||
const val PROGRAM_NAME = "program-1"
|
||||
}
|
||||
}
|
||||
|
|
@ -120,8 +120,10 @@ internal class DefaultPaymentAccountStatusFetcherTest {
|
|||
|
||||
private val basicPlan = TangemPayTariffPlan(
|
||||
id = "plan_basic",
|
||||
type = TangemPayTariffPlan.Type.BASIC,
|
||||
tierId = "BASIC",
|
||||
isBasicTier = true,
|
||||
name = "Basic",
|
||||
programName = "program_basic",
|
||||
descriptionItems = emptyList(),
|
||||
images = emptyList(),
|
||||
fees = emptyList(),
|
||||
|
|
|
|||
|
|
@ -91,8 +91,10 @@ internal class DefaultTariffPlanTransitionsRepositoryTest {
|
|||
type = TangemPayTariffPlanTransition.Type.UPGRADE,
|
||||
plan = TangemPayTariffPlan(
|
||||
id = PLAN_ID,
|
||||
type = TangemPayTariffPlan.Type.PLUS,
|
||||
tierId = "PLUS",
|
||||
isBasicTier = false,
|
||||
name = PLAN_NAME,
|
||||
programName = PROGRAM_NAME,
|
||||
descriptionItems = emptyList(),
|
||||
images = emptyList(),
|
||||
fees = emptyList(),
|
||||
|
|
@ -187,6 +189,7 @@ internal class DefaultTariffPlanTransitionsRepositoryTest {
|
|||
id = id,
|
||||
type = "PLUS",
|
||||
name = PLAN_NAME,
|
||||
programName = PROGRAM_NAME,
|
||||
descriptionItems = null,
|
||||
images = null,
|
||||
fees = null,
|
||||
|
|
@ -197,6 +200,7 @@ internal class DefaultTariffPlanTransitionsRepositoryTest {
|
|||
const val AUTH_HEADER = "auth-header"
|
||||
const val PLAN_ID = "plan-plus"
|
||||
const val PLAN_NAME = "Plus"
|
||||
const val PROGRAM_NAME = "program-plus"
|
||||
const val PENDING_PLAN_ID = "plan-basic"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue