-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link Gate to determine link behaviour
- Loading branch information
1 parent
4ac8f33
commit 39b6a68
Showing
7 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...com/stripe/android/paymentsheet/example/playground/settings/LinkTypeSettingsDefinition.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,44 @@ | ||
package com.stripe.android.paymentsheet.example.playground.settings | ||
|
||
import com.stripe.android.core.utils.FeatureFlags | ||
|
||
internal object LinkTypeSettingsDefinition : PlaygroundSettingDefinition<LinkType>, | ||
PlaygroundSettingDefinition.Saveable<LinkType> by EnumSaveable( | ||
key = "LinkType", | ||
values = LinkType.entries.toTypedArray(), | ||
defaultValue = LinkType.Native | ||
), | ||
PlaygroundSettingDefinition.Displayable<LinkType> { | ||
override val displayName: String = "LinkType" | ||
|
||
override fun createOptions(configurationData: PlaygroundConfigurationData): List<PlaygroundSettingDefinition.Displayable.Option<LinkType>> { | ||
return listOf( | ||
option("Native", LinkType.Native), | ||
option("Native + Attest", LinkType.NativeAttest), | ||
option("Web", LinkType.Web), | ||
) | ||
} | ||
|
||
override fun setValue(value: LinkType) { | ||
when (value) { | ||
LinkType.Native -> { | ||
FeatureFlags.nativeLinkEnabled.setEnabled(true) | ||
FeatureFlags.nativeLinkAttestationEnabled.setEnabled(false) | ||
} | ||
LinkType.NativeAttest -> { | ||
FeatureFlags.nativeLinkEnabled.setEnabled(true) | ||
FeatureFlags.nativeLinkAttestationEnabled.setEnabled(true) | ||
} | ||
LinkType.Web -> { | ||
FeatureFlags.nativeLinkEnabled.setEnabled(false) | ||
FeatureFlags.nativeLinkAttestationEnabled.setEnabled(false) | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class LinkType(override val value: String) : ValueEnum { | ||
Native("Native"), | ||
NativeAttest("Native + Attest"), | ||
Web("Web"), | ||
} |
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
20 changes: 20 additions & 0 deletions
20
paymentsheet/src/main/java/com/stripe/android/link/gate/DefaultLinkGate.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,20 @@ | ||
package com.stripe.android.link.gate | ||
|
||
import com.stripe.android.core.utils.FeatureFlags | ||
import com.stripe.android.link.LinkConfiguration | ||
|
||
internal class DefaultLinkGate( | ||
private val configuration: LinkConfiguration | ||
) : LinkGate { | ||
override val useNativeLink: Boolean | ||
get() { | ||
if (FeatureFlags.nativeLinkEnabled.isEnabled) return true | ||
return useAttestationEndpoints | ||
} | ||
|
||
override val useAttestationEndpoints: Boolean | ||
get() { | ||
if (FeatureFlags.nativeLinkAttestationEnabled.isEnabled) return true | ||
return configuration.useAttestationEndpointsForLink | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
paymentsheet/src/main/java/com/stripe/android/link/gate/LinkGate.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,6 @@ | ||
package com.stripe.android.link.gate | ||
|
||
internal interface LinkGate { | ||
val useNativeLink: Boolean | ||
val useAttestationEndpoints: Boolean | ||
} |
91 changes: 91 additions & 0 deletions
91
paymentsheet/src/test/java/com/stripe/android/link/gate/DefaultLinkGateTest.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,91 @@ | ||
package com.stripe.android.link.gate | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.stripe.android.core.utils.FeatureFlags | ||
import com.stripe.android.link.TestFactory | ||
import com.stripe.android.testing.FeatureFlagTestRule | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
internal class DefaultLinkGateTest { | ||
|
||
@get:Rule | ||
val nativeLinkFeatureFlagTestRule = FeatureFlagTestRule( | ||
featureFlag = FeatureFlags.nativeLinkEnabled, | ||
isEnabled = false | ||
) | ||
|
||
@get:Rule | ||
val attestationFeatureFlagTestRule = FeatureFlagTestRule( | ||
featureFlag = FeatureFlags.nativeLinkAttestationEnabled, | ||
isEnabled = false | ||
) | ||
|
||
@Test | ||
fun `useNativeLink is true when nativeLinkFeatureFlag is enabled`() { | ||
nativeLinkFeatureFlagTestRule.setEnabled(true) | ||
val gate = gate() | ||
|
||
assertThat(gate.useNativeLink).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useNativeLink is true when nativeLinkFeatureFlag is enabled regardless of other settings`() { | ||
nativeLinkFeatureFlagTestRule.setEnabled(true) | ||
attestationFeatureFlagTestRule.setEnabled(false) | ||
|
||
val gate = gate(useAttestationEndpoints = false) | ||
|
||
assertThat(gate.useNativeLink).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useNativeLink reflects useAttestationEndpoints when nativeLinkFeatureFlag is disabled`() { | ||
nativeLinkFeatureFlagTestRule.setEnabled(false) | ||
attestationFeatureFlagTestRule.setEnabled(true) | ||
|
||
val gate = gate() | ||
|
||
assertThat(gate.useNativeLink).isEqualTo(gate.useAttestationEndpoints) | ||
} | ||
|
||
@Test | ||
fun `useAttestationEndpoints is true when attestationFeatureFlag is enabled`() { | ||
attestationFeatureFlagTestRule.setEnabled(true) | ||
|
||
val gate = gate() | ||
|
||
assertThat(gate.useAttestationEndpoints).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useAttestationEndpoints is true when attestationFeatureFlag is enabled regardless of configuration`() { | ||
attestationFeatureFlagTestRule.setEnabled(true) | ||
|
||
val gate = gate(useAttestationEndpoints = false) | ||
|
||
assertThat(gate.useAttestationEndpoints).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useAttestationEndpoints reflects configuration when attestationFeatureFlag is disabled`() { | ||
attestationFeatureFlagTestRule.setEnabled(false) | ||
|
||
val gateTrue = gate(useAttestationEndpoints = true) | ||
val gateFalse = gate(useAttestationEndpoints = false) | ||
|
||
assertThat(gateTrue.useAttestationEndpoints).isTrue() | ||
assertThat(gateFalse.useAttestationEndpoints).isFalse() | ||
} | ||
|
||
private fun gate(useAttestationEndpoints: Boolean = true): DefaultLinkGate { | ||
return DefaultLinkGate( | ||
configuration = TestFactory.LINK_CONFIGURATION.copy( | ||
useAttestationEndpointsForLink = useAttestationEndpoints | ||
) | ||
) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
paymentsheet/src/test/java/com/stripe/android/link/gate/FakeLinkGate.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,19 @@ | ||
package com.stripe.android.link.gate | ||
|
||
internal class FakeLinkGate : LinkGate { | ||
private var _useNativeLink = true | ||
override val useNativeLink: Boolean | ||
get() = _useNativeLink | ||
|
||
private var _useAttestationEndpoints = true | ||
override val useAttestationEndpoints: Boolean | ||
get() = _useAttestationEndpoints | ||
|
||
fun setUseNativeLink(value: Boolean) { | ||
_useNativeLink = value | ||
} | ||
|
||
fun setUseAttestationEndpoints(value: Boolean) { | ||
_useAttestationEndpoints = value | ||
} | ||
} |
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