-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test rule to force native bank flow
- Loading branch information
1 parent
064778c
commit b82f10c
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...heet-example/src/androidTest/java/com/stripe/android/utils/ForceNativeBankFlowTestRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} |