Skip to content

Commit

Permalink
Merge pull request #12178 from woocommerce/issue/11612-skip-stripe-pe…
Browse files Browse the repository at this point in the history
…nding-error-pos

Woo POS: Skip Stripe Pending Error in POS Mode
  • Loading branch information
malinajirka authored Aug 5, 2024
2 parents 45364a1 + faa6679 commit e8750e7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CardReaderOnboardingState.StripeAccountPendingRequirement>()
whenever(onboardingCompleted.preferredPlugin).thenReturn(PluginType.WOOCOMMERCE_PAYMENTS)
whenever(cardReaderOnboardingChecker.getOnboardingState()).thenReturn(onboardingCompleted)

assertTrue(sut())
assertFalse(sut())
}

@Test
Expand Down

0 comments on commit e8750e7

Please sign in to comment.