diff --git a/app/src/androidTest/kotlin/com/tangem/common/BaseTestCase.kt b/app/src/androidTest/kotlin/com/tangem/common/BaseTestCase.kt index dd3f4dc1e5..fab9e10cfb 100644 --- a/app/src/androidTest/kotlin/com/tangem/common/BaseTestCase.kt +++ b/app/src/androidTest/kotlin/com/tangem/common/BaseTestCase.kt @@ -20,7 +20,6 @@ import com.tangem.common.constants.TestConstants.ALLURE_LABEL_NAME import com.tangem.common.constants.TestConstants.ALLURE_LABEL_VALUE import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT import com.tangem.common.rules.ApiEnvironmentRule -import com.tangem.data.pay.TangemPayMockControl import com.tangem.datasource.api.common.config.managers.ApiConfigsManager import com.tangem.datasource.local.preferences.AppPreferencesStore import com.tangem.datasource.local.preferences.PreferencesKeys @@ -112,9 +111,6 @@ abstract class BaseTestCase : TestCase( additionalBeforeSection: () -> Unit = {}, additionalAfterSection: () -> Unit = {}, ) = before { - // Reset opt-in Tangem Pay mock switches so a previous Tangem Pay test can't leak an active Payment - // account into the next (e.g. generic openMainScreen) test running in the same process. - TangemPayMockControl.reset() Allure.label(ALLURE_LABEL_NAME, ALLURE_LABEL_VALUE) // Setup WireMock redirect for CI with local WireMock instances val wiremockUrl = InstrumentationRegistry.getArguments().getString(WIREMOCK_BASE_URL_ARG) @@ -184,16 +180,6 @@ abstract class BaseTestCase : TestCase( fun waitForIdle() = composeTestRule.waitForIdle() - /** - * Opts the current test's wallet into the Tangem Pay mock so it is treated as an existing customer - * (an active Payment account appears). MUST be called before the wallet is imported, so the first - * payment-account status fetch observes it. Paired with the [TangemPayMockControl] reset in [setupHooks], - * which restores the Payment-free default for every other (e.g. generic openMainScreen) test. - */ - fun markExistingTangemPayCustomer() { - TangemPayMockControl.hasTangemPayInWallet = true - } - /** * Waits until [block] stops throwing (or [timeoutMillis] elapses). Use in scenario (BaseTestCase extension) * code where flakySafely is unavailable; in test bodies prefer flakySafely. diff --git a/app/src/androidTest/kotlin/com/tangem/scenarios/TangemPayScenarios.kt b/app/src/androidTest/kotlin/com/tangem/scenarios/TangemPayScenarios.kt index 691ad65e6e..55c9009c89 100644 --- a/app/src/androidTest/kotlin/com/tangem/scenarios/TangemPayScenarios.kt +++ b/app/src/androidTest/kotlin/com/tangem/scenarios/TangemPayScenarios.kt @@ -12,8 +12,8 @@ import com.tangem.screens.tangempay.* import io.qameta.allure.kotlin.Allure.step fun BaseTestCase.openTangemPay() { - // Opt this wallet into the Tangem Pay mock (existing customer) before importing the wallet. - markExistingTangemPayCustomer() + // Existing customer: callers set the `tangem_pay_eligibility` scenario to PaeraCustomer (in + // additionalBeforeSection, before this runs), which drives the checkCustomerWalletId mock -> Payment account. step("Import hot wallet from Tangem Pay seed phrase (with access code)") { openMainScreenWithExistingHotWallet(SVS_SEED_PHRASE_12, accessCode = TANGEM_PAY_ACCESS_CODE) } diff --git a/app/src/androidTest/kotlin/com/tangem/tests/tangempay/TangemPayOnboardingKycTest.kt b/app/src/androidTest/kotlin/com/tangem/tests/tangempay/TangemPayOnboardingKycTest.kt index 104f63c820..f6f0abc42a 100644 --- a/app/src/androidTest/kotlin/com/tangem/tests/tangempay/TangemPayOnboardingKycTest.kt +++ b/app/src/androidTest/kotlin/com/tangem/tests/tangempay/TangemPayOnboardingKycTest.kt @@ -35,8 +35,6 @@ class TangemPayOnboardingKycTest : BaseTestCase() { val paeraCustomerState = "PaeraCustomer" setupHooks( - // Existing customer: opt into the Tangem Pay mock so the Payment account (tile) appears. - additionalBeforeSection = { markExistingTangemPayCustomer() }, additionalAfterSection = { resetWireMockScenarioState(TANGEM_PAY_ELIGIBILITY_SCENARIO) }, @@ -136,9 +134,6 @@ class TangemPayOnboardingKycTest : BaseTestCase() { val viewStatusText = getResourceString(CoreResR.string.tangempay_kyc_in_progress_notification_button) setupHooks( - // Existing customer: the tile must appear so its KYC-status subtitle can be asserted. - // The KYC status itself comes from the WireMock TANGEM_PAY_KYC_STATUS_SCENARIO via getCustomerInfo. - additionalBeforeSection = { markExistingTangemPayCustomer() }, additionalAfterSection = { resetWireMockScenarioState(TANGEM_PAY_ELIGIBILITY_SCENARIO) resetWireMockScenarioState(TANGEM_PAY_KYC_STATUS_SCENARIO) @@ -192,9 +187,6 @@ class TangemPayOnboardingKycTest : BaseTestCase() { val goToSupportText = getResourceString(CoreResR.string.tangempay_go_to_support) setupHooks( - // Existing customer: the tile must appear so its KYC-status subtitle can be asserted. - // The KYC status itself comes from the WireMock TANGEM_PAY_KYC_STATUS_SCENARIO via getCustomerInfo. - additionalBeforeSection = { markExistingTangemPayCustomer() }, additionalAfterSection = { resetWireMockScenarioState(TANGEM_PAY_ELIGIBILITY_SCENARIO) resetWireMockScenarioState(TANGEM_PAY_KYC_STATUS_SCENARIO) diff --git a/data/visa/src/main/kotlin/com/tangem/data/pay/TangemPayMockControl.kt b/data/visa/src/main/kotlin/com/tangem/data/pay/TangemPayMockControl.kt deleted file mode 100644 index d156530919..0000000000 --- a/data/visa/src/main/kotlin/com/tangem/data/pay/TangemPayMockControl.kt +++ /dev/null @@ -1,30 +0,0 @@ -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 - } -} \ No newline at end of file diff --git a/data/visa/src/mocked/kotlin/com/tangem/data/pay/repository/MockAwareOnboardingRepository.kt b/data/visa/src/mocked/kotlin/com/tangem/data/pay/repository/MockAwareOnboardingRepository.kt index fc71742ea8..504ac2e99a 100644 --- a/data/visa/src/mocked/kotlin/com/tangem/data/pay/repository/MockAwareOnboardingRepository.kt +++ b/data/visa/src/mocked/kotlin/com/tangem/data/pay/repository/MockAwareOnboardingRepository.kt @@ -3,7 +3,6 @@ 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 @@ -22,8 +21,9 @@ import javax.inject.Singleton * 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; + * - [hasTangemPayInWallet] delegates to the real repo, so the "existing customer" gate follows the + * checkCustomerWalletId mock (the `tangem_pay_eligibility` scenario: `Started` → 404/NotPaeraCustomer → + * no Payment account, `PaeraCustomer` → 200 → Payment account); * - [getCustomerInfo] delegates to the real repo (WireMock), so KYC / customer-state scenarios take effect. */ @Singleton @@ -113,14 +113,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 { - if (isMockMode) return TangemPayMockControl.hasTangemPayInWallet.right() - return real.hasTangemPayInWallet(userWalletId) - } + // The "existing Tangem Pay customer" gate (decides whether an active Payment account — and accounts mode — + // appears). Delegates to WireMock's checkCustomerWalletId via the real repo (static token, no signing), so it + // is driven by the `tangem_pay_eligibility` scenario: `Started` (default) → 404/NotPaeraCustomer → no account; + // `PaeraCustomer` → 200 → account. Generic UI tests never set the scenario, so they stay Payment-free. + override suspend fun hasTangemPayInWallet(userWalletId: UserWalletId): Either = + real.hasTangemPayInWallet(userWalletId) override suspend fun checkCustomerEligibility(): List = real.checkCustomerEligibility()