Skip to content

Commit

Permalink
Add test rule to force native bank flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Feb 20, 2025
1 parent 064778c commit b82f10c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.stripe.android.lpm
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.isEnabled
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.model.PaymentMethod
Expand All @@ -21,6 +22,8 @@ import com.stripe.android.test.core.AuthorizeAction
import com.stripe.android.test.core.DEFAULT_UI_TIMEOUT
import com.stripe.android.test.core.TestParameters
import com.stripe.android.test.core.ui.ComposeButton
import com.stripe.android.utils.ForceNativeBankFlowTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -41,6 +44,11 @@ internal class TestInstantDebits : BasePlaygroundTest() {
).joinToString(",")
}

@get:Rule
val forceNativeBankFlowTestRule = ForceNativeBankFlowTestRule(
context = ApplicationProvider.getApplicationContext()
)

@Test
fun testInstantDebitsSuccess() {
val params = testParameters.copyPlaygroundSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.stripe.android.lpm
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.isEnabled
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.example.playground.settings.AutomaticPaymentMethodsSettingsDefinition
Expand All @@ -20,6 +21,8 @@ import com.stripe.android.test.core.AuthorizeAction
import com.stripe.android.test.core.DEFAULT_UI_TIMEOUT
import com.stripe.android.test.core.TestParameters
import com.stripe.android.test.core.ui.ComposeButton
import com.stripe.android.utils.ForceNativeBankFlowTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -37,6 +40,11 @@ internal class TestLinkCardBrand : BasePlaygroundTest() {
settings[SupportedPaymentMethodsSettingsDefinition] = "card"
}

@get:Rule
val forceNativeBankFlowTestRule = ForceNativeBankFlowTestRule(
context = ApplicationProvider.getApplicationContext()
)

@Test
fun testLinkCardBrandSuccess() {
val params = testParameters.copyPlaygroundSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.stripe.android.lpm
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.isEnabled
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.example.playground.settings.Country
Expand All @@ -19,6 +20,8 @@ import com.stripe.android.test.core.DEFAULT_UI_TIMEOUT
import com.stripe.android.test.core.TestParameters
import com.stripe.android.test.core.ui.ComposeButton
import com.stripe.android.test.core.ui.PaymentSelection
import com.stripe.android.utils.ForceNativeBankFlowTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -33,6 +36,11 @@ internal class TestUSBankAccount : BasePlaygroundTest() {
settings[DelayedPaymentMethodsSettingsDefinition] = true
}

@get:Rule
val forceNativeBankFlowTestRule = ForceNativeBankFlowTestRule(
context = ApplicationProvider.getApplicationContext()
)

@Test
fun testUSBankAccountSuccess() {
testDriver.confirmUSBankAccount(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stripe.android.lpm

import androidx.test.core.app.ApplicationProvider
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition
Expand All @@ -8,6 +9,8 @@ import com.stripe.android.paymentsheet.example.playground.settings.CustomerSheet
import com.stripe.android.paymentsheet.example.playground.settings.PaymentMethodMode
import com.stripe.android.test.core.AuthorizeAction
import com.stripe.android.test.core.TestParameters
import com.stripe.android.utils.ForceNativeBankFlowTestRule
import org.junit.Rule
import org.junit.Test

internal class TestUsBankAccountInCustomerSheet : BasePlaygroundTest() {
Expand All @@ -20,6 +23,11 @@ internal class TestUsBankAccountInCustomerSheet : BasePlaygroundTest() {
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.SetupIntent
}

@get:Rule
val forceNativeBankFlowTestRule = ForceNativeBankFlowTestRule(
context = ApplicationProvider.getApplicationContext()
)

@Test
fun testUSBankAccount() {
testDriver.saveUsBankAccountInCustomerSheet(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.stripe.android.utils

import android.content.Context
import androidx.core.content.edit
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import org.junit.rules.TestWatcher
import org.junit.runner.Description

class ForceNativeBankFlowTestRule(
private val context: Context,
) : TestWatcher() {

override fun starting(description: Description) {
super.starting(description)
forceNativeBankAuth(true)
}

override fun finished(description: Description) {
forceNativeBankAuth(false)
super.finished(description)
}

private fun forceNativeBankAuth(force: Boolean) {
val sharedPrefs = context.getSharedPreferences(
"FINANCIAL_CONNECTIONS_DEBUG",
Context.MODE_PRIVATE
)

val settings = sharedPrefs.getString("json", null)
val settingsJson = settings?.let { Json.decodeFromString(JsonObject.serializer(), it) } ?: JsonObject(emptyMap())
val newSettings = settingsJson.toMutableMap().apply {
if (force) {
put("financial_connections_override_native", JsonPrimitive("native"))
} else {
remove("financial_connections_override_native")
}
}

sharedPrefs.edit {
putString("json", JsonObject(newSettings).toString())
}
}
}

0 comments on commit b82f10c

Please sign in to comment.