Updated on 2026-08-14
This commit is contained in:
parent
64b094c8e7
commit
1dc70cf918
6 changed files with 130 additions and 71 deletions
|
|
@ -0,0 +1,30 @@
|
|||
package com.tangem.data.pay
|
||||
|
||||
/**
|
||||
* Test-only switch for the mocked Tangem Pay graph.
|
||||
*
|
||||
* Kept in the `main` source set (not `mocked`) on purpose: it is read only by the `mocked`-only
|
||||
* [com.tangem.data.pay.repository.MockAwareOnboardingRepository], but it is also written from `app`
|
||||
* `androidTest` sources, which are shared across build-type variants. Restricting it to the `mocked` source set
|
||||
* would leave it off the classpath of any non-mocked androidTest variant and break their compilation. Being in
|
||||
* `main`, it is unreferenced in production/release (only the mocked repository reads it) and is dropped by R8.
|
||||
*
|
||||
* [hasTangemPayInWallet] gates whether a wallet is treated as an existing Tangem Pay customer. It defaults to
|
||||
* `false` so that the many generic `openMainScreen*` UI tests keep a Payment-account-free wallet (and thus stay
|
||||
* out of accounts mode). Tangem Pay scenarios opt in by flipping it to `true` before the wallet is loaded; the
|
||||
* value is reset to the default at the start of every test in `BaseTestCase.setupHooks`.
|
||||
*
|
||||
* @see com.tangem.data.pay.repository.MockAwareOnboardingRepository
|
||||
*/
|
||||
object TangemPayMockControl {
|
||||
|
||||
private const val DEFAULT_HAS_TANGEM_PAY_IN_WALLET = false
|
||||
|
||||
@Volatile
|
||||
var hasTangemPayInWallet: Boolean = DEFAULT_HAS_TANGEM_PAY_IN_WALLET
|
||||
|
||||
/** Restores every switch to its default. Called between tests to prevent state leaking across the process. */
|
||||
fun reset() {
|
||||
hasTangemPayInWallet = DEFAULT_HAS_TANGEM_PAY_IN_WALLET
|
||||
}
|
||||
}
|
||||
|
|
@ -3,28 +3,28 @@ package com.tangem.data.pay.repository
|
|||
import arrow.core.Either
|
||||
import arrow.core.right
|
||||
import com.tangem.core.error.UniversalError
|
||||
import com.tangem.data.pay.TangemPayMockControl
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.ApiEnvironment
|
||||
import com.tangem.datasource.api.common.config.managers.ApiConfigsManager
|
||||
import com.tangem.domain.models.account.BankCredentials
|
||||
import com.tangem.domain.models.account.PaymentAccountStatusValue
|
||||
import com.tangem.domain.models.kyc.KycStatus
|
||||
import com.tangem.domain.models.pay.TangemPayCard
|
||||
import com.tangem.domain.models.pay.TangemPayCardFrozenState
|
||||
import com.tangem.domain.models.pay.TangemPayEligibilityType
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.pay.model.CustomerInfo
|
||||
import com.tangem.domain.pay.repository.OnboardingRepository
|
||||
import com.tangem.domain.visa.error.VisaApiError
|
||||
import java.math.BigDecimal
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* In MOCK env returns canned onboarding data so the Payment Account shows up as fully loaded on the main
|
||||
* screen (the entry point to the TangemPay details & cashback screens), and skips local-storage / signing
|
||||
* enrollment; remaining server calls go to WireMock.
|
||||
* In MOCK env only skips the local-storage / NFC-signing enrollment steps (order ids, initial data). The
|
||||
* customer-facing state — whether a wallet has Tangem Pay ([hasTangemPayInWallet]), KYC status, ACTIVE /
|
||||
* INACTIVE, balances ([getCustomerInfo]) — is driven by the WireMock test scenario (authenticated with the
|
||||
* synthetic tokens from [com.tangem.data.pay.store.MockAwareTangemPayStorage]) rather than hardcoded:
|
||||
* - [hasTangemPayInWallet] is answered locally via [TangemPayMockControl] (WireMock does not mock the
|
||||
* underlying checkCustomerWalletId endpoint) — default false, opt-in true for Tangem Pay scenarios;
|
||||
* - [getCustomerInfo] delegates to the real repo (WireMock), so KYC / customer-state scenarios take effect.
|
||||
*/
|
||||
@Singleton
|
||||
internal class MockAwareOnboardingRepository @Inject constructor(
|
||||
|
|
@ -55,10 +55,11 @@ internal class MockAwareOnboardingRepository @Inject constructor(
|
|||
real.produceInitialData(userWalletId)
|
||||
}
|
||||
|
||||
override suspend fun getCustomerInfo(userWalletId: UserWalletId): Either<VisaApiError, CustomerInfo> {
|
||||
if (isMockMode) return MOCK_CUSTOMER_INFO.right()
|
||||
return real.getCustomerInfo(userWalletId)
|
||||
}
|
||||
// Delegates to WireMock (via the real repo + synthetic storage tokens) so the customer state — KYC status,
|
||||
// ACTIVE/INACTIVE, balances — follows the test scenario instead of a hardcoded "always active" customer.
|
||||
// Only reached when hasTangemPayInWallet is true, i.e. for wallets opted in via TangemPayMockControl.
|
||||
override suspend fun getCustomerInfo(userWalletId: UserWalletId): Either<VisaApiError, CustomerInfo> =
|
||||
real.getCustomerInfo(userWalletId)
|
||||
|
||||
override suspend fun getBankCredentials(
|
||||
userWalletId: UserWalletId,
|
||||
|
|
@ -111,8 +112,12 @@ internal class MockAwareOnboardingRepository @Inject constructor(
|
|||
real.storeVirtualAccountOrderId(userWalletId, vaOrderId)
|
||||
}
|
||||
|
||||
// This is the gate that decides whether a wallet is treated as an existing Tangem Pay customer (and thus
|
||||
// whether an active Payment account — and accounts mode — appears). WireMock does NOT mock the underlying
|
||||
// checkCustomerWalletId endpoint, so we answer locally: default false (generic UI tests stay Payment-free),
|
||||
// opt-in true via TangemPayMockControl for Tangem Pay scenarios. Never delegate to `real` here.
|
||||
override suspend fun hasTangemPayInWallet(userWalletId: UserWalletId): Either<VisaApiError, Boolean> {
|
||||
if (isMockMode) return true.right()
|
||||
if (isMockMode) return TangemPayMockControl.hasTangemPayInWallet.right()
|
||||
return real.hasTangemPayInWallet(userWalletId)
|
||||
}
|
||||
|
||||
|
|
@ -152,52 +157,5 @@ internal class MockAwareOnboardingRepository @Inject constructor(
|
|||
private companion object {
|
||||
const val MOCK_ORDER_ID = "mock-order-id"
|
||||
const val MOCK_VA_ORDER_ID = "mock-va-order-id"
|
||||
|
||||
const val MOCK_CUSTOMER_ID = "mock-customer-id"
|
||||
const val MOCK_CARD_ID = "mock-card-id"
|
||||
const val MOCK_PRODUCT_INSTANCE_ID = "mock-product-instance-id"
|
||||
const val MOCK_CUSTOMER_WALLET_ADDRESS = "0x0000000000000000000000000000000000000002"
|
||||
const val MOCK_TOKEN_CONTRACT_ADDRESS = "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359"
|
||||
const val MOCK_POLYGON_CHAIN_ID = 137L
|
||||
|
||||
val MOCK_CUSTOMER_INFO = CustomerInfo(
|
||||
customerId = MOCK_CUSTOMER_ID,
|
||||
productInstances = listOf(
|
||||
CustomerInfo.ProductInstance(
|
||||
id = MOCK_PRODUCT_INSTANCE_ID,
|
||||
cardId = MOCK_CARD_ID,
|
||||
frozenState = TangemPayCardFrozenState.Unfrozen,
|
||||
displayName = null,
|
||||
actualCardLimit = null,
|
||||
adminCardLimit = null,
|
||||
status = CustomerInfo.ProductInstance.Status.ACTIVE,
|
||||
specificationDataType = CustomerInfo.ProductInstance.SpecificationDataType.CARD,
|
||||
),
|
||||
),
|
||||
cards = listOf(
|
||||
CustomerInfo.CardInfo(
|
||||
cardId = MOCK_CARD_ID,
|
||||
cardStatus = TangemPayCard.Status.ACTIVE,
|
||||
lastFourDigits = "4242",
|
||||
isPinSet = true,
|
||||
images = emptyList(),
|
||||
),
|
||||
),
|
||||
kycStatus = KycStatus.APPROVED,
|
||||
state = CustomerInfo.State.ACTIVE,
|
||||
fiatBalance = PaymentAccountStatusValue.FiatBalance(
|
||||
availableBalance = BigDecimal("123.45"),
|
||||
currency = "USD",
|
||||
),
|
||||
cryptoBalance = PaymentAccountStatusValue.CryptoBalance(
|
||||
id = "usd-coin",
|
||||
chainId = MOCK_POLYGON_CHAIN_ID,
|
||||
depositAddress = MOCK_CUSTOMER_WALLET_ADDRESS,
|
||||
tokenContractAddress = MOCK_TOKEN_CONTRACT_ADDRESS,
|
||||
balance = BigDecimal("123.45"),
|
||||
),
|
||||
availableForWithdrawal = BigDecimal("123.45"),
|
||||
tariffPlan = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue