Skip to content

Commit

Permalink
Remove logged out check
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Oct 7, 2024
1 parent ba3ae15 commit 02ca344
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.stripe.android.model.PaymentMethodCreateParams
import com.stripe.android.payments.core.analytics.ErrorReporter
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import javax.inject.Inject

Expand Down Expand Up @@ -218,15 +217,6 @@ internal class LinkAccountManager @Inject constructor(
}
}

/**
* Whether the user has logged out from any account.
*/
suspend fun hasUserLoggedOut(email: String?): Boolean {
return email == null ||
linkAccount.value?.email != email ||
accountStatus.first() == AccountStatus.SignedOut
}

private fun setAccount(
consumerSession: ConsumerSession,
publishableKey: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.stripe.android.core.strings.ResolvableString
import com.stripe.android.uicore.elements.PhoneNumberController
import com.stripe.android.uicore.elements.TextFieldController

data class SignUpScreenState(
internal data class SignUpScreenState(
val emailController: TextFieldController,
val phoneNumberController: PhoneNumberController,
val nameController: TextFieldController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ internal class SignUpViewModel @Inject constructor(
internal var navController: NavHostController? = null
private val _state = MutableStateFlow(
value = SignUpScreenState(
emailController = EmailConfig.createController(""),
emailController = EmailConfig.createController(
initialValue = args.configuration.customerInfo.email
),
phoneNumberController = PhoneNumberController.createPhoneNumberController(
initialValue = args.configuration.customerInfo.phone.orEmpty(),
initiallySelectedCountryCode = args.configuration.customerInfo.billingCountryCode
),
nameController = NameConfig.createController(""),
nameController = NameConfig.createController(
initialValue = args.configuration.customerInfo.name
),
signUpEnabled = false
)
)
Expand All @@ -62,9 +67,6 @@ internal class SignUpViewModel @Inject constructor(
}

init {
viewModelScope.launch {
loadScreen()
}
viewModelScope.launch {
signUpEnabledListener()
}
Expand All @@ -74,19 +76,6 @@ internal class SignUpViewModel @Inject constructor(
linkEventsReporter.onSignupFlowPresented()
}

private suspend fun loadScreen() {
val isLoggedOut = linkAccountManager.hasUserLoggedOut(args.configuration.customerInfo.email)
_state.value.emailController.onRawValueChange(
rawValue = args.configuration.customerInfo.email.takeUnless { isLoggedOut } ?: ""
)
_state.value.phoneNumberController.onRawValueChange(
rawValue = args.configuration.customerInfo.email.takeUnless { isLoggedOut } ?: ""
)
_state.value.nameController.onRawValueChange(
rawValue = args.configuration.customerInfo.name.takeUnless { isLoggedOut } ?: ""
)
}

private suspend fun signUpEnabledListener() {
_state.flatMapLatest { state ->
combine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,49 +430,6 @@ class LinkAccountManagerTest {
assertThat(accountManager.linkAccount.value).isNotNull()
}

@Test
fun `hasUserLoggedOut is true when email is null`() = runSuspendTest {
val accountManager = accountManager()

assertThat(accountManager.hasUserLoggedOut(null)).isTrue()
}

@Test
fun `hasUserLoggedOut is true when email does not match link account`() = runSuspendTest {
val accountManager = accountManager()

accountManager.setLinkAccountFromLookupResult(
mockConsumerSessionLookup.copy(
consumerSession = mockConsumerSession.copy(
emailAddress = "${EMAIL}m"
)
),
startSession = true,
)

assertThat(accountManager.hasUserLoggedOut(EMAIL)).isTrue()
}

@Test
fun `hasUserLoggedOut is true when there is no link account`() = runSuspendTest {
val accountManager = accountManager()

assertThat(accountManager.hasUserLoggedOut(EMAIL)).isTrue()
}

@Test
fun `hasUserLoggedOut is false when there is a link account with the same email and valid status`() =
runSuspendTest {
val accountManager = accountManager()

accountManager.setLinkAccountFromLookupResult(
mockConsumerSessionLookup,
startSession = true,
)

assertThat(accountManager.hasUserLoggedOut(EMAIL)).isFalse()
}

private fun runSuspendTest(testBody: suspend TestScope.() -> Unit) = runTest {
setupRepository()
testBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,57 +79,31 @@ internal class LinkAnalyticsHelperTest {
}
}

private open class FakeLinkEventsReporter : LinkEventsReporter {
internal open class FakeLinkEventsReporter : LinkEventsReporter {
var calledCount = 0
override fun onInvalidSessionState(state: LinkEventsReporter.SessionState) {
throw NotImplementedError()
}
override fun onInvalidSessionState(state: LinkEventsReporter.SessionState) = Unit

override fun onInlineSignupCheckboxChecked() {
throw NotImplementedError()
}
override fun onInlineSignupCheckboxChecked() = Unit

override fun onSignupFlowPresented() {
throw NotImplementedError()
}
override fun onSignupFlowPresented() = Unit

override fun onSignupStarted(isInline: Boolean) {
throw NotImplementedError()
}
override fun onSignupStarted(isInline: Boolean) = Unit

override fun onSignupCompleted(isInline: Boolean) {
throw NotImplementedError()
}
override fun onSignupCompleted(isInline: Boolean) = Unit

override fun onSignupFailure(isInline: Boolean, error: Throwable) {
throw NotImplementedError()
}
override fun onSignupFailure(isInline: Boolean, error: Throwable) = Unit

override fun onAccountLookupFailure(error: Throwable) {
throw NotImplementedError()
}
override fun onAccountLookupFailure(error: Throwable) = Unit

override fun onPopupShow() {
throw NotImplementedError()
}
override fun onPopupShow() = Unit

override fun onPopupSuccess() {
throw NotImplementedError()
}
override fun onPopupSuccess() = Unit

override fun onPopupCancel() {
throw NotImplementedError()
}
override fun onPopupCancel() = Unit

override fun onPopupError(error: Throwable) {
throw NotImplementedError()
}
override fun onPopupError(error: Throwable) = Unit

override fun onPopupLogout() {
throw NotImplementedError()
}
override fun onPopupLogout() = Unit

override fun onPopupSkipped() {
throw NotImplementedError()
}
override fun onPopupSkipped() = Unit
}
Loading

0 comments on commit 02ca344

Please sign in to comment.