Skip to content

Commit

Permalink
use startSession
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Jan 29, 2025
1 parent 2ee9a21 commit 7b949db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,21 @@ internal class DefaultLinkAuth @Inject constructor(
return signupResult.toLinkAuthResult()
}

override suspend fun lookUp(email: String, emailSource: EmailSource): LinkAuthResult {
override suspend fun lookUp(
email: String,
emailSource: EmailSource,
startSession: Boolean
): LinkAuthResult {
val lookupResult = if (linkGate.useAttestationEndpoints) {
mobileLookUp(
email = email,
emailSource = emailSource
emailSource = emailSource,
startSession = startSession
)
} else {
linkAccountManager.lookupConsumer(
email = email,
startSession = true
startSession = startSession
)
}
return lookupResult.toLinkAuthResult()
Expand Down Expand Up @@ -82,7 +87,8 @@ internal class DefaultLinkAuth @Inject constructor(

private suspend fun mobileLookUp(
email: String,
emailSource: EmailSource
emailSource: EmailSource,
startSession: Boolean
): Result<LinkAccount?> {
return runCatching {
val verificationToken = integrityRequestManager.requestToken().getOrThrow()
Expand All @@ -91,7 +97,7 @@ internal class DefaultLinkAuth @Inject constructor(
emailSource = emailSource,
verificationToken = verificationToken,
appId = applicationId,
startSession = true
startSession = startSession
).getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal interface LinkAuth {
suspend fun lookUp(
email: String,
emailSource: EmailSource,
startSession: Boolean
): LinkAuthResult
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ internal class DefaultLinkAuthTest {

val result = linkAuth.lookUp(
email = TestFactory.CUSTOMER_EMAIL,
emailSource = TestFactory.EMAIL_SOURCE
emailSource = TestFactory.EMAIL_SOURCE,
startSession = true
)

val accountManagerCall = linkAccountManager.awaitMobileLookupCall()
Expand Down Expand Up @@ -279,7 +280,8 @@ internal class DefaultLinkAuthTest {

val result = linkAuth.lookUp(
email = TestFactory.CUSTOMER_EMAIL,
emailSource = TestFactory.EMAIL_SOURCE
emailSource = TestFactory.EMAIL_SOURCE,
startSession = false
)

integrityRequestManager.awaitRequestTokenCall()
Expand Down Expand Up @@ -308,7 +310,8 @@ internal class DefaultLinkAuthTest {

val result = linkAuth.lookUp(
email = TestFactory.CUSTOMER_EMAIL,
emailSource = TestFactory.EMAIL_SOURCE
emailSource = TestFactory.EMAIL_SOURCE,
startSession = false
)

integrityRequestManager.awaitRequestTokenCall()
Expand All @@ -334,7 +337,8 @@ internal class DefaultLinkAuthTest {

val result = linkAuth.lookUp(
email = TestFactory.CUSTOMER_EMAIL,
emailSource = TestFactory.EMAIL_SOURCE
emailSource = TestFactory.EMAIL_SOURCE,
startSession = false
)

integrityRequestManager.awaitRequestTokenCall()
Expand All @@ -358,13 +362,14 @@ internal class DefaultLinkAuthTest {

val result = linkAuth.lookUp(
email = TestFactory.CUSTOMER_EMAIL,
emailSource = TestFactory.EMAIL_SOURCE
emailSource = TestFactory.EMAIL_SOURCE,
startSession = false
)

val accountManagerCall = linkAccountManager.awaitLookupCall()

assertThat(accountManagerCall.email).isEqualTo(TestFactory.CUSTOMER_EMAIL)
assertThat(accountManagerCall.startSession).isTrue()
assertThat(accountManagerCall.startSession).isFalse()

assertThat(result).isEqualTo(LinkAuthResult.Success(TestFactory.LINK_ACCOUNT))

Expand All @@ -388,7 +393,8 @@ internal class DefaultLinkAuthTest {

val result = linkAuth.lookUp(
email = TestFactory.CUSTOMER_EMAIL,
emailSource = TestFactory.EMAIL_SOURCE
emailSource = TestFactory.EMAIL_SOURCE,
startSession = true
)

val accountManagerCall = linkAccountManager.awaitLookupCall()
Expand Down Expand Up @@ -416,12 +422,14 @@ internal class DefaultLinkAuthTest {

val result = linkAuth.lookUp(
email = TestFactory.CUSTOMER_EMAIL,
emailSource = TestFactory.EMAIL_SOURCE
emailSource = TestFactory.EMAIL_SOURCE,
startSession = false
)

linkAccountManager.awaitMobileLookupCall()
val accountManagerCall = linkAccountManager.awaitMobileLookupCall()
integrityRequestManager.awaitRequestTokenCall()

assertThat(accountManagerCall.startSession).isFalse()
assertThat(result).isEqualTo(LinkAuthResult.NoLinkAccountFound)

linkAccountManager.ensureAllEventsConsumed()
Expand Down

0 comments on commit 7b949db

Please sign in to comment.