Add test on RustClientSessionDelegate
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.impl
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.impl.fixtures.factories.aRustSession
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.aSessionData
|
||||
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class RustClientSessionDelegateTest {
|
||||
@Test
|
||||
fun `saveSessionInKeychain should update the store`() = runTest {
|
||||
val sessionStore = InMemorySessionStore()
|
||||
sessionStore.storeData(
|
||||
aSessionData(
|
||||
accessToken = "anAccessToken",
|
||||
refreshToken = "aRefreshToken",
|
||||
)
|
||||
)
|
||||
val sut = aRustClientSessionDelegate(sessionStore)
|
||||
sut.saveSessionInKeychain(
|
||||
aRustSession(
|
||||
accessToken = "at",
|
||||
refreshToken = "rt",
|
||||
)
|
||||
)
|
||||
runCurrent()
|
||||
val result = sessionStore.getLatestSession()
|
||||
assertThat(result!!.accessToken).isEqualTo("at")
|
||||
assertThat(result.refreshToken).isEqualTo("rt")
|
||||
}
|
||||
}
|
||||
|
||||
fun TestScope.aRustClientSessionDelegate(
|
||||
sessionStore: SessionStore = InMemorySessionStore(),
|
||||
) = RustClientSessionDelegate(
|
||||
sessionStore = sessionStore,
|
||||
appCoroutineScope = this,
|
||||
coroutineDispatchers = testCoroutineDispatchers(),
|
||||
)
|
||||
@@ -37,10 +37,8 @@ class RustMatrixClientTest {
|
||||
baseDirectory = File(""),
|
||||
sessionStore = InMemorySessionStore(),
|
||||
appCoroutineScope = this,
|
||||
sessionDelegate = RustClientSessionDelegate(
|
||||
sessionDelegate = aRustClientSessionDelegate(
|
||||
sessionStore = sessionStore,
|
||||
appCoroutineScope = this,
|
||||
coroutineDispatchers = testCoroutineDispatchers(),
|
||||
),
|
||||
syncService = FakeRustSyncService(),
|
||||
dispatchers = testCoroutineDispatchers(),
|
||||
|
||||
@@ -14,11 +14,13 @@ import org.matrix.rustcomponents.sdk.Session
|
||||
import org.matrix.rustcomponents.sdk.SlidingSyncVersion
|
||||
|
||||
internal fun aRustSession(
|
||||
proxy: SlidingSyncVersion = SlidingSyncVersion.None
|
||||
proxy: SlidingSyncVersion = SlidingSyncVersion.None,
|
||||
accessToken: String = "accessToken",
|
||||
refreshToken: String = "refreshToken",
|
||||
): Session {
|
||||
return Session(
|
||||
accessToken = "accessToken",
|
||||
refreshToken = "refreshToken",
|
||||
accessToken = accessToken,
|
||||
refreshToken = refreshToken,
|
||||
userId = A_USER_ID.value,
|
||||
deviceId = A_DEVICE_ID.value,
|
||||
homeserverUrl = A_HOMESERVER_URL,
|
||||
|
||||
@@ -16,12 +16,14 @@ fun aSessionData(
|
||||
isTokenValid: Boolean = false,
|
||||
sessionPath: String = "/a/path/to/a/session",
|
||||
cachePath: String = "/a/path/to/a/cache",
|
||||
): SessionData {
|
||||
accessToken: String = "anAccessToken",
|
||||
refreshToken: String? = "aRefreshToken",
|
||||
): SessionData {
|
||||
return SessionData(
|
||||
userId = sessionId,
|
||||
deviceId = deviceId,
|
||||
accessToken = "anAccessToken",
|
||||
refreshToken = "aRefreshToken",
|
||||
accessToken = accessToken,
|
||||
refreshToken = refreshToken,
|
||||
homeserverUrl = "aHomeserverUrl",
|
||||
oidcData = null,
|
||||
slidingSyncProxy = null,
|
||||
|
||||
Reference in New Issue
Block a user