Skip to content

Add check if plugin setup is completed #11549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2024
Merged
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
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,13 +87,27 @@ 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)
whenever(ippStore.loadAccount(any(), any())).thenReturn(result)
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",
Expand Down
Loading