Rename API and update test.

This commit is contained in:
Benoit Marty
2025-09-05 15:59:36 +02:00
committed by Benoit Marty
parent 06bcbb8bb8
commit 8e819d48ed
4 changed files with 9 additions and 7 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
}
}

View File

@@ -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