From 2fb01a413bda2f5c95dd3f02e8aa81db0f04ad04 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 12 Nov 2024 08:42:18 +0100 Subject: [PATCH 1/6] Use store settings to determine country and currency --- .../android/ui/woopos/WooPosIsEnabled.kt | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt index 5ae7059997b..f6b76903d32 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt @@ -11,33 +11,26 @@ import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled import com.woocommerce.android.util.RemoteFeatureFlag.WOO_POS import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope -import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.model.payments.inperson.WCPaymentAccountResult -import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore -import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore.InPersonPaymentsPluginType.WOOCOMMERCE_PAYMENTS +import org.wordpress.android.fluxc.store.WooCommerceStore import javax.inject.Inject import javax.inject.Singleton -private typealias LocalSiteId = Int - @Singleton class WooPosIsEnabled @Inject constructor( private val selectedSite: SelectedSite, - private val ippStore: WCInPersonPaymentsStore, private val isScreenSizeAllowed: WooPosIsScreenSizeAllowed, private val getWooCoreVersion: GetWooCorePluginCachedVersion, private val cardReaderOnboardingChecker: CardReaderOnboardingChecker, + private val wooCommerceStore: WooCommerceStore, private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled, private val isWooPosPaymentsOnboardingSupportedInternally: WooPosIsPaymentsOnboardingSupportedInternally, ) { - private var paymentAccountCache: HashMap = hashMapOf() - @Suppress("ReturnCount") suspend operator fun invoke(): Boolean = coroutineScope { val selectedSite = selectedSite.getOrNull() ?: return@coroutineScope false val onboardingStatusDeferred = async { cardReaderOnboardingChecker.getOnboardingState() } - val paymentAccountDeferred = async { getOrFetchPaymentAccount(selectedSite, WOOCOMMERCE_PAYMENTS) } + val siteSettingsDeferred = async { wooCommerceStore.getSiteSettings(selectedSite) } if (!isRemoteFeatureFlagEnabled(WOO_POS)) return@coroutineScope false if (!isScreenSizeAllowed()) return@coroutineScope false @@ -50,27 +43,13 @@ class WooPosIsEnabled @Inject constructor( if (!isIPPOnboardingCompleted(onboardingStatus)) return@coroutineScope false } - val paymentAccount = paymentAccountDeferred.await() ?: return@coroutineScope false - if (paymentAccount.country.lowercase() != "us") return@coroutineScope false - if (paymentAccount.storeCurrencies.default.lowercase() != "usd") return@coroutineScope false + val siteSettings = siteSettingsDeferred.await() ?: return@coroutineScope false + if (siteSettings.countryCode.lowercase() !in SUPPORTED_COUNTRIES) return@coroutineScope false + if (siteSettings.currencyCode.lowercase() !in SUPPORTED_CURRENCIES) return@coroutineScope false return@coroutineScope true } - private suspend fun getOrFetchPaymentAccount( - selectedSite: SiteModel, - ippPlugin: WCInPersonPaymentsStore.InPersonPaymentsPluginType - ): WCPaymentAccountResult? { - paymentAccountCache[selectedSite.id]?.let { return it } - - val paymentsAccount = ippStore.loadAccount( - ippPlugin, - selectedSite - ) - - return paymentsAccount.model?.also { paymentAccountCache[selectedSite.id] = it } - } - private fun isIPPOnboardingCompleted(onboardingStatus: CardReaderOnboardingState): Boolean = when (onboardingStatus) { CardReaderOnboardingState.ChoosePaymentGatewayProvider, @@ -100,5 +79,8 @@ class WooPosIsEnabled @Inject constructor( private companion object { const val WC_VERSION_SUPPORTS_ORDER_AUTO_DRAFTS_AND_EXTRA_PAYMENTS_PROPS = "6.6.0" + + val SUPPORTED_COUNTRIES = listOf("us") + val SUPPORTED_CURRENCIES = listOf("usd") } } From 6ba4faa459a24cd1cf09078b2716725f8fb35704 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 12 Nov 2024 09:38:01 +0100 Subject: [PATCH 2/6] Fixed navigation to WpComWEbView from the POS flow --- .../CardReaderOnboardingFragment.kt | 4 +- .../main/res/navigation/nav_graph_main.xml | 2 +- .../main/res/navigation/nav_graph_orders.xml | 2 +- .../res/navigation/nav_graph_payment_flow.xml | 43 ++++++++++++++++++- .../main/res/navigation/nav_graph_refunds.xml | 2 +- 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/onboarding/CardReaderOnboardingFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/onboarding/CardReaderOnboardingFragment.kt index 06cda49e084..a4d04a9955c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/onboarding/CardReaderOnboardingFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/onboarding/CardReaderOnboardingFragment.kt @@ -12,7 +12,7 @@ import androidx.core.view.get import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.google.android.material.button.MaterialButton -import com.woocommerce.android.NavGraphMainDirections +import com.woocommerce.android.NavGraphPaymentFlowDirections import com.woocommerce.android.R import com.woocommerce.android.databinding.FragmentCardReaderOnboardingBinding import com.woocommerce.android.databinding.FragmentCardReaderOnboardingCodDisabledBinding @@ -75,7 +75,7 @@ class CardReaderOnboardingFragment : BaseFragment(R.layout.fragment_card_reader_ } is CardReaderOnboardingEvent.NavigateToUrlInWPComWebView -> { findNavController().navigate( - NavGraphMainDirections.actionGlobalWPComWebViewFragment(urlToLoad = event.url) + NavGraphPaymentFlowDirections.actionGlobalWPComWebViewFragment(urlToLoad = event.url) ) } is CardReaderOnboardingEvent.NavigateToUrlInGenericWebView -> { diff --git a/WooCommerce/src/main/res/navigation/nav_graph_main.xml b/WooCommerce/src/main/res/navigation/nav_graph_main.xml index 5af7918d068..82fe1dfdc84 100644 --- a/WooCommerce/src/main/res/navigation/nav_graph_main.xml +++ b/WooCommerce/src/main/res/navigation/nav_graph_main.xml @@ -309,7 +309,7 @@ app:destination="@id/nav_graph_coupons" /> + app:destination="@id/nav_graph_payment_flow"> @@ -383,4 +384,44 @@ app:nullable="false" /> + + + + + + + + + + + + diff --git a/WooCommerce/src/main/res/navigation/nav_graph_refunds.xml b/WooCommerce/src/main/res/navigation/nav_graph_refunds.xml index bc36e2d706d..9a594d4e3f5 100644 --- a/WooCommerce/src/main/res/navigation/nav_graph_refunds.xml +++ b/WooCommerce/src/main/res/navigation/nav_graph_refunds.xml @@ -73,7 +73,7 @@ android:label="RefundConfirmationDialog" > Date: Tue, 12 Nov 2024 10:48:34 +0100 Subject: [PATCH 3/6] NavGraphPaymentFlowDirections to navigate to WPCom view to make it work on the POS flows --- .../cardreader/connect/CardReaderConnectDialogFragment.kt | 3 ++- .../cardreader/payment/CardReaderPaymentDialogFragment.kt | 3 ++- .../woocommerce/android/ui/payments/hub/PaymentsHubFragment.kt | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt index 53ffecb521f..31070ad7445 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt @@ -24,6 +24,7 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.woocommerce.android.NavGraphMainDirections +import com.woocommerce.android.NavGraphPaymentFlowDirections import com.woocommerce.android.R import com.woocommerce.android.analytics.AnalyticsTracker import com.woocommerce.android.databinding.CardReaderConnectDialogBinding @@ -268,7 +269,7 @@ class CardReaderConnectDialogFragment : PaymentsBaseDialogFragment(R.layout.card ToastUtils.showToast(requireContext(), event.message) is CardReaderConnectEvent.OpenWPComWebView -> findNavController().navigateSafely( - NavGraphMainDirections.actionGlobalWPComWebViewFragment(urlToLoad = event.url) + NavGraphPaymentFlowDirections.actionGlobalWPComWebViewFragment(urlToLoad = event.url) ) is CardReaderConnectEvent.OpenGenericWebView -> ChromeCustomTabUtils.launchUrl(requireContext(), event.url) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt index 3b744901ed5..d082deedd9b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt @@ -18,6 +18,7 @@ import androidx.navigation.fragment.findNavController import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar import com.woocommerce.android.NavGraphMainDirections +import com.woocommerce.android.NavGraphPaymentFlowDirections import com.woocommerce.android.R import com.woocommerce.android.analytics.AnalyticsTracker import com.woocommerce.android.databinding.CardReaderPaymentDialogBinding @@ -141,7 +142,7 @@ class CardReaderPaymentDialogFragment : PaymentsBaseDialogFragment(R.layout.card private fun openPurchaseCardReaderScreen(url: String) { findNavController().navigate( - NavGraphMainDirections.actionGlobalWPComWebViewFragment(urlToLoad = url) + NavGraphPaymentFlowDirections.actionGlobalWPComWebViewFragment(urlToLoad = url) ) } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/hub/PaymentsHubFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/hub/PaymentsHubFragment.kt index c09b66725d9..b0c089d8d54 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/hub/PaymentsHubFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/hub/PaymentsHubFragment.kt @@ -15,6 +15,7 @@ import androidx.transition.Slide import androidx.transition.TransitionManager import com.google.android.material.textview.MaterialTextView import com.woocommerce.android.NavGraphMainDirections +import com.woocommerce.android.NavGraphPaymentFlowDirections import com.woocommerce.android.R import com.woocommerce.android.analytics.AnalyticsTracker import com.woocommerce.android.databinding.FragmentPaymentsHubBinding @@ -91,7 +92,7 @@ class PaymentsHubFragment : BaseFragment(R.layout.fragment_payments_hub) { } is PaymentsHubViewModel.PaymentsHubEvents.NavigateToPurchaseCardReaderFlow -> { findNavController().navigate( - NavGraphMainDirections.actionGlobalWPComWebViewFragment( + NavGraphPaymentFlowDirections.actionGlobalWPComWebViewFragment( urlToLoad = event.url, title = resources.getString(event.titleRes) ) From 68b43154ce03faf7b284411c2aa5d365bd960530 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 12 Nov 2024 10:51:29 +0100 Subject: [PATCH 4/6] Removed unused imports --- .../cardreader/connect/CardReaderConnectDialogFragment.kt | 1 - .../cardreader/payment/CardReaderPaymentDialogFragment.kt | 1 - .../kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt index 31070ad7445..549e91bba23 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/connect/CardReaderConnectDialogFragment.kt @@ -23,7 +23,6 @@ import androidx.lifecycle.Lifecycle import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager -import com.woocommerce.android.NavGraphMainDirections import com.woocommerce.android.NavGraphPaymentFlowDirections import com.woocommerce.android.R import com.woocommerce.android.analytics.AnalyticsTracker diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt index d082deedd9b..da01e59001d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/CardReaderPaymentDialogFragment.kt @@ -17,7 +17,6 @@ import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar -import com.woocommerce.android.NavGraphMainDirections import com.woocommerce.android.NavGraphPaymentFlowDirections import com.woocommerce.android.R import com.woocommerce.android.analytics.AnalyticsTracker diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt index f6b76903d32..a0ea76823ed 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabled.kt @@ -30,7 +30,7 @@ class WooPosIsEnabled @Inject constructor( val selectedSite = selectedSite.getOrNull() ?: return@coroutineScope false val onboardingStatusDeferred = async { cardReaderOnboardingChecker.getOnboardingState() } - val siteSettingsDeferred = async { wooCommerceStore.getSiteSettings(selectedSite) } + val siteSettingsDeferred = async { wooCommerceStore.getSiteSettings(selectedSite) } if (!isRemoteFeatureFlagEnabled(WOO_POS)) return@coroutineScope false if (!isScreenSizeAllowed()) return@coroutineScope false From 58008788448b1de27585742e0e95b61efe64bac0 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 12 Nov 2024 11:04:45 +0100 Subject: [PATCH 5/6] Fixed test. Addeed missing cases --- .../android/ui/woopos/WooPosIsEnabledTest.kt | 161 ++++++------------ 1 file changed, 48 insertions(+), 113 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabledTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabledTest.kt index a6daf17cdc2..469ea528c76 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabledTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/WooPosIsEnabledTest.kt @@ -12,17 +12,11 @@ import com.woocommerce.android.viewmodel.BaseUnitTest import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.Before import org.mockito.kotlin.any -import org.mockito.kotlin.clearInvocations import org.mockito.kotlin.mock -import org.mockito.kotlin.never -import org.mockito.kotlin.times -import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.model.payments.inperson.WCPaymentAccountResult -import org.wordpress.android.fluxc.model.payments.inperson.WCPaymentAccountResult.WCPaymentAccountStatus.StoreCurrencies -import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooResult -import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore +import org.wordpress.android.fluxc.model.WCSettingsModel +import org.wordpress.android.fluxc.store.WooCommerceStore import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -30,7 +24,7 @@ import kotlin.test.assertTrue @OptIn(ExperimentalCoroutinesApi::class) class WooPosIsEnabledTest : BaseUnitTest() { private val selectedSite: SelectedSite = mock() - private val ippStore: WCInPersonPaymentsStore = mock() + private val wooCommerceStore: WooCommerceStore = mock() private val cardReaderOnboardingChecker: CardReaderOnboardingChecker = mock() private val isScreenSizeAllowed: WooPosIsScreenSizeAllowed = mock() private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled = mock() @@ -43,18 +37,20 @@ class WooPosIsEnabledTest : BaseUnitTest() { @Before fun setup() = testBlocking { - whenever(selectedSite.getOrNull()).thenReturn(SiteModel().also { it.id = 1 }) + val siteModel = SiteModel().also { it.id = 1 } + whenever(selectedSite.getOrNull()).thenReturn(siteModel) val onboardingCompleted = mock() whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS) whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) whenever(isScreenSizeAllowed()).thenReturn(true) - whenever(ippStore.loadAccount(any(), any())).thenReturn(buildPaymentAccountResult()) whenever(isRemoteFeatureFlagEnabled(WOO_POS)).thenReturn(true) whenever(isWooPosPaymentsOnboardingSupportedInternally()).thenReturn(false) + val siteSettings = buildSiteSettings() + whenever(wooCommerceStore.getSiteSettings(siteModel)).thenReturn(siteSettings) sut = WooPosIsEnabled( selectedSite = selectedSite, - ippStore = ippStore, + wooCommerceStore = wooCommerceStore, cardReaderOnboardingChecker = cardReaderOnboardingChecker, isScreenSizeAllowed = isScreenSizeAllowed, isRemoteFeatureFlagEnabled = isRemoteFeatureFlagEnabled, @@ -64,80 +60,77 @@ class WooPosIsEnabledTest : BaseUnitTest() { } @Test - fun `given big enough screen, IPP Onboarding completed, USD currency, store in the US, then return true`() = + fun `given feature flag enabled screen size allowed onboarding completed correct plugin supported country and currency, when invoked, then return true`() = testBlocking { - whenever(selectedSite.getOrNull()).thenReturn(SiteModel().also { it.id = 1 }) + whenever(isRemoteFeatureFlagEnabled(WOO_POS)).thenReturn(true) whenever(isScreenSizeAllowed()).thenReturn(true) val onboardingCompleted = mock() - whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS) - whenever(ippStore.loadAccount(any(), any())) - .thenReturn(buildPaymentAccountResult(countryCode = "US", defaultCurrency = "USD")) - whenever(isRemoteFeatureFlagEnabled(WOO_POS)).thenReturn(true) + whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) assertTrue(sut()) } @Test - fun `given store not in the US, then return false`() = testBlocking { - val result = buildPaymentAccountResult(countryCode = "CA") - whenever(ippStore.loadAccount(any(), any())).thenReturn(result) + fun `given feature flag disabled, when invoked, then return false`() = testBlocking { + whenever(isRemoteFeatureFlagEnabled.invoke(WOO_POS)).thenReturn(false) assertFalse(sut()) } @Test - fun `given not big enough screen, then return false`() = testBlocking { - whenever(isScreenSizeAllowed()).thenReturn(false) + fun `given unsupported country, when invoked, then return false`() = testBlocking { + val result = buildSiteSettings(countryCode = "CA", currencyCode = "USD") + whenever(wooCommerceStore.getSiteSettings(any())).thenReturn(result) assertFalse(sut()) } @Test - fun `given currency is not USD, then return false`() = testBlocking { - val result = buildPaymentAccountResult(defaultCurrency = "CAD") - whenever(ippStore.loadAccount(any(), any())).thenReturn(result) + fun `given unsupported currency, when invoked, then return false`() = testBlocking { + val result = buildSiteSettings(currencyCode = "CAD", countryCode = "US") + whenever(wooCommerceStore.getSiteSettings(any())).thenReturn(result) assertFalse(sut()) } @Test - fun `given ipp onboarding is Completed, then return true`() = testBlocking { + fun `given plugin is not WooCommerce Payments, when invoked, then return false`() = testBlocking { val onboardingCompleted = mock() - whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS) - whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) - - assertTrue(sut()) - } - - @Test - fun `given ipp onboarding is Pending Requirements, then return false`() = testBlocking { - val onboardingCompleted = mock() - whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS) + whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.STRIPE_EXTENSION_GATEWAY) whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) assertFalse(sut()) } @Test - fun `given ipp onboarding is WCPayNotInstalled, then return false`() = testBlocking { - val onboardingCompleted = CardReaderOnboardingState.WcpayNotInstalled - whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) + fun `given onboarding not completed when supported internally, when invoked, then return true`() = testBlocking { + whenever(isWooPosPaymentsOnboardingSupportedInternally()).thenReturn(true) + val onboardingNotCompleted = CardReaderOnboardingState.SetupNotCompleted( + preferredPlugin = PluginType.WOOCOMMERCE_PAYMENTS + ) + whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingNotCompleted) - assertFalse(sut()) + assertTrue(sut()) } @Test - fun `given ipp plugin is not woo payments, then return false`() = testBlocking { - val onboardingCompleted = mock() - whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.STRIPE_EXTENSION_GATEWAY) - whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) + fun `given onboarding not completed when not supported internally, when invoked, then return false`() = testBlocking { + whenever(isWooPosPaymentsOnboardingSupportedInternally()).thenReturn(false) + val onboardingNotCompleted = CardReaderOnboardingState.SetupNotCompleted( + preferredPlugin = PluginType.WOOCOMMERCE_PAYMENTS + ) + whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingNotCompleted) assertFalse(sut()) } @Test - fun `given feature flag disabled, then return false`() = testBlocking { - whenever(isRemoteFeatureFlagEnabled.invoke(WOO_POS)).thenReturn(false) - assertFalse(sut()) - } + fun `given IPP onboarding completed and plugin is WooCommerce Payments, when invoked, then return true`() = + testBlocking { + val onboardingCompleted = mock() + whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS) + whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) + + assertTrue(sut()) + } @Test fun `given woo version 6_5_0, when invoked, then return false`() = testBlocking { @@ -163,69 +156,11 @@ class WooPosIsEnabledTest : BaseUnitTest() { assertTrue(sut()) } - @Test - fun `given payment account cached, when invoked, then do not send remote request`() = testBlocking { - sut() // ensure it is cached - verify(ippStore, times(1)).loadAccount(any(), any()) - clearInvocations(ippStore) - - sut() - sut() - sut() - sut() - sut() - - verify(ippStore, never()).loadAccount(any(), any()) - } - - @Test - fun `given cached for siteA, when switched to siteB, then send remote request`() = testBlocking { - whenever(selectedSite.getOrNull()).thenReturn(SiteModel().also { it.id = 1 }) - sut() - - whenever(selectedSite.getOrNull()).thenReturn(SiteModel().also { it.id = 2 }) - sut() - - verify(ippStore, times(2)).loadAccount(any(), any()) - } - - @Test - fun `given onboarding supported internally and onboarding not completed, when sut run, then return true`() = testBlocking { - whenever(isWooPosPaymentsOnboardingSupportedInternally()).thenReturn(true) - val onboardingNotCompleted = CardReaderOnboardingState.SetupNotCompleted( - preferredPlugin = PluginType.WOOCOMMERCE_PAYMENTS - ) - whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingNotCompleted) - - assertTrue(sut()) - } - - @Test - fun `given onboarding not supported internally and onboarding not completed, when sut run, then return false`() = - testBlocking { - whenever(isWooPosPaymentsOnboardingSupportedInternally()).thenReturn(false) - val onboardingNotCompleted = CardReaderOnboardingState.SetupNotCompleted( - preferredPlugin = PluginType.WOOCOMMERCE_PAYMENTS - ) - whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingNotCompleted) - - assertFalse(sut()) - } - - private fun buildPaymentAccountResult( + private fun buildSiteSettings( countryCode: String = "US", - defaultCurrency: String = "USD" - ) = WooResult( - WCPaymentAccountResult( - status = mock(), - hasPendingRequirements = false, - hasOverdueRequirements = false, - currentDeadline = null, - statementDescriptor = "", - storeCurrencies = StoreCurrencies(defaultCurrency, listOf(defaultCurrency)), - country = countryCode, - isLive = true, - testMode = false, - ) - ) + currencyCode: String = "USD" + ) = mock { + on { this.countryCode }.thenReturn(countryCode) + on { this.currencyCode }.thenReturn(currencyCode) + } } From ad138a98ef6a0b57bfdb735ccd1a486f32c83c00 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 12 Nov 2024 11:15:18 +0100 Subject: [PATCH 6/6] Updated release notes --- RELEASE-NOTES.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 0fb9b3a5e43..fa7d018f570 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,6 +1,9 @@ *** PLEASE FOLLOW THIS FORMAT: [] [] *** Use [*****] to indicate smoke tests of all critical flows should be run on the final APK before release (e.g. major library or targetSdk updates). *** For entries which are touching the Android Wear app's, start entry with `[WEAR]` too. +21.2 +- [Internal] Changed a way how authenticated web view opened in the IPP flows [https://github.com/woocommerce/woocommerce-android/pull/12908] + 21.1 ----- - [*] Show web views on the payments hub screen in 3/4 of the screen [https://github.com/woocommerce/woocommerce-android/pull/12875]