-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
656119b
commit 439af93
Showing
6 changed files
with
309 additions
and
75 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
98 changes: 98 additions & 0 deletions
98
...nancialconnections/features/networkinglinksignup/LinkSignupHandlerForInstantDebitsTest.kt
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.stripe.android.financialconnections.features.networkinglinksignup; | ||
|
||
import com.stripe.android.financialconnections.domain.AttachConsumerToLinkAccountSession | ||
import com.stripe.android.financialconnections.domain.GetOrFetchSync | ||
import com.stripe.android.financialconnections.domain.HandleError | ||
import com.stripe.android.financialconnections.features.networkinglinksignup.NetworkingLinkSignupState.Payload | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane | ||
import com.stripe.android.financialconnections.navigation.NavigationManager | ||
import com.stripe.android.financialconnections.presentation.Async | ||
import com.stripe.android.financialconnections.repository.FinancialConnectionsConsumerSessionRepository | ||
import com.stripe.attestation.IntegrityRequestManager | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class LinkSignupHandlerForInstantDebitsTest { | ||
|
||
private lateinit var handler: LinkSignupHandlerForInstantDebits | ||
private val consumerRepository = mock<FinancialConnectionsConsumerSessionRepository>() | ||
private val getOrFetchSync = mock<GetOrFetchSync>() | ||
private val attachConsumerToLinkAccountSession = mock<AttachConsumerToLinkAccountSession>() | ||
private val integrityRequestManager = mock<IntegrityRequestManager>() | ||
private val navigationManager = mock<NavigationManager>() | ||
private val handleError = mock<HandleError>() | ||
|
||
@Before | ||
fun setUp() { | ||
handler = LinkSignupHandlerForInstantDebits( | ||
consumerRepository, | ||
attachConsumerToLinkAccountSession, | ||
integrityRequestManager, | ||
getOrFetchSync, | ||
navigationManager, | ||
"applicationId", | ||
handleError | ||
) | ||
} | ||
|
||
private val validPayload = Payload( | ||
merchantName = "Mock Merchant", | ||
emailController = mock(), | ||
appVerificationEnabled = false, | ||
phoneController = mock { | ||
whenever(it.getCountryCode()).thenReturn("US") | ||
}, | ||
isInstantDebits = true, | ||
content = mock() | ||
) | ||
|
||
@Test | ||
fun `performSignup should navigate to next pane on success`() = runTest { | ||
val testState = NetworkingLinkSignupState( | ||
validEmail = "[email protected]", | ||
validPhone = "+123456789", | ||
isInstantDebits = true, | ||
payload = Async.Success(validPayload) | ||
) | ||
|
||
val expectedPane = Pane.INSTITUTION_PICKER | ||
whenever(getOrFetchSync()).thenReturn(mock { | ||
whenever(it.manifest).thenReturn(mock { | ||
whenever(it.nextPane).thenReturn(expectedPane) | ||
}) | ||
}) | ||
whenever( | ||
consumerRepository.mobileSignUp( | ||
email = any(), | ||
phoneNumber = any(), | ||
country = any(), | ||
verificationToken = any(), | ||
appId = any() | ||
) | ||
).thenReturn(mock()) | ||
|
||
val result = handler.performSignup(testState) | ||
|
||
verify(attachConsumerToLinkAccountSession).invoke(any()) | ||
assertEquals(expectedPane, result) | ||
} | ||
|
||
@Test | ||
fun `handleSignupFailure should call handleError with correct parameters`() = runTest { | ||
val error = RuntimeException("Test Error") | ||
handler.handleSignupFailure(error) | ||
|
||
verify(handleError).invoke( | ||
extraMessage = "Error creating a Link account", | ||
error = error, | ||
pane = Pane.LINK_LOGIN, | ||
displayErrorScreen = true | ||
) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
payments-model/src/main/java/com/stripe/android/model/SignUpParams.kt
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.stripe.android.model; | ||
|
||
import androidx.annotation.RestrictTo | ||
import java.util.Locale | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) | ||
data class SignUpParams( | ||
val email: String, | ||
val phoneNumber: String, | ||
val country: String, | ||
val name: String?, | ||
val locale: Locale?, | ||
val amount: Long?, | ||
val currency: String?, | ||
val incentiveEligibilitySession: IncentiveEligibilitySession?, | ||
val requestSurface: String, | ||
val consentAction: ConsumerSignUpConsentAction, | ||
val verificationToken: String? = null, | ||
val appId: String? = null | ||
) { | ||
fun toParamMap(): Map<String, *> { | ||
val params = mutableMapOf( | ||
"email_address" to email.lowercase(), | ||
"phone_number" to phoneNumber, | ||
"country" to country, | ||
"country_inferring_method" to "PHONE_NUMBER", | ||
"amount" to amount, | ||
"currency" to currency, | ||
"consent_action" to consentAction.value, | ||
"request_surface" to requestSurface | ||
) | ||
|
||
locale?.let { | ||
params["locale"] = it.toLanguageTag() | ||
} | ||
|
||
name?.let { | ||
params["legal_name"] = it | ||
} | ||
|
||
verificationToken?.let { | ||
params["android_verification_token"] = it | ||
} | ||
|
||
appId?.let { | ||
params["app_id"] = it | ||
} | ||
|
||
params.putAll(incentiveEligibilitySession?.toParamMap().orEmpty()) | ||
|
||
return params.toMap() | ||
} | ||
} | ||
|
Oops, something went wrong.