Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ForceNativeBankFlowTestRule for bank auth flow #10241

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,11 +22,11 @@ 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 org.junit.Ignore
import com.stripe.android.utils.ForceNativeBankFlowTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@Ignore("Tests currently failing, ignoring while we work on a fix so we can merge other PRs.")
@RunWith(AndroidJUnit4::class)
internal class TestInstantDebits : BasePlaygroundTest() {

Expand All @@ -43,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,11 +20,11 @@ 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 org.junit.Ignore
import com.stripe.android.utils.ForceNativeBankFlowTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@Ignore("Tests currently failing, ignoring while we work on a fix so we can merge other PRs.")
@RunWith(AndroidJUnit4::class)
internal class TestUSBankAccount : BasePlaygroundTest() {
private val testParameters = TestParameters.create(
Expand All @@ -35,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,10 +9,10 @@ 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 org.junit.Ignore
import com.stripe.android.utils.ForceNativeBankFlowTestRule
import org.junit.Rule
import org.junit.Test

@Ignore("Tests currently failing, ignoring while we work on a fix so we can merge other PRs.")
internal class TestUsBankAccountInCustomerSheet : BasePlaygroundTest() {
private val testParameters = TestParameters.create(
paymentMethodCode = "us_bank_account",
Expand All @@ -22,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())
}
}
}
Loading