Skip to content
Draft
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
@@ -1,5 +1,6 @@
package com.x8bit.bitwarden.data.billing.manager

import com.bitwarden.core.data.manager.model.FlagKey
import kotlinx.coroutines.flow.StateFlow

/**
Expand All @@ -16,6 +17,13 @@ interface PremiumStateManager {
*/
val isPremiumUpgradeBannerEligibleFlow: StateFlow<Boolean>

/**
* Emits `true` when the in-app upgrade flow is available (i.e., in-app billing is
* supported and the [FlagKey.MobilePremiumUpgrade] feature flag is enabled),
* or `false` otherwise.
*/
val isInAppUpgradeAvailableFlow: StateFlow<Boolean>

/**
* Marks the Premium upgrade banner as dismissed for the current user.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ class PremiumStateManagerImpl(
initialValue = false,
)

override val isInAppUpgradeAvailableFlow: StateFlow<Boolean> =
combine(
billingRepository.isInAppBillingSupportedFlow,
featureFlagManager.getFeatureFlagFlow(FlagKey.MobilePremiumUpgrade),
) { isInAppBillingSupported, featureFlagEnabled ->
isInAppBillingSupported && featureFlagEnabled
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Eagerly,
initialValue = false,
)

override fun dismissPremiumUpgradeBanner() {
val activeUserId = authDiskSource.userState?.activeUserId ?: return
settingsDiskSource.storePremiumUpgradeBannerDismissed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,46 @@
}
}

@Test
fun `isInAppUpgradeAvailableFlow should emit true when billing supported and flag enabled`() =

Check warning on line 334 in app/src/test/kotlin/com/x8bit/bitwarden/data/billing/manager/PremiumStateManagerImplTest.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "isInAppUpgradeAvailableFlow should emit true when billing supported and flag enabled" to match the regular expression ^[a-zA-Z][a-zA-Z0-9]*$

See more on https://sonarcloud.io/project/issues?id=bitwarden_android&issues=AZ2J9arNC9jM6ujZQAMl&open=AZ2J9arNC9jM6ujZQAMl&pullRequest=6795
runTest {
val manager = createManager()
manager.isInAppUpgradeAvailableFlow.test {
assertTrue(awaitItem())
}
}

@Test
fun `isInAppUpgradeAvailableFlow should emit false when billing not supported`() =

Check warning on line 343 in app/src/test/kotlin/com/x8bit/bitwarden/data/billing/manager/PremiumStateManagerImplTest.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "isInAppUpgradeAvailableFlow should emit false when billing not supported" to match the regular expression ^[a-zA-Z][a-zA-Z0-9]*$

See more on https://sonarcloud.io/project/issues?id=bitwarden_android&issues=AZ2J9arNC9jM6ujZQAMm&open=AZ2J9arNC9jM6ujZQAMm&pullRequest=6795
runTest {
mutableIsInAppBillingSupportedFlow.value = false
val manager = createManager()
manager.isInAppUpgradeAvailableFlow.test {
assertFalse(awaitItem())
}
}

@Test
fun `isInAppUpgradeAvailableFlow should emit false when feature flag disabled`() =

Check warning on line 353 in app/src/test/kotlin/com/x8bit/bitwarden/data/billing/manager/PremiumStateManagerImplTest.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "isInAppUpgradeAvailableFlow should emit false when feature flag disabled" to match the regular expression ^[a-zA-Z][a-zA-Z0-9]*$

See more on https://sonarcloud.io/project/issues?id=bitwarden_android&issues=AZ2J9arNC9jM6ujZQAMn&open=AZ2J9arNC9jM6ujZQAMn&pullRequest=6795
runTest {
mutableMobilePremiumUpgradeFlagFlow.value = false
val manager = createManager()
manager.isInAppUpgradeAvailableFlow.test {
assertFalse(awaitItem())
}
}

@Test
fun `isInAppUpgradeAvailableFlow should emit false when both conditions are false`() =

Check warning on line 363 in app/src/test/kotlin/com/x8bit/bitwarden/data/billing/manager/PremiumStateManagerImplTest.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "isInAppUpgradeAvailableFlow should emit false when both conditions are false" to match the regular expression ^[a-zA-Z][a-zA-Z0-9]*$

See more on https://sonarcloud.io/project/issues?id=bitwarden_android&issues=AZ2J9arNC9jM6ujZQAMo&open=AZ2J9arNC9jM6ujZQAMo&pullRequest=6795
runTest {
mutableIsInAppBillingSupportedFlow.value = false
mutableMobilePremiumUpgradeFlagFlow.value = false
val manager = createManager()
manager.isInAppUpgradeAvailableFlow.test {
assertFalse(awaitItem())
}
}

@Test
fun `dismissPremiumUpgradeBanner should store dismissed state for active user`() {
val manager = createManager()
Expand Down
Loading