feat: route provider sessions to ABSDK and simulation
This commit is contained in:
+77
@@ -1,5 +1,6 @@
|
||||
package com.flagship.abox.manager.testing.fakes
|
||||
|
||||
import com.flagship.abox.manager.domain.CredentialStore
|
||||
import com.flagship.abox.manager.domain.DomainError
|
||||
import com.flagship.abox.manager.domain.DomainResult
|
||||
import com.flagship.abox.manager.domain.LoginCredentials
|
||||
@@ -9,6 +10,8 @@ import com.flagship.abox.manager.domain.ProviderProfile
|
||||
import com.flagship.abox.manager.domain.ProviderProfileId
|
||||
import com.flagship.abox.manager.domain.ProviderType
|
||||
import com.flagship.abox.manager.domain.SessionCoordinator
|
||||
import com.flagship.abox.manager.domain.SessionGateway
|
||||
import com.flagship.abox.manager.domain.Session
|
||||
import com.flagship.abox.manager.domain.Username
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.test.runTest
|
||||
@@ -41,6 +44,37 @@ class SessionCoordinatorTest {
|
||||
assertNull(fixture.remote.observeSession(localProfile.id).first())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun localSelectionCreatesSessionWithoutAboxOrCredentialAccess() = runTest {
|
||||
val remote = CountingSessionGateway()
|
||||
val credentialsStore = CountingCredentialStore()
|
||||
val coordinator = SessionCoordinator(
|
||||
FakeProviderProfileStore(),
|
||||
credentialsStore,
|
||||
remote,
|
||||
FakeLocalSessionGateway(),
|
||||
)
|
||||
|
||||
val result = coordinator.selectProvider(localProfile)
|
||||
|
||||
assertTrue(result is DomainResult.Success)
|
||||
assertEquals(0, remote.loginCalls)
|
||||
assertEquals(0, credentialsStore.loadCalls + credentialsStore.saveCalls)
|
||||
assertEquals(localProfile.id, coordinator.observeActiveSession().first()?.profileId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aboxAuthenticationFailureDoesNotCreateSession() = runTest {
|
||||
val fixture = Fixture()
|
||||
fixture.coordinator.selectProvider(remoteProfile)
|
||||
fixture.remote.failLogin(remoteProfile.id, DomainError.Authentication())
|
||||
|
||||
val result = fixture.coordinator.login(remoteProfile.id, credentials, false, false)
|
||||
|
||||
assertTrue(result is DomainResult.Failure)
|
||||
assertNull(fixture.coordinator.observeActiveSession().first())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loginPersistsIndependentUsernameAndAutoLoginChoices() = runTest {
|
||||
val fixture = Fixture()
|
||||
@@ -126,4 +160,47 @@ class SessionCoordinatorTest {
|
||||
private val local = FakeLocalSessionGateway()
|
||||
val coordinator = SessionCoordinator(profiles, credentials, remote, local)
|
||||
}
|
||||
|
||||
private class CountingSessionGateway(
|
||||
private val delegate: FakeSessionGateway = FakeSessionGateway(),
|
||||
) : SessionGateway by delegate {
|
||||
var loginCalls = 0
|
||||
private set
|
||||
|
||||
override suspend fun login(
|
||||
profileId: ProviderProfileId,
|
||||
credentials: LoginCredentials,
|
||||
): DomainResult<Session> {
|
||||
loginCalls++
|
||||
return delegate.login(profileId, credentials)
|
||||
}
|
||||
|
||||
fun failLogin(profileId: ProviderProfileId, error: DomainError) {
|
||||
delegate.failLogin(profileId, error)
|
||||
}
|
||||
}
|
||||
|
||||
private class CountingCredentialStore(
|
||||
private val delegate: FakeCredentialStore = FakeCredentialStore(),
|
||||
) : CredentialStore by delegate {
|
||||
var loadCalls = 0
|
||||
private set
|
||||
var saveCalls = 0
|
||||
private set
|
||||
|
||||
override suspend fun loadCredentials(
|
||||
profileId: ProviderProfileId,
|
||||
): DomainResult<LoginCredentials?> {
|
||||
loadCalls++
|
||||
return delegate.loadCredentials(profileId)
|
||||
}
|
||||
|
||||
override suspend fun saveCredentials(
|
||||
profileId: ProviderProfileId,
|
||||
credentials: LoginCredentials,
|
||||
): DomainResult<Unit> {
|
||||
saveCalls++
|
||||
return delegate.saveCredentials(profileId, credentials)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user