Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Nov 22, 2024
1 parent 51c82c1 commit 16e7772
Showing 1 changed file with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1446,7 +1469,7 @@ class USBankAccountFormViewModelTest {
)
}

private fun mockUnverifiedBankAccount(): CollectBankAccountResultInternal.Completed {
private fun mockManuallyEnteredBankAccount(usesMicrodeposits: Boolean): CollectBankAccountResultInternal.Completed {
val paymentIntent = mock<PaymentIntent>()
val financialConnectionsSession = mock<FinancialConnectionsSession>()
whenever(paymentIntent.id).thenReturn(defaultArgs.clientSecret)
Expand All @@ -1464,7 +1487,8 @@ class USBankAccountFormViewModelTest {
CollectBankAccountResponseInternal(
intent = paymentIntent,
usBankAccountData = CollectBankAccountResponseInternal.USBankAccountData(
financialConnectionsSession = financialConnectionsSession
financialConnectionsSession = financialConnectionsSession,
usesMicrodeposits = usesMicrodeposits,
),
instantDebitsData = null
)
Expand All @@ -1491,7 +1515,8 @@ class USBankAccountFormViewModelTest {
CollectBankAccountResponseInternal(
intent = paymentIntent,
usBankAccountData = CollectBankAccountResponseInternal.USBankAccountData(
financialConnectionsSession = financialConnectionsSession
financialConnectionsSession = financialConnectionsSession,
usesMicrodeposits = false,
),
instantDebitsData = null
)
Expand Down

0 comments on commit 16e7772

Please sign in to comment.