-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate layers in `LinkSignupHandler`.
- Loading branch information
1 parent
067813a
commit dba999b
Showing
4 changed files
with
126 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
...om/stripe/android/financialconnections/features/networkinglinksignup/PerformLinkSignup.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,18 @@ import app.cash.turbine.test | |
import com.google.common.truth.Truth.assertThat | ||
import com.stripe.android.core.Logger | ||
import com.stripe.android.core.exception.APIConnectionException | ||
import com.stripe.android.financialconnections.ApiKeyFixtures.cachedPartnerAccounts | ||
import com.stripe.android.financialconnections.ApiKeyFixtures.consumerSessionSignup | ||
import com.stripe.android.financialconnections.ApiKeyFixtures.sessionManifest | ||
import com.stripe.android.financialconnections.ApiKeyFixtures.syncResponse | ||
import com.stripe.android.financialconnections.CoroutineTestRule | ||
import com.stripe.android.financialconnections.TestFinancialConnectionsAnalyticsTracker | ||
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.ConsentAgree.analyticsValue | ||
import com.stripe.android.financialconnections.domain.GetCachedAccounts | ||
import com.stripe.android.financialconnections.domain.GetOrFetchSync | ||
import com.stripe.android.financialconnections.domain.LookupAccount | ||
import com.stripe.android.financialconnections.domain.NativeAuthFlowCoordinator | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane | ||
import com.stripe.android.financialconnections.domain.SaveAccountToLink | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane.LINK_LOGIN | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane.NETWORKING_LINK_SIGNUP_PANE | ||
import com.stripe.android.financialconnections.model.LinkLoginPane | ||
|
@@ -24,13 +27,16 @@ import com.stripe.android.financialconnections.navigation.Destination.Networking | |
import com.stripe.android.financialconnections.navigation.Destination.NetworkingSaveToLinkVerification | ||
import com.stripe.android.financialconnections.navigation.NavigationIntent | ||
import com.stripe.android.financialconnections.navigation.NavigationManagerImpl | ||
import com.stripe.android.financialconnections.repository.FinancialConnectionsConsumerSessionRepository | ||
import com.stripe.android.financialconnections.utils.UriUtils | ||
import com.stripe.android.model.ConsumerSessionLookup | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.doAnswer | ||
import org.mockito.kotlin.doReturn | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
|
||
|
@@ -185,7 +191,8 @@ class NetworkingLinkSignupViewModelTest { | |
val viewModel = buildViewModel( | ||
state = NetworkingLinkSignupState(isInstantDebits = true), | ||
signupHandler = mockLinkSignupHandlerForInstantDebits( | ||
performLinkSignup = { error("Not expected to call sign-up") }, | ||
// We don't expect a signup to be performed | ||
failOnSignup = true, | ||
), | ||
) | ||
|
||
|
@@ -222,7 +229,8 @@ class NetworkingLinkSignupViewModelTest { | |
val viewModel = buildViewModel( | ||
state = NetworkingLinkSignupState(), | ||
signupHandler = mockLinkSignupHandlerForNetworking( | ||
performLinkSignup = { error("Not expected to call sign-up") }, | ||
// We don't expect a signup to be performed | ||
failOnSignup = true, | ||
) | ||
) | ||
|
||
|
@@ -382,9 +390,7 @@ class NetworkingLinkSignupViewModelTest { | |
|
||
val viewModel = buildViewModel( | ||
state = NetworkingLinkSignupState(isInstantDebits = false), | ||
signupHandler = mockLinkSignupHandlerForNetworking( | ||
performLinkSignup = { throw APIConnectionException() }, | ||
), | ||
signupHandler = mockLinkSignupHandlerForNetworking(failOnSignup = true), | ||
) | ||
|
||
navigationManager.navigationFlow.test { | ||
|
@@ -418,9 +424,7 @@ class NetworkingLinkSignupViewModelTest { | |
|
||
val viewModel = buildViewModel( | ||
state = NetworkingLinkSignupState(isInstantDebits = true), | ||
signupHandler = mockLinkSignupHandlerForInstantDebits( | ||
performLinkSignup = { throw APIConnectionException() }, | ||
) | ||
signupHandler = mockLinkSignupHandlerForInstantDebits(failOnSignup = true), | ||
) | ||
|
||
navigationManager.navigationFlow.test { | ||
|
@@ -436,21 +440,79 @@ class NetworkingLinkSignupViewModelTest { | |
} | ||
|
||
private fun mockLinkSignupHandlerForNetworking( | ||
performLinkSignup: PerformLinkSignup = PerformLinkSignup { Pane.SUCCESS }, | ||
failOnSignup: Boolean = false, | ||
): LinkSignupHandler { | ||
val manifest = sessionManifest().copy( | ||
businessName = "Business", | ||
accountholderCustomerEmailAddress = "[email protected]" | ||
) | ||
|
||
val getOrFetchSync = mock<GetOrFetchSync> { | ||
onBlocking { invoke(any()) } doReturn syncResponse().copy( | ||
manifest = manifest, | ||
text = TextUpdate( | ||
consent = null, | ||
networkingLinkSignupPane = networkingLinkSignupPane(), | ||
) | ||
) | ||
} | ||
|
||
val getCachedAccounts = mock<GetCachedAccounts> { | ||
onBlocking { invoke() } doReturn cachedPartnerAccounts() | ||
} | ||
|
||
val saveAccountToLink = mock<SaveAccountToLink> { | ||
if (failOnSignup) { | ||
onBlocking { new(any(), any(), any(), any(), any()) } doAnswer { | ||
throw APIConnectionException() | ||
} | ||
} else { | ||
onBlocking { new(any(), any(), any(), any(), any()) } doReturn manifest | ||
} | ||
} | ||
|
||
return LinkSignupHandlerForNetworking( | ||
performLinkSignup = performLinkSignup, | ||
getOrFetchSync = getOrFetchSync, | ||
getCachedAccounts = getCachedAccounts, | ||
saveAccountToLink = saveAccountToLink, | ||
eventTracker = eventTracker, | ||
navigationManager = navigationManager, | ||
logger = Logger.noop(), | ||
) | ||
} | ||
|
||
private fun mockLinkSignupHandlerForInstantDebits( | ||
performLinkSignup: PerformLinkSignup = PerformLinkSignup { Pane.SUCCESS }, | ||
failOnSignup: Boolean = false, | ||
): LinkSignupHandler { | ||
val manifest = sessionManifest().copy( | ||
businessName = "Business", | ||
accountholderCustomerEmailAddress = "[email protected]" | ||
) | ||
|
||
val getOrFetchSync = mock<GetOrFetchSync> { | ||
onBlocking { invoke(any()) } doReturn syncResponse().copy( | ||
manifest = manifest, | ||
text = TextUpdate( | ||
consent = null, | ||
linkLoginPane = linkLoginPane(), | ||
) | ||
) | ||
} | ||
|
||
val consumerRepository = mock<FinancialConnectionsConsumerSessionRepository> { | ||
if (failOnSignup) { | ||
onBlocking { signUp(any(), any(), any()) } doAnswer { | ||
throw APIConnectionException() | ||
} | ||
} else { | ||
onBlocking { signUp(any(), any(), any()) } doReturn consumerSessionSignup() | ||
} | ||
} | ||
|
||
return LinkSignupHandlerForInstantDebits( | ||
performLinkSignup = performLinkSignup, | ||
getOrFetchSync = getOrFetchSync, | ||
consumerRepository = consumerRepository, | ||
attachConsumerToLinkAccountSession = { /** Success **/ }, | ||
eventTracker = eventTracker, | ||
navigationManager = navigationManager, | ||
logger = Logger.noop(), | ||
|