diff --git a/forage-android/src/main/java/com/joinforage/forage/android/core/services/launchdarkly/LDManager.kt b/forage-android/src/main/java/com/joinforage/forage/android/core/services/launchdarkly/LDManager.kt index 4e26f5df6..7a736f6c5 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/core/services/launchdarkly/LDManager.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/core/services/launchdarkly/LDManager.kt @@ -10,8 +10,8 @@ import com.launchdarkly.sdk.android.LDClient import com.launchdarkly.sdk.android.LDConfig internal object LDFlags { - const val VAULT_PRIMARY_TRAFFIC_PERCENTAGE_FLAG = "vault-primary-traffic-percentage" const val ISO_POLLING_WAIT_INTERVALS = "iso-polling-wait-intervals" + const val ROSETTA_TRAFFIC_PERCENTAGE = "rosetta-traffic-percentage" } internal object LDContexts { @@ -22,12 +22,13 @@ internal object LDContextKind { const val SERVICE = "service" } -internal val ALWAYS_BT_PERCENT = 100.0 -internal val ALWAYS_VGS_PERCENT = 0.0 +// rosetta-traffic-percentage +internal val ALWAYS_ROSETTA_PERCENT = 100.0 +internal val ALWAYS_THIRD_PARTY_PERCENT = 0.0 -internal fun computeVaultType(trafficPrimaryPercentFlag: Double): VaultType { +internal fun computeVaultType(rosettaPercentage: Double): VaultType { val randomNum = Math.random() * 100 - return if (randomNum < trafficPrimaryPercentFlag) VaultType.BT_VAULT_TYPE else VaultType.VGS_VAULT_TYPE + return if (randomNum <= rosettaPercentage) VaultType.FORAGE_VAULT_TYPE else VaultType.BT_VAULT_TYPE } internal object LDManager { @@ -45,14 +46,14 @@ internal object LDManager { } internal fun getVaultProvider(logger: Log = Log.getSilentInstance()): VaultType { - val vaultPercent = client?.doubleVariation( - LDFlags.VAULT_PRIMARY_TRAFFIC_PERCENTAGE_FLAG, - ALWAYS_VGS_PERCENT - ) ?: ALWAYS_VGS_PERCENT - logger.i("[LaunchDarkly] Vault percent of $vaultPercent return from LD") - - // convert the flag percent into an answer to which vault provider to use - val vaultType = computeVaultType(vaultPercent) + val rosettaPercent = client?.doubleVariation( + LDFlags.ROSETTA_TRAFFIC_PERCENTAGE, + ALWAYS_ROSETTA_PERCENT + ) ?: ALWAYS_ROSETTA_PERCENT + logger.i("[LaunchDarkly] Rosetta percent of $rosettaPercent returned from LD") + + // convert the rosetta flag percent into an answer to which vault provider to use + val vaultType = computeVaultType(rosettaPercent) logger.i("[LaunchDarkly] Vault type set to $vaultType") // return vault provider diff --git a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/ForagePINEditText.kt b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/ForagePINEditText.kt index 5b50c588c..947e363f1 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/ForagePINEditText.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/ForagePINEditText.kt @@ -94,6 +94,8 @@ class ForagePINEditText @JvmOverloads constructor( return if (vaultType == VaultType.BT_VAULT_TYPE) { btVaultWrapper } else { + // TODO: Update this to the ForageVaultWrapper once it's back in this codebase + // https://linear.app/joinforage/issue/FX-1368/re-introduce-the-foragevaultwrapper-into-the-coreui-module-in-the vgsVaultWrapper } } diff --git a/forage-android/src/test/java/com/joinforage/forage/android/network/data/LaunchDarklyTest.kt b/forage-android/src/test/java/com/joinforage/forage/android/network/data/LaunchDarklyTest.kt index c592a32b5..38debdf14 100644 --- a/forage-android/src/test/java/com/joinforage/forage/android/network/data/LaunchDarklyTest.kt +++ b/forage-android/src/test/java/com/joinforage/forage/android/network/data/LaunchDarklyTest.kt @@ -3,8 +3,8 @@ package com.joinforage.forage.android.network.data import android.app.Application import androidx.test.platform.app.InstrumentationRegistry import com.joinforage.forage.android.core.services.VaultType -import com.joinforage.forage.android.core.services.launchdarkly.ALWAYS_BT_PERCENT -import com.joinforage.forage.android.core.services.launchdarkly.ALWAYS_VGS_PERCENT +import com.joinforage.forage.android.core.services.launchdarkly.ALWAYS_ROSETTA_PERCENT +import com.joinforage.forage.android.core.services.launchdarkly.ALWAYS_THIRD_PARTY_PERCENT import com.joinforage.forage.android.core.services.launchdarkly.LDFlags import com.joinforage.forage.android.core.services.launchdarkly.LDManager import com.joinforage.forage.android.core.services.launchdarkly.computeVaultType @@ -35,38 +35,50 @@ class LaunchDarklyTest() { } @Test - fun `Test computeVaultType returns BT percent is 100f`() { - assertThat(computeVaultType(ALWAYS_BT_PERCENT)).isEqualTo(VaultType.BT_VAULT_TYPE) + fun `Test computeVaultType returns Forage Vault if percent is 100f`() { + assertThat(computeVaultType(ALWAYS_ROSETTA_PERCENT)).isEqualTo(VaultType.FORAGE_VAULT_TYPE) } @Test - fun `Test computeVaultType returns VGS percent is 0f`() { - assertThat(computeVaultType(ALWAYS_VGS_PERCENT)).isEqualTo(VaultType.VGS_VAULT_TYPE) + fun `Test computeVaultType returns BT percent is 0f`() { + assertThat(computeVaultType(ALWAYS_THIRD_PARTY_PERCENT)).isEqualTo(VaultType.BT_VAULT_TYPE) } @Test - fun `It should default to using VGS and honor flag updates`() = runTest { - // set up LDManager, importantly, we're not giving it any value for - // primaryTrafficPercent since we want to test it defaults to VGS + fun `It should default to using Rosetta and honor flag updates`() = runTest { + // set up LDManager, importantly, we're not giving it any value for rosettaTrafficPercentage or + // primaryTrafficPercent since we want to test it defaults to Rosetta val app = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as Application LDManager.initialize(app, ldConfig) - // it should default to using VGS as the vault provider + // it should default to using Rosetta as the vault provider when no flags are set val original = LDManager.getVaultProvider() - assertThat(original).isEqualTo(VaultType.VGS_VAULT_TYPE) + assertThat(original).isEqualTo(VaultType.FORAGE_VAULT_TYPE) - // Set the test data to send all traffic to BT + // Set the test data to send all traffic to rosetta td.update( - td.flag(LDFlags.VAULT_PRIMARY_TRAFFIC_PERCENTAGE_FLAG).variations( + td.flag(LDFlags.ROSETTA_TRAFFIC_PERCENTAGE).variations( LDValue.of( - ALWAYS_BT_PERCENT + ALWAYS_ROSETTA_PERCENT ) ) ) - // it should consume the flag and choose BT - val postUpdate = LDManager.getVaultProvider() - assertThat(postUpdate).isEqualTo(VaultType.BT_VAULT_TYPE) + val postRosettaUpdate = LDManager.getVaultProvider() + assertThat(postRosettaUpdate).isEqualTo(VaultType.FORAGE_VAULT_TYPE) + + // Set the test data to send all traffic to third-party + td.update( + td.flag(LDFlags.ROSETTA_TRAFFIC_PERCENTAGE).variations( + LDValue.of( + ALWAYS_THIRD_PARTY_PERCENT + ) + ) + ) + + // it should use BT + val post3PUpdate = LDManager.getVaultProvider() + assertThat(post3PUpdate).isEqualTo(VaultType.BT_VAULT_TYPE) } @Test