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

Commit f5cbe2b1 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

refactor: complete auth boundary cleanup for login and source selection

parent bdad7141
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import foundation.e.apps.feature.auth.session.SessionStateController
import foundation.e.apps.updates.PeriodicUpdatesScheduler
import javax.inject.Inject

class UpdateSourceSelectionUseCase @Inject constructor(
class UpdateSourceSelectionCoordinator @Inject constructor(
    private val pendingUpdatesRepository: PendingUpdatesRepository,
    private val periodicUpdatesScheduler: PeriodicUpdatesScheduler,
    private val sessionStateController: SessionStateController,
+3 −3
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import foundation.e.apps.domain.source.AppSource
import foundation.e.apps.domain.source.SourceSelection
import foundation.e.apps.domain.source.SourceSelectionRepository
import foundation.e.apps.feature.auth.session.SessionRefreshException
import foundation.e.apps.feature.auth.source.UpdateSourceSelectionUseCase
import foundation.e.apps.feature.auth.source.UpdateSourceSelectionCoordinator
import foundation.e.apps.updates.PeriodicUpdatesScheduler
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
@@ -50,7 +50,7 @@ class SettingsViewModel @Inject constructor(
    private val authSessionRepository: AuthSessionRepository,
    private val playStoreAccountRepository: PlayStoreAccountRepository,
    private val sourceSelectionRepository: SourceSelectionRepository,
    private val updateSourceSelectionUseCase: UpdateSourceSelectionUseCase,
    private val updateSourceSelectionCoordinator: UpdateSourceSelectionCoordinator,
    private val periodicUpdatesScheduler: PeriodicUpdatesScheduler,
) : ViewModel() {
    private sealed interface SourceSelectionRequestOutcome {
@@ -101,7 +101,7 @@ class SettingsViewModel @Inject constructor(
    ) {
        viewModelScope.launch {
            try {
                updateSourceSelectionUseCase(sourceSelection)
                updateSourceSelectionCoordinator(sourceSelection)
            } catch (exception: IOException) {
                Timber.e(exception, "Failed to update source selection")
            } catch (exception: SessionRefreshException) {
+2 −2
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ class LoginWorkflowCoordinatorTest {

    private val authRefreshSnapshotState = MutableStateFlow<AuthRefreshSnapshot?>(null)
    private val currentSessionState = MutableStateFlow<AuthSession>(AuthSession.Unauthenticated)
    private val playCredentialState = object : PlayCredentialState {}
    private val preparedPlayLogin = object : PreparedPlayLogin {}
    private val playCredentialState = PlayCredentialState.fromOpaqueValue("credential-state")
    private val preparedPlayLogin = PreparedPlayLogin.fromOpaqueValue("prepared-play-login")

    @Mock
    private lateinit var anonymousLoginUseCase: AnonymousLoginUseCase
+3 −3
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.test.runTest
import org.junit.Test

class UpdateSourceSelectionUseCaseTest {
class UpdateSourceSelectionCoordinatorTest {

    @Test
    fun `invoke persists selection reschedules updates clears pending updates and refreshes sessions`() = runTest {
@@ -44,7 +44,7 @@ class UpdateSourceSelectionUseCaseTest {
        val sourceSelectionRepository = FakeSourceSelectionRepository(SourceSelection.DEFAULT)
        val periodicUpdatesScheduler = mockk<PeriodicUpdatesScheduler>(relaxed = true)
        val sessionStateController = FakeSessionStateController()
        val useCase = UpdateSourceSelectionUseCase(
        val coordinator = UpdateSourceSelectionCoordinator(
            pendingUpdatesRepository = pendingUpdatesRepository,
            periodicUpdatesScheduler = periodicUpdatesScheduler,
            sessionStateController = sessionStateController,
@@ -52,7 +52,7 @@ class UpdateSourceSelectionUseCaseTest {
        )
        val updatedSelection = SourceSelection.OPEN_SOURCE_AND_PWA

        useCase(updatedSelection)
        coordinator(updatedSelection)

        assertThat(sourceSelectionRepository.currentSourceSelection()).isEqualTo(updatedSelection)
        assertThat(pendingUpdatesRepository.clearPendingUpdatesCallCount).isEqualTo(1)
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import foundation.e.apps.domain.source.AppSource
import foundation.e.apps.domain.source.SourceSelection
import foundation.e.apps.domain.source.SourceSelectionRepository
import foundation.e.apps.domain.updates.PendingUpdatesRepository
import foundation.e.apps.feature.auth.source.UpdateSourceSelectionUseCase
import foundation.e.apps.feature.auth.source.UpdateSourceSelectionCoordinator
import foundation.e.apps.feature.auth.session.SessionStateController
import foundation.e.apps.util.MainCoroutineRule
import foundation.e.apps.updates.PeriodicUpdatesScheduler
@@ -238,7 +238,7 @@ class SettingsViewModelTest {
            authSessionRepository = FakeAuthSessionRepository(session),
            playStoreAccountRepository = FakePlayStoreAccountRepository(account),
            sourceSelectionRepository = sourceSelectionRepository,
            updateSourceSelectionUseCase = UpdateSourceSelectionUseCase(
            updateSourceSelectionCoordinator = UpdateSourceSelectionCoordinator(
                pendingUpdatesRepository = FakePendingUpdatesRepository(),
                periodicUpdatesScheduler = mockk<PeriodicUpdatesScheduler>(relaxed = true),
                sessionStateController = sessionStateController,
Loading