Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1baac935 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

refactor(auth): move legacy retry scope into auth failure policy

parent 0488051a
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ data class LegacyLoadFailure(
    val storeType: StoreType? = null,
    val authError: AuthError? = null,
    val loginMode: PlayStoreLoginMode? = null,
    val storesToResetOnRetry: List<AuthStore> = emptyList(),
    @StringRes val dialogTitleRes: Int = R.string.data_load_error,
    @StringRes val dialogMessageRes: Int = R.string.data_load_error_desc,
) {
@@ -74,6 +75,10 @@ data class LegacyLoadFailure(
                storeType = storeType,
                authError = authError,
                loginMode = loginMode,
                storesToResetOnRetry = resolveStoresToResetOnRetry(
                    exception = exception,
                    authError = authError,
                ),
                dialogTitleRes = dialogSpec.titleRes,
                dialogMessageRes = dialogSpec.messageRes,
            )
@@ -237,6 +242,21 @@ private fun resolveDialogSpec(
    }
}

private fun resolveStoresToResetOnRetry(
    exception: Exception,
    authError: AuthError?,
): List<AuthStore> {
    return when {
        authError is AuthError.InvalidToken && authError.store == AuthStore.PLAY_STORE ->
            listOf(AuthStore.PLAY_STORE)

        exception is GPlayValidationException ->
            listOf(AuthStore.PLAY_STORE)

        else -> emptyList()
    }
}

private data class LegacyLoadDialogSpec(
    @StringRes val titleRes: Int = R.string.data_load_error,
    @StringRes val messageRes: Int = R.string.data_load_error_desc,
+1 −6
Original line number Diff line number Diff line
@@ -31,10 +31,8 @@ import androidx.lifecycle.Observer
import foundation.e.apps.R
import foundation.e.apps.data.login.core.StoreType
import foundation.e.apps.data.login.exceptions.GPlayLoginException
import foundation.e.apps.data.login.exceptions.GPlayValidationException
import foundation.e.apps.data.system.NetworkStatusManager
import foundation.e.apps.databinding.DialogErrorLogBinding
import foundation.e.apps.domain.auth.AuthStore
import foundation.e.apps.domain.auth.PlayStoreLoginMode
import foundation.e.apps.feature.auth.login.LoginUiEvent
import foundation.e.apps.feature.auth.login.LoginViewModel
@@ -191,10 +189,7 @@ class LegacyLoadFailureDialogs(
            setView(dialogView.root)
            setPositiveButton(R.string.retry) { _, _ ->
                callbacks.showLoading()
                when (exception) {
                    is GPlayValidationException -> sessionViewModel.refreshSessions(listOf(AuthStore.PLAY_STORE))
                    else -> sessionViewModel.refreshSessions()
                }
                sessionViewModel.refreshSessions(failure.storesToResetOnRetry)
            }
            setNegativeButton(R.string.logout) { _, _ ->
                loginViewModel.onEvent(LoginUiEvent.LogoutRequested)
+16 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ class LegacyLoadFailureTest {
        assertThat(failure.kind).isEqualTo(LegacyLoadFailureKind.SIGN_IN)
        assertThat(failure.loginMode).isEqualTo(PlayStoreLoginMode.MICROG)
        assertThat(failure.exception).isInstanceOf(GPlayValidationException::class.java)
        assertThat(failure.storesToResetOnRetry).containsExactly(AuthStore.PLAY_STORE)
    }

    @Test
@@ -80,5 +81,20 @@ class LegacyLoadFailureTest {

        assertThat(failure.kind).isEqualTo(LegacyLoadFailureKind.SIGN_IN)
        assertThat(failure.loginMode).isEqualTo(PlayStoreLoginMode.ANONYMOUS)
        assertThat(failure.storesToResetOnRetry).containsExactly(AuthStore.PLAY_STORE)
    }

    @Test
    fun `login required failures keep full session retry scope`() {
        val failure = AuthError.LoginRequired(
            store = AuthStore.PLAY_STORE,
            message = "sign in again",
        ).toLegacyLoadFailure(
            storeType = StoreType.PLAY_STORE,
            loginMode = PlayStoreLoginMode.GOOGLE,
        )

        assertThat(failure.kind).isEqualTo(LegacyLoadFailureKind.SIGN_IN)
        assertThat(failure.storesToResetOnRetry).isEmpty()
    }
}