@@ -1167,6 +1167,7 @@ internal class PaymentSheetViewModelTest {
1167
1167
val error = APIException ()
1168
1168
1169
1169
viewModel.updateSelection(selection)
1170
+ viewModel.checkout()
1170
1171
1171
1172
viewModel.paymentMethodMetadata.test {
1172
1173
confirmationHandler.state.value = ConfirmationHandler .State .Complete (
@@ -2596,6 +2597,37 @@ internal class PaymentSheetViewModelTest {
2596
2597
assertThat(paymentSuccessCall.paymentSelection).isEqualTo(PaymentSelection .GooglePay )
2597
2598
}
2598
2599
2600
+ @Test
2601
+ fun `On checkout with Google Pay, should report failure as expected` () = runTest {
2602
+ val confirmationHandler = FakeConfirmationHandler ().apply {
2603
+ awaitResultTurbine.add(null )
2604
+ awaitResultTurbine.add(null )
2605
+ }
2606
+ val eventReporter = FakeEventReporter ()
2607
+ val viewModel = createViewModel(
2608
+ args = ARGS_CUSTOMER_WITH_GOOGLEPAY ,
2609
+ isGooglePayReady = true ,
2610
+ eventReporter = eventReporter,
2611
+ confirmationHandlerFactory = {
2612
+ confirmationHandler
2613
+ }
2614
+ )
2615
+
2616
+ viewModel.checkoutWithGooglePay()
2617
+
2618
+ confirmationHandler.state.value = ConfirmationHandler .State .Complete (
2619
+ ConfirmationHandler .Result .Failed (
2620
+ cause = IllegalStateException (" This failed!" ),
2621
+ message = " This failed" .resolvableString,
2622
+ type = ConfirmationHandler .Result .Failed .ErrorType .GooglePay (errorCode = 10 ),
2623
+ )
2624
+ )
2625
+
2626
+ val paymentFailureCall = eventReporter.paymentFailureCalls.awaitItem()
2627
+
2628
+ assertThat(paymentFailureCall.paymentSelection).isEqualTo(PaymentSelection .GooglePay )
2629
+ }
2630
+
2599
2631
@Test
2600
2632
fun `On checkout with Link, should report success as expected` () = runTest {
2601
2633
val confirmationHandler = FakeConfirmationHandler ().apply {
@@ -2630,6 +2662,41 @@ internal class PaymentSheetViewModelTest {
2630
2662
assertThat(paymentSuccessCall.paymentSelection).isEqualTo(PaymentSelection .Link (useLinkExpress = false ))
2631
2663
}
2632
2664
2665
+ @Test
2666
+ fun `On checkout with Link, should report failure as expected` () = runTest {
2667
+ val confirmationHandler = FakeConfirmationHandler ().apply {
2668
+ awaitResultTurbine.add(null )
2669
+ awaitResultTurbine.add(null )
2670
+ }
2671
+ val eventReporter = FakeEventReporter ()
2672
+ val viewModel = createViewModel(
2673
+ args = ARGS_CUSTOMER_WITH_GOOGLEPAY ,
2674
+ linkState = LinkState (
2675
+ configuration = LINK_CONFIG ,
2676
+ loginState = LinkState .LoginState .LoggedOut ,
2677
+ signupMode = null
2678
+ ),
2679
+ eventReporter = eventReporter,
2680
+ confirmationHandlerFactory = {
2681
+ confirmationHandler
2682
+ }
2683
+ )
2684
+
2685
+ viewModel.checkoutWithLink()
2686
+
2687
+ confirmationHandler.state.value = ConfirmationHandler .State .Complete (
2688
+ ConfirmationHandler .Result .Failed (
2689
+ cause = IllegalStateException (" This failed!" ),
2690
+ message = " This failed" .resolvableString,
2691
+ type = ConfirmationHandler .Result .Failed .ErrorType .GooglePay (errorCode = 10 ),
2692
+ )
2693
+ )
2694
+
2695
+ val paymentFailureCall = eventReporter.paymentFailureCalls.awaitItem()
2696
+
2697
+ assertThat(paymentFailureCall.paymentSelection).isEqualTo(PaymentSelection .Link (useLinkExpress = false ))
2698
+ }
2699
+
2633
2700
@Test
2634
2701
fun `On checkout with Link Express, should report success as expected` () = runTest {
2635
2702
val confirmationHandler = FakeConfirmationHandler ().apply {
@@ -2664,6 +2731,41 @@ internal class PaymentSheetViewModelTest {
2664
2731
assertThat(paymentSuccessCall.paymentSelection).isEqualTo(PaymentSelection .Link (useLinkExpress = true ))
2665
2732
}
2666
2733
2734
+ @Test
2735
+ fun `On checkout with Link Express, should report failure as expected` () = runTest {
2736
+ val confirmationHandler = FakeConfirmationHandler ().apply {
2737
+ awaitResultTurbine.add(null )
2738
+ awaitResultTurbine.add(null )
2739
+ }
2740
+ val eventReporter = FakeEventReporter ()
2741
+
2742
+ createViewModel(
2743
+ args = ARGS_CUSTOMER_WITH_GOOGLEPAY ,
2744
+ linkState = LinkState (
2745
+ configuration = LINK_CONFIG ,
2746
+ loginState = LinkState .LoginState .LoggedIn ,
2747
+ signupMode = null
2748
+ ),
2749
+ linkConfigurationCoordinator = FakeLinkConfigurationCoordinator (),
2750
+ eventReporter = eventReporter,
2751
+ confirmationHandlerFactory = {
2752
+ confirmationHandler
2753
+ }
2754
+ )
2755
+
2756
+ confirmationHandler.state.value = ConfirmationHandler .State .Complete (
2757
+ ConfirmationHandler .Result .Failed (
2758
+ cause = IllegalStateException (" This failed!" ),
2759
+ message = " This failed" .resolvableString,
2760
+ type = ConfirmationHandler .Result .Failed .ErrorType .GooglePay (errorCode = 10 ),
2761
+ )
2762
+ )
2763
+
2764
+ val paymentFailureCall = eventReporter.paymentFailureCalls.awaitItem()
2765
+
2766
+ assertThat(paymentFailureCall.paymentSelection).isEqualTo(PaymentSelection .Link (useLinkExpress = true ))
2767
+ }
2768
+
2667
2769
@Test
2668
2770
fun `Can complete payment after switching to another LPM from card selection with inline Link signup state` () =
2669
2771
runTest {
0 commit comments