Rename API and update test.
This commit is contained in:
committed by
Benoit Marty
parent
06bcbb8bb8
commit
8e819d48ed
@@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
interface SessionStore {
|
||||
fun isLoggedIn(): Flow<LoggedInState>
|
||||
fun loggedInStateFlow(): Flow<LoggedInState>
|
||||
fun sessionsFlow(): Flow<List<SessionData>>
|
||||
suspend fun addSession(sessionData: SessionData)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class DatabaseSessionStore(
|
||||
) : SessionStore {
|
||||
private val sessionDataMutex = Mutex()
|
||||
|
||||
override fun isLoggedIn(): Flow<LoggedInState> {
|
||||
override fun loggedInStateFlow(): Flow<LoggedInState> {
|
||||
return database.sessionDataQueries.selectFirst()
|
||||
.asFlow()
|
||||
.mapToOneOrNull(dispatchers.io)
|
||||
|
||||
@@ -54,12 +54,14 @@ class DatabaseSessionStoreTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isLoggedIn emits true while there are sessions in the DB`() = runTest {
|
||||
databaseSessionStore.isLoggedIn().test {
|
||||
fun `loggedInStateFlow emits LoggedIn while there are sessions in the DB`() = runTest {
|
||||
databaseSessionStore.loggedInStateFlow().test {
|
||||
assertThat(awaitItem()).isEqualTo(LoggedInState.NotLoggedIn)
|
||||
database.sessionDataQueries.insertSessionData(aSessionData)
|
||||
databaseSessionStore.addSession(aSessionData.toApiModel())
|
||||
assertThat(awaitItem()).isEqualTo(LoggedInState.LoggedIn(sessionId = aSessionData.userId, isTokenValid = true))
|
||||
database.sessionDataQueries.removeSession(aSessionData.userId)
|
||||
// TODO add more sessions in multi-account PR.
|
||||
// Remove the first session
|
||||
databaseSessionStore.removeSession(aSessionData.userId)
|
||||
assertThat(awaitItem()).isEqualTo(LoggedInState.NotLoggedIn)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class InMemorySessionStore(
|
||||
) : SessionStore {
|
||||
private val sessionDataListFlow = MutableStateFlow(initialList)
|
||||
|
||||
override fun isLoggedIn(): Flow<LoggedInState> {
|
||||
override fun loggedInStateFlow(): Flow<LoggedInState> {
|
||||
return sessionDataListFlow.map {
|
||||
if (it.isEmpty()) {
|
||||
LoggedInState.NotLoggedIn
|
||||
|
||||
Reference in New Issue
Block a user