-
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.
Add tests in `RealCreateInstantDebitsResultTest` to ensure the endpoint is called correctly.
- Loading branch information
1 parent
3be015b
commit 2d0ba4c
Showing
14 changed files
with
186 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,7 @@ internal object ApiKeyFixtures { | |
) | ||
|
||
fun consumerSessionSignup() = ConsumerSessionSignup( | ||
accountId = "acct_123", | ||
publishableKey = "pk_123", | ||
consumerSession = consumerSession().copy( | ||
verificationSessions = listOf( | ||
|
@@ -163,7 +164,10 @@ internal object ApiKeyFixtures { | |
), | ||
) | ||
|
||
fun cachedConsumerSession() = CachedConsumerSession( | ||
fun cachedConsumerSession( | ||
accountId: String? = null, | ||
) = CachedConsumerSession( | ||
accountId = accountId, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(***) *** **12", | ||
|
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 |
---|---|---|
|
@@ -108,6 +108,7 @@ internal class PollAttachPaymentAccountTest { | |
) | ||
|
||
private fun cachedConsumerSession() = CachedConsumerSession( | ||
accountId = null, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
isVerified = true, | ||
|
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 |
---|---|---|
@@ -1,21 +1,27 @@ | ||
package com.stripe.android.financialconnections.domain | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsSessionContext | ||
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsSessionContext.BillingDetails | ||
import com.stripe.android.financialconnections.repository.CachedConsumerSession | ||
import com.stripe.android.financialconnections.repository.FinancialConnectionsConsumerSessionRepository | ||
import com.stripe.android.financialconnections.repository.FinancialConnectionsRepository | ||
import com.stripe.android.model.ConsumerPaymentDetails | ||
import com.stripe.android.model.IncentiveEligibilitySession | ||
import com.stripe.android.model.LinkConsumerIncentive | ||
import com.stripe.android.model.LinkMode | ||
import com.stripe.android.model.SharePaymentDetails | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.anyOrNull | ||
import org.mockito.kotlin.doReturn | ||
import org.mockito.kotlin.eq | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.verifyNoInteractions | ||
import org.mockito.kotlin.whenever | ||
|
||
class RealCreateInstantDebitsResultTest { | ||
|
||
|
@@ -167,6 +173,96 @@ class RealCreateInstantDebitsResultTest { | |
) | ||
} | ||
|
||
@Test | ||
fun `Skips checking available incentives if not incentive eligible`() = runTest { | ||
val consumerRepository = makeConsumerSessionRepository() | ||
val repository = makeRepository() | ||
|
||
val createInstantDebitResult = RealCreateInstantDebitsResult( | ||
consumerRepository = consumerRepository, | ||
repository = repository, | ||
consumerSessionProvider = { makeCachedConsumerSession("acct_789") }, | ||
elementsSessionContext = makeElementsSessionContext( | ||
linkMode = LinkMode.LinkPaymentMethod, | ||
incentiveEligibilitySession = null, | ||
), | ||
) | ||
|
||
val result = createInstantDebitResult("bank_account_id_001") | ||
|
||
verify(consumerRepository, never()).updateAvailableIncentives( | ||
sessionId = any(), | ||
consumerAccount = any(), | ||
) | ||
|
||
assertThat(result.eligibleForIncentive).isFalse() | ||
} | ||
|
||
@Test | ||
fun `Skips checking available incentives if no signup happened in the flow`() = runTest { | ||
val consumerRepository = makeConsumerSessionRepository() | ||
val repository = makeRepository() | ||
|
||
val createInstantDebitResult = RealCreateInstantDebitsResult( | ||
consumerRepository = consumerRepository, | ||
repository = repository, | ||
consumerSessionProvider = { | ||
// A missing account ID means no signup happened | ||
makeCachedConsumerSession(accountId = null) | ||
}, | ||
elementsSessionContext = makeElementsSessionContext( | ||
linkMode = LinkMode.LinkPaymentMethod, | ||
incentiveEligibilitySession = IncentiveEligibilitySession.PaymentIntent("pi_123"), | ||
), | ||
) | ||
|
||
val result = createInstantDebitResult("bank_account_id_001") | ||
|
||
verify(consumerRepository, never()).updateAvailableIncentives( | ||
sessionId = any(), | ||
consumerAccount = any(), | ||
) | ||
|
||
assertThat(result.eligibleForIncentive).isFalse() | ||
} | ||
|
||
@Test | ||
fun `Checks available incentives if eligible`() = runTest { | ||
val consumerRepository = makeConsumerSessionRepository() | ||
val repository = makeRepository() | ||
|
||
val createInstantDebitResult = RealCreateInstantDebitsResult( | ||
consumerRepository = consumerRepository, | ||
repository = repository, | ||
consumerSessionProvider = { makeCachedConsumerSession("acct_789") }, | ||
elementsSessionContext = makeElementsSessionContext( | ||
linkMode = LinkMode.LinkPaymentMethod, | ||
incentiveEligibilitySession = IncentiveEligibilitySession.PaymentIntent("pi_123"), | ||
), | ||
) | ||
|
||
whenever( | ||
consumerRepository.updateAvailableIncentives( | ||
sessionId = eq("pi_123"), | ||
consumerAccount = eq("acct_789"), | ||
) | ||
).thenReturn( | ||
UpdateAvailableIncentives( | ||
data = listOf( | ||
LinkConsumerIncentive( | ||
incentiveParams = LinkConsumerIncentive.IncentiveParams( | ||
paymentMethod = "link_instant_debits", | ||
), | ||
incentiveDisplayText = "$5", | ||
) | ||
) | ||
) | ||
) | ||
|
||
val result = createInstantDebitResult("bank_account_id_001") | ||
assertThat(result.eligibleForIncentive).isTrue() | ||
} | ||
|
||
private fun makeConsumerSessionRepository(): FinancialConnectionsConsumerSessionRepository { | ||
val consumerPaymentDetails = ConsumerPaymentDetails( | ||
paymentDetails = listOf( | ||
|
@@ -199,8 +295,11 @@ class RealCreateInstantDebitsResultTest { | |
} | ||
} | ||
|
||
private fun makeCachedConsumerSession(): CachedConsumerSession { | ||
private fun makeCachedConsumerSession( | ||
accountId: String? = null, | ||
): CachedConsumerSession { | ||
return CachedConsumerSession( | ||
accountId = accountId, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(***) *** **12", | ||
|
@@ -212,6 +311,7 @@ class RealCreateInstantDebitsResultTest { | |
private fun makeElementsSessionContext( | ||
linkMode: LinkMode?, | ||
billingDetails: BillingDetails? = null, | ||
incentiveEligibilitySession: IncentiveEligibilitySession? = null, | ||
): ElementsSessionContext { | ||
return ElementsSessionContext( | ||
amount = 100L, | ||
|
@@ -223,7 +323,7 @@ class RealCreateInstantDebitsResultTest { | |
phone = null, | ||
phoneCountryCode = null, | ||
), | ||
incentiveEligibilitySession = null, | ||
incentiveEligibilitySession = incentiveEligibilitySession, | ||
) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -277,6 +277,7 @@ internal class AccountPickerViewModelTest { | |
@Test | ||
fun `Saves selected accounts to Link if we have a consumer session`() = runTest { | ||
val consumerSession = CachedConsumerSession( | ||
accountId = null, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(***) *** **12", | ||
|
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
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 |
---|---|---|
|
@@ -75,6 +75,7 @@ class FinancialConnectionsConsumerSessionRepositoryImplTest { | |
) | ||
|
||
val consumerSessionSignup = ConsumerSessionSignup( | ||
accountId = "acct_123", | ||
consumerSession = consumerSession, | ||
publishableKey = "pk_123", | ||
) | ||
|
@@ -111,6 +112,7 @@ class FinancialConnectionsConsumerSessionRepositoryImplTest { | |
// ensures there's a cached consumer session after the signup call. | ||
assertThat(repository.getCachedConsumerSession()).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = "acct_123", | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) ••• ••12", | ||
|
@@ -132,6 +134,7 @@ class FinancialConnectionsConsumerSessionRepositoryImplTest { | |
) | ||
|
||
val consumerSessionSignup = ConsumerSessionSignup( | ||
accountId = "acct_123", | ||
consumerSession = consumerSession, | ||
publishableKey = "pk_123", | ||
) | ||
|
@@ -212,6 +215,7 @@ class FinancialConnectionsConsumerSessionRepositoryImplTest { | |
// ensures there's a cached consumer session after the lookup call. | ||
assertThat(repository.getCachedConsumerSession()).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = null, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) ••• ••12", | ||
|
@@ -267,6 +271,7 @@ class FinancialConnectionsConsumerSessionRepositoryImplTest { | |
// ensures there's a cached consumer session after the start-verification call. | ||
assertThat(repository.getCachedConsumerSession()).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = null, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) ••• ••12", | ||
|
@@ -316,6 +321,7 @@ class FinancialConnectionsConsumerSessionRepositoryImplTest { | |
// ensures there's a cached consumer session after the confirm-verification call. | ||
assertThat(repository.getCachedConsumerSession()).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = null, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) ••• ••12", | ||
|
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ class RealConsumerSessionRepositoryTest { | |
val cachedSession = store.provideConsumerSession() | ||
assertThat(cachedSession).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = null, | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) •••-1234", | ||
clientSecret = "abc_123", | ||
|
@@ -42,6 +43,7 @@ class RealConsumerSessionRepositoryTest { | |
val cachedSession = store.provideConsumerSession() | ||
assertThat(cachedSession).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = null, | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) •••-1234", | ||
clientSecret = "abc_123", | ||
|
@@ -52,7 +54,7 @@ class RealConsumerSessionRepositoryTest { | |
} | ||
|
||
@Test | ||
fun `Keeps existing publishable key when storing updated consumer session`() { | ||
fun `Keeps existing publishable key and account ID when storing updated consumer session`() { | ||
val store = RealConsumerSessionRepository(savedStateHandle = SavedStateHandle()) | ||
|
||
val session1 = makeConsumerSession( | ||
|
@@ -65,12 +67,13 @@ class RealConsumerSessionRepositoryTest { | |
isVerified = true, | ||
) | ||
|
||
store.storeNewConsumerSession(session1, publishableKey = "pk_123") | ||
store.storeNewConsumerSession(session1, publishableKey = "pk_123", accountId = "acct_123") | ||
store.updateConsumerSession(session2) | ||
|
||
val cachedSession = store.provideConsumerSession() | ||
assertThat(cachedSession).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = "acct_123", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) •••-1234", | ||
clientSecret = "abc_123", | ||
|
@@ -94,12 +97,13 @@ class RealConsumerSessionRepositoryTest { | |
isVerified = false, | ||
) | ||
|
||
store.storeNewConsumerSession(session1, publishableKey = "pk_123") | ||
store.storeNewConsumerSession(session2, publishableKey = "pk_456") | ||
store.storeNewConsumerSession(session1, publishableKey = "pk_123", accountId = "acct_123") | ||
store.storeNewConsumerSession(session2, publishableKey = "pk_456", accountId = "acct_456") | ||
|
||
val cachedSession = store.provideConsumerSession() | ||
assertThat(cachedSession).isEqualTo( | ||
CachedConsumerSession( | ||
accountId = "acct_456", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(•••) •••-1234", | ||
clientSecret = "abc_456", | ||
|
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 |
---|---|---|
|
@@ -106,6 +106,7 @@ class RealProvideApiRequestOptionsTest { | |
publishableKey: String?, | ||
): CachedConsumerSession { | ||
return CachedConsumerSession( | ||
accountId = null, | ||
clientSecret = "clientSecret", | ||
emailAddress = "[email protected]", | ||
phoneNumber = "(***) *** **12", | ||
|
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ internal object TestFactory { | |
|
||
const val EMAIL = "[email protected]" | ||
const val CLIENT_SECRET = "client_secret" | ||
const val ACCOUNT_ID = "acct_123" | ||
const val PUBLISHABLE_KEY = "publishable_key" | ||
const val MERCHANT_NAME = "merchantName" | ||
const val CUSTOMER_EMAIL = "[email protected]" | ||
|
@@ -55,6 +56,7 @@ internal object TestFactory { | |
) | ||
|
||
val CONSUMER_SESSION_SIGN_UP = ConsumerSessionSignup( | ||
accountId = ACCOUNT_ID, | ||
consumerSession = CONSUMER_SESSION, | ||
publishableKey = PUBLISHABLE_KEY | ||
) | ||
|
Oops, something went wrong.