Skip to content

Commit 80fa442

Browse files
committed
Rename API and update test.
1 parent 65d682f commit 80fa442

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

libraries/session-storage/api/src/main/kotlin/io/element/android/libraries/sessionstorage/api/SessionStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.Flow
1111
import kotlinx.coroutines.flow.map
1212

1313
interface SessionStore {
14-
fun isLoggedIn(): Flow<LoggedInState>
14+
fun loggedInStateFlow(): Flow<LoggedInState>
1515
fun sessionsFlow(): Flow<List<SessionData>>
1616
suspend fun addSession(sessionData: SessionData)
1717

libraries/session-storage/impl/src/main/kotlin/io/element/android/libraries/sessionstorage/impl/DatabaseSessionStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DatabaseSessionStore(
3333
) : SessionStore {
3434
private val sessionDataMutex = Mutex()
3535

36-
override fun isLoggedIn(): Flow<LoggedInState> {
36+
override fun loggedInStateFlow(): Flow<LoggedInState> {
3737
return database.sessionDataQueries.selectFirst()
3838
.asFlow()
3939
.mapToOneOrNull(dispatchers.io)

libraries/session-storage/impl/src/test/kotlin/io/element/android/libraries/sessionstorage/impl/DatabaseSessionStoreTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ class DatabaseSessionStoreTest {
5454
}
5555

5656
@Test
57-
fun `isLoggedIn emits true while there are sessions in the DB`() = runTest {
58-
databaseSessionStore.isLoggedIn().test {
57+
fun `loggedInStateFlow emits LoggedIn while there are sessions in the DB`() = runTest {
58+
databaseSessionStore.loggedInStateFlow().test {
5959
assertThat(awaitItem()).isEqualTo(LoggedInState.NotLoggedIn)
60-
database.sessionDataQueries.insertSessionData(aSessionData)
60+
databaseSessionStore.addSession(aSessionData.toApiModel())
6161
assertThat(awaitItem()).isEqualTo(LoggedInState.LoggedIn(sessionId = aSessionData.userId, isTokenValid = true))
62-
database.sessionDataQueries.removeSession(aSessionData.userId)
62+
// TODO add more sessions in multi-account PR.
63+
// Remove the first session
64+
databaseSessionStore.removeSession(aSessionData.userId)
6365
assertThat(awaitItem()).isEqualTo(LoggedInState.NotLoggedIn)
6466
}
6567
}

libraries/session-storage/test/src/main/kotlin/io/element/android/libraries/sessionstorage/test/InMemorySessionStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class InMemorySessionStore(
2020
) : SessionStore {
2121
private val sessionDataListFlow = MutableStateFlow(initialList)
2222

23-
override fun isLoggedIn(): Flow<LoggedInState> {
23+
override fun loggedInStateFlow(): Flow<LoggedInState> {
2424
return sessionDataListFlow.map {
2525
if (it.isEmpty()) {
2626
LoggedInState.NotLoggedIn

0 commit comments

Comments
 (0)