Skip to content

Commit

Permalink
Merge pull request #12641 from woocommerce/12189-woo-pos-m2-hide-pos-…
Browse files Browse the repository at this point in the history
…mode-for-ineligible-users

[Woo POS] Hide POS mode for ineligible users
  • Loading branch information
samiuelson authored Sep 20, 2024
2 parents 525e121 + 0e8113a commit d6c8879
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.woocommerce.android.ui.payments.taptopay.isAvailable
import com.woocommerce.android.ui.plans.domain.SitePlan
import com.woocommerce.android.ui.plans.repository.SitePlanRepository
import com.woocommerce.android.ui.woopos.WooPosIsEnabled
import com.woocommerce.android.ui.woopos.WooPosIsFeatureFlagEnabled
import com.woocommerce.android.util.WooLog
import com.woocommerce.android.viewmodel.ResourceProvider
import com.woocommerce.android.viewmodel.ScopedViewModel
Expand Down Expand Up @@ -71,7 +70,6 @@ class MoreMenuViewModel @Inject constructor(
private val isGoogleForWooEnabled: IsGoogleForWooEnabled,
private val hasGoogleAdsCampaigns: HasGoogleAdsCampaigns,
private val isWooPosEnabled: WooPosIsEnabled,
private val isWooPosFFEnabled: WooPosIsFeatureFlagEnabled,
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper
) : ScopedViewModel(savedState) {
private var storeHasGoogleAdsCampaigns = false
Expand Down Expand Up @@ -458,24 +456,17 @@ class MoreMenuViewModel @Inject constructor(
.onStart { emit("") }

private fun checkFeaturesAvailability(): Flow<Map<MoreMenuItemButton.Type, MoreMenuItemButton.State>> {
val initialState = MoreMenuItemButton.Type.entries.associateWith { MoreMenuItemButton.State.Loading }
.toMutableMap()
val initialState = MoreMenuItemButton.Type.entries.associateWith {
MoreMenuItemButton.State.Loading
}.toMutableMap()

val flows = mutableListOf(
return listOf(
doCheckAvailability(MoreMenuItemButton.Type.Blaze) { isBlazeEnabled() },
doCheckAvailability(MoreMenuItemButton.Type.GoogleForWoo) { isGoogleForWooEnabled() },
doCheckAvailability(MoreMenuItemButton.Type.Inbox) { moreMenuRepository.isInboxEnabled() },
doCheckAvailability(MoreMenuItemButton.Type.Settings) { moreMenuRepository.isUpgradesEnabled() },
)

// While this in development better to not show loading state for WooPos at all
if (isWooPosFFEnabled()) {
flows += doCheckAvailability(MoreMenuItemButton.Type.WooPos) { isWooPosEnabled() }
} else {
initialState[MoreMenuItemButton.Type.WooPos] = MoreMenuItemButton.State.Hidden
}

return flows.merge()
doCheckAvailability(MoreMenuItemButton.Type.WooPos) { isWooPosEnabled() }
).merge()
.map { update ->
initialState[update.first] = update.second
initialState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboa
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboardingState
import com.woocommerce.android.ui.payments.cardreader.onboarding.PluginType
import com.woocommerce.android.util.GetWooCorePluginCachedVersion
import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled
import com.woocommerce.android.util.RemoteFeatureFlag.WOO_POS
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.model.payments.inperson.WCPaymentAccountResult
import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore
Expand All @@ -20,17 +22,17 @@ class WooPosIsEnabled @Inject constructor(
private val selectedSite: SelectedSite,
private val ippStore: WCInPersonPaymentsStore,
private val isScreenSizeAllowed: WooPosIsScreenSizeAllowed,
private val isFeatureFlagEnabled: WooPosIsFeatureFlagEnabled,
private val getWooCoreVersion: GetWooCorePluginCachedVersion,
private val cardReaderOnboardingChecker: CardReaderOnboardingChecker,
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled,
) {
private var paymentAccountCache: HashMap<LocalSiteId, WCPaymentAccountResult> = hashMapOf()

@Suppress("ReturnCount")
suspend operator fun invoke(): Boolean {
val selectedSite = selectedSite.getOrNull() ?: return false

if (!isFeatureFlagEnabled()) return false
if (!isRemoteFeatureFlagEnabled(WOO_POS)) return false
if (!isScreenSizeAllowed()) return false
if (!isWooCoreSupportsOrderAutoDraftsAndExtraPaymentsProps()) return false

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.Context
* "Feature flags" are used to hide in-progress features from release versions
*/
enum class FeatureFlag {
WOO_POS,
DB_DOWNGRADE,
INBOX,
WC_SHIPPING_BANNER,
Expand All @@ -25,7 +24,6 @@ enum class FeatureFlag {
PackageUtils.isDebugBuild() || context != null && PackageUtils.isBetaBuild(context)
}

WOO_POS,
WC_SHIPPING_BANNER,
BETTER_CUSTOMER_SEARCH_M2,
ORDER_CREATION_AUTO_TAX_RATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.woocommerce.android.util.RemoteFeatureFlag.LOCAL_NOTIFICATION_1D_AFTE
import com.woocommerce.android.util.RemoteFeatureFlag.LOCAL_NOTIFICATION_1D_BEFORE_FREE_TRIAL_EXPIRES
import com.woocommerce.android.util.RemoteFeatureFlag.LOCAL_NOTIFICATION_STORE_CREATION_READY
import com.woocommerce.android.util.RemoteFeatureFlag.WOO_BLAZE
import com.woocommerce.android.util.RemoteFeatureFlag.WOO_POS
import javax.inject.Inject

class IsRemoteFeatureFlagEnabled @Inject constructor(
Expand All @@ -15,6 +16,7 @@ class IsRemoteFeatureFlagEnabled @Inject constructor(
LOCAL_NOTIFICATION_STORE_CREATION_READY,
LOCAL_NOTIFICATION_1D_BEFORE_FREE_TRIAL_EXPIRES,
LOCAL_NOTIFICATION_1D_AFTER_FREE_TRIAL_EXPIRES,
WOO_POS,
WOO_BLAZE ->
PackageUtils.isDebugBuild() ||
wpComRemoteFeatureFlagRepository.isRemoteFeatureFlagEnabled(featureFlag.remoteKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ enum class RemoteFeatureFlag(val remoteKey: String) {
LOCAL_NOTIFICATION_STORE_CREATION_READY("woo_notification_store_creation_ready"),
LOCAL_NOTIFICATION_1D_BEFORE_FREE_TRIAL_EXPIRES("woo_notification_1d_before_free_trial_expires"),
LOCAL_NOTIFICATION_1D_AFTER_FREE_TRIAL_EXPIRES("woo_notification_1d_after_free_trial_expires"),
WOO_BLAZE("woo_blaze")
WOO_BLAZE("woo_blaze"),
WOO_POS("woo_pos"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.woocommerce.android.ui.payments.taptopay.TapToPayAvailabilityStatus
import com.woocommerce.android.ui.plans.domain.SitePlan
import com.woocommerce.android.ui.plans.repository.SitePlanRepository
import com.woocommerce.android.ui.woopos.WooPosIsEnabled
import com.woocommerce.android.ui.woopos.WooPosIsFeatureFlagEnabled
import com.woocommerce.android.util.captureValues
import com.woocommerce.android.util.runAndCaptureValues
import com.woocommerce.android.viewmodel.BaseUnitTest
Expand Down Expand Up @@ -90,10 +89,6 @@ class MoreMenuViewModelTests : BaseUnitTest() {

private val analyticsTrackerWrapper: AnalyticsTrackerWrapper = mock()

private val isWooPosFFEnabled: WooPosIsFeatureFlagEnabled = mock {
onBlocking { invoke() } doReturn true
}

private val blazeCampaignsStore: BlazeCampaignsStore = mock()

private lateinit var viewModel: MoreMenuViewModel
Expand All @@ -116,7 +111,6 @@ class MoreMenuViewModelTests : BaseUnitTest() {
isGoogleForWooEnabled = isGoogleForWooEnabled,
hasGoogleAdsCampaigns = hasGoogleAdsCampaigns,
isWooPosEnabled = isWooPosEnabled,
isWooPosFFEnabled = isWooPosFFEnabled,
analyticsTrackerWrapper = analyticsTrackerWrapper,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboa
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboardingState
import com.woocommerce.android.ui.payments.cardreader.onboarding.PluginType
import com.woocommerce.android.util.GetWooCorePluginCachedVersion
import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled
import com.woocommerce.android.util.RemoteFeatureFlag.WOO_POS
import com.woocommerce.android.viewmodel.BaseUnitTest
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
Expand All @@ -30,7 +32,7 @@ class WooPosIsEnabledTest : BaseUnitTest() {
private val ippStore: WCInPersonPaymentsStore = mock()
private val cardReaderOnboardingChecker: CardReaderOnboardingChecker = mock()
private val isScreenSizeAllowed: WooPosIsScreenSizeAllowed = mock()
private val isFeatureFlagEnabled: WooPosIsFeatureFlagEnabled = mock()
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled = mock()
private val getWooCoreVersion: GetWooCorePluginCachedVersion = mock {
on { invoke() }.thenReturn("6.6.0")
}
Expand All @@ -45,14 +47,14 @@ class WooPosIsEnabledTest : BaseUnitTest() {
whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted)
whenever(isScreenSizeAllowed()).thenReturn(true)
whenever(ippStore.loadAccount(any(), any())).thenReturn(buildPaymentAccountResult())
whenever(isFeatureFlagEnabled()).thenReturn(true)
whenever(isRemoteFeatureFlagEnabled(WOO_POS)).thenReturn(true)

sut = WooPosIsEnabled(
selectedSite = selectedSite,
ippStore = ippStore,
cardReaderOnboardingChecker = cardReaderOnboardingChecker,
isScreenSizeAllowed = isScreenSizeAllowed,
isFeatureFlagEnabled = isFeatureFlagEnabled,
isRemoteFeatureFlagEnabled = isRemoteFeatureFlagEnabled,
getWooCoreVersion = getWooCoreVersion,
)
}
Expand All @@ -67,7 +69,7 @@ class WooPosIsEnabledTest : BaseUnitTest() {
whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS)
whenever(ippStore.loadAccount(any(), any()))
.thenReturn(buildPaymentAccountResult(countryCode = "US", defaultCurrency = "USD"))
whenever(isFeatureFlagEnabled()).thenReturn(true)
whenever(isRemoteFeatureFlagEnabled(WOO_POS)).thenReturn(true)

assertTrue(sut())
}
Expand Down Expand Up @@ -129,7 +131,7 @@ class WooPosIsEnabledTest : BaseUnitTest() {

@Test
fun `given feature flag disabled, then return false`() = testBlocking {
whenever(isFeatureFlagEnabled.invoke()).thenReturn(false)
whenever(isRemoteFeatureFlagEnabled.invoke(WOO_POS)).thenReturn(false)
assertFalse(sut())
}

Expand Down

0 comments on commit d6c8879

Please sign in to comment.