From 16e77722a934fa03a19be74d929fa205da6213f2 Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Fri, 22 Nov 2024 11:17:51 -0500 Subject: [PATCH] Add test --- .../ach/USBankAccountFormViewModelTest.kt | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt index ca6e5a4159f..0073916d450 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt @@ -152,7 +152,7 @@ class USBankAccountFormViewModelTest { viewModel.linkedAccount.test { skipItems(1) - viewModel.handleCollectBankAccountResult(mockUnverifiedBankAccount()) + viewModel.handleCollectBankAccountResult(mockManuallyEnteredBankAccount(usesMicrodeposits = true)) val screenState = awaitItem()?.screenState assertThat(screenState?.linkedBankAccount?.isVerifyingWithMicrodeposits).isTrue() @@ -173,7 +173,7 @@ class USBankAccountFormViewModelTest { @Test fun `Transitions to correct screen state when collecting an unverified bank account in custom flow`() = runTest { val viewModel = createViewModel(defaultArgs.copy(isCompleteFlow = false)) - val bankAccount = mockUnverifiedBankAccount() + val bankAccount = mockManuallyEnteredBankAccount(usesMicrodeposits = true) viewModel.linkedAccount.test { skipItems(1) @@ -1034,7 +1034,30 @@ class USBankAccountFormViewModelTest { viewModel.currentScreenState.test { assertThat(awaitItem().linkedBankAccount).isNull() - val unverifiedAccount = mockUnverifiedBankAccount() + val unverifiedAccount = mockManuallyEnteredBankAccount(usesMicrodeposits = true) + viewModel.handleCollectBankAccountResult(unverifiedAccount) + + val mandateCollectionViewState = awaitItem() + assertThat(mandateCollectionViewState.linkedBankAccount?.mandateText).isEqualTo(expectedResult) + } + } + + @Test + fun `Produces correct mandate text when skipping verification for manually entered account`() = runTest { + val viewModel = createViewModel() + + val expectedResult = USBankAccountTextBuilder.buildMandateAndMicrodepositsText( + merchantName = MERCHANT_NAME, + isVerifyingMicrodeposits = false, + isSaveForFutureUseSelected = false, + isSetupFlow = false, + isInstantDebits = false, + ) + + viewModel.currentScreenState.test { + assertThat(awaitItem().linkedBankAccount).isNull() + + val unverifiedAccount = mockManuallyEnteredBankAccount(usesMicrodeposits = false) viewModel.handleCollectBankAccountResult(unverifiedAccount) val mandateCollectionViewState = awaitItem() @@ -1446,7 +1469,7 @@ class USBankAccountFormViewModelTest { ) } - private fun mockUnverifiedBankAccount(): CollectBankAccountResultInternal.Completed { + private fun mockManuallyEnteredBankAccount(usesMicrodeposits: Boolean): CollectBankAccountResultInternal.Completed { val paymentIntent = mock() val financialConnectionsSession = mock() whenever(paymentIntent.id).thenReturn(defaultArgs.clientSecret) @@ -1464,7 +1487,8 @@ class USBankAccountFormViewModelTest { CollectBankAccountResponseInternal( intent = paymentIntent, usBankAccountData = CollectBankAccountResponseInternal.USBankAccountData( - financialConnectionsSession = financialConnectionsSession + financialConnectionsSession = financialConnectionsSession, + usesMicrodeposits = usesMicrodeposits, ), instantDebitsData = null ) @@ -1491,7 +1515,8 @@ class USBankAccountFormViewModelTest { CollectBankAccountResponseInternal( intent = paymentIntent, usBankAccountData = CollectBankAccountResponseInternal.USBankAccountData( - financialConnectionsSession = financialConnectionsSession + financialConnectionsSession = financialConnectionsSession, + usesMicrodeposits = false, ), instantDebitsData = null )