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 ec4901756b4..4f5bb0ee216 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 @@ -73,10 +73,10 @@ class WooPosIsEnabled @Inject constructor( is CardReaderOnboardingState.StripeAccountOverdueRequirement, is CardReaderOnboardingState.StripeAccountRejected, is CardReaderOnboardingState.StripeAccountUnderReview, + is CardReaderOnboardingState.StripeAccountPendingRequirement, CardReaderOnboardingState.WcpayNotActivated, CardReaderOnboardingState.WcpayNotInstalled -> false - is CardReaderOnboardingState.StripeAccountPendingRequirement, is CardReaderOnboardingState.OnboardingCompleted -> true } diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt index bca4610e06f..72395e022e2 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/statuschecker/CardReaderStatusCheckerViewModelTest.kt @@ -21,6 +21,7 @@ import org.junit.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.whenever +import java.math.BigDecimal @ExperimentalCoroutinesApi class CardReaderStatusCheckerViewModelTest : BaseUnitTest() { @@ -436,6 +437,75 @@ class CardReaderStatusCheckerViewModelTest : BaseUnitTest() { ) } + @Test + fun `given woo pos connection and onboarding failed with error, when vm init, then navigates to onboarding`() = + testBlocking { + // GIVEN + val param = CardReaderFlowParam.WooPosConnection + val onboardingState = CardReaderOnboardingState.StripeAccountRejected( + preferredPlugin = PluginType.WOOCOMMERCE_PAYMENTS, + ) + whenever(cardReaderChecker.getOnboardingState()).thenReturn(onboardingState) + + // WHEN + val vm = initViewModel(param) + + // THEN + assertThat(vm.event.value) + .isInstanceOf(CardReaderStatusCheckerViewModel.StatusCheckerEvent.NavigateToOnboarding::class.java) + } + + @Test + fun `given refund flow and not connected and error, when vm init, then navigates to onboarding with fail`() = + testBlocking { + // GIVEN + val orderId = 1L + val param = CardReaderFlowParam.PaymentOrRefund.Refund(orderId = orderId, BigDecimal.TEN) + whenever(cardReaderManager.readerStatus).thenReturn(MutableStateFlow(CardReaderStatus.NotConnected())) + val onboardingError = CardReaderOnboardingState.StripeAccountPendingRequirement( + dueDate = 0L, + preferredPlugin = PluginType.WOOCOMMERCE_PAYMENTS, + version = pluginVersion, + countryCode = countryCode + ) + whenever(cardReaderChecker.getOnboardingState()).thenReturn(onboardingError) + + // WHEN + val vm = initViewModel(param) + + // THEN + assertThat(vm.event.value) + .isEqualTo( + CardReaderStatusCheckerViewModel.StatusCheckerEvent.NavigateToOnboarding( + CardReaderOnboardingParams.Failed(param, onboardingError), + CardReaderType.EXTERNAL + ) + ) + } + + @Test + fun `given card reader hub flow and not connected and error, when vm init, then navigates to onboarding with fail`() = + testBlocking { + // GIVEN + val param = CardReaderFlowParam.CardReadersHub() + val onboardingError = CardReaderOnboardingState.StripeAccountPendingRequirement( + dueDate = 0L, + preferredPlugin = PluginType.WOOCOMMERCE_PAYMENTS, + version = pluginVersion, + countryCode = countryCode + ) + whenever(cardReaderChecker.getOnboardingState()).thenReturn(onboardingError) + + // WHEN + val vm = initViewModel(param) + + // THEN + assertThat(vm.event.value) + .isInstanceOf( + CardReaderStatusCheckerViewModel.StatusCheckerEvent.NavigateToOnboarding::class.java + ) + } + private fun initViewModel( param: CardReaderFlowParam, cardReaderType: CardReaderType = CardReaderType.EXTERNAL 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 f9374ba5681..39260ccef3d 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 @@ -102,12 +102,12 @@ class WooPosIsEnabledTest : BaseUnitTest() { } @Test - fun `given ipp onboarding is Pending Requirements, then return true`() = testBlocking { + fun `given ipp onboarding is Pending Requirements, then return false`() = testBlocking { val onboardingCompleted = mock() whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS) whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted) - assertTrue(sut()) + assertFalse(sut()) } @Test