diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabled.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabled.kt index 3bac3fd3135..30d6b6ef477 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabled.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabled.kt @@ -3,6 +3,7 @@ package com.woocommerce.android.ui.woopos import com.woocommerce.android.tools.SelectedSite import com.woocommerce.android.ui.payments.GetActivePaymentsPlugin import com.woocommerce.android.util.IsWindowClassExpandedAndBigger +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 javax.inject.Inject @@ -33,7 +34,12 @@ class IsWooPosEnabled @Inject constructor( countryCode.lowercase() == "us" && ippPlugin == WOOCOMMERCE_PAYMENTS && paymentAccount.storeCurrencies.default.lowercase() == "usd" && - isWindowSizeExpandedAndBigger() + isWindowSizeExpandedAndBigger() && + isPluginSetupEnabled(paymentAccount) ).also { cachedResult = it } } + + private fun isPluginSetupEnabled(paymentAccount: WCPaymentAccountResult): Boolean = + paymentAccount.status == WCPaymentAccountResult.WCPaymentAccountStatus.COMPLETE || + paymentAccount.status == WCPaymentAccountResult.WCPaymentAccountStatus.ENABLED } diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabledTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabledTest.kt index 684827174f8..41be32310be 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabledTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/IsWooPosEnabledTest.kt @@ -12,6 +12,7 @@ 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.COMPLETE +import org.wordpress.android.fluxc.model.payments.inperson.WCPaymentAccountResult.WCPaymentAccountStatus.ENABLED 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 @@ -86,6 +87,13 @@ class IsWooPosEnabledTest : BaseUnitTest() { assertFalse(sut()) } + @Test + fun `given woo payments setup not completed or enabled, then return false`() = testBlocking { + val result = buildPaymentAccountResult(status = WCPaymentAccountResult.WCPaymentAccountStatus.NO_ACCOUNT) + whenever(ippStore.loadAccount(any(), any())).thenReturn(result) + assertFalse(sut()) + } + @Test fun `given big enough screen, woo payments enabled, USD currency and store in the US, then return true`() = testBlocking { val result = buildPaymentAccountResult(defaultCurrency = "USD", countryCode = "US", status = COMPLETE) @@ -93,6 +101,13 @@ class IsWooPosEnabledTest : BaseUnitTest() { assertTrue(sut()) } + @Test + fun `given big enough screen, woo payments enabled, USD currency, store in the US, and status enabled, then return true`() = testBlocking { + val result = buildPaymentAccountResult(defaultCurrency = "USD", countryCode = "US", status = ENABLED) + whenever(ippStore.loadAccount(any(), any())).thenReturn(result) + assertTrue(sut()) + } + private fun buildPaymentAccountResult( status: WCPaymentAccountResult.WCPaymentAccountStatus = COMPLETE, countryCode: String = "US",