Add test on RustClientSessionDelegate
This commit is contained in:
parent
fc795c9be8
commit
cc78096d87
4 changed files with 64 additions and 9 deletions
|
|
@ -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(""),
|
baseDirectory = File(""),
|
||||||
sessionStore = InMemorySessionStore(),
|
sessionStore = InMemorySessionStore(),
|
||||||
appCoroutineScope = this,
|
appCoroutineScope = this,
|
||||||
sessionDelegate = RustClientSessionDelegate(
|
sessionDelegate = aRustClientSessionDelegate(
|
||||||
sessionStore = sessionStore,
|
sessionStore = sessionStore,
|
||||||
appCoroutineScope = this,
|
|
||||||
coroutineDispatchers = testCoroutineDispatchers(),
|
|
||||||
),
|
),
|
||||||
syncService = FakeRustSyncService(),
|
syncService = FakeRustSyncService(),
|
||||||
dispatchers = testCoroutineDispatchers(),
|
dispatchers = testCoroutineDispatchers(),
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,13 @@ import org.matrix.rustcomponents.sdk.Session
|
||||||
import org.matrix.rustcomponents.sdk.SlidingSyncVersion
|
import org.matrix.rustcomponents.sdk.SlidingSyncVersion
|
||||||
|
|
||||||
internal fun aRustSession(
|
internal fun aRustSession(
|
||||||
proxy: SlidingSyncVersion = SlidingSyncVersion.None
|
proxy: SlidingSyncVersion = SlidingSyncVersion.None,
|
||||||
|
accessToken: String = "accessToken",
|
||||||
|
refreshToken: String = "refreshToken",
|
||||||
): Session {
|
): Session {
|
||||||
return Session(
|
return Session(
|
||||||
accessToken = "accessToken",
|
accessToken = accessToken,
|
||||||
refreshToken = "refreshToken",
|
refreshToken = refreshToken,
|
||||||
userId = A_USER_ID.value,
|
userId = A_USER_ID.value,
|
||||||
deviceId = A_DEVICE_ID.value,
|
deviceId = A_DEVICE_ID.value,
|
||||||
homeserverUrl = A_HOMESERVER_URL,
|
homeserverUrl = A_HOMESERVER_URL,
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,14 @@ fun aSessionData(
|
||||||
isTokenValid: Boolean = false,
|
isTokenValid: Boolean = false,
|
||||||
sessionPath: String = "/a/path/to/a/session",
|
sessionPath: String = "/a/path/to/a/session",
|
||||||
cachePath: String = "/a/path/to/a/cache",
|
cachePath: String = "/a/path/to/a/cache",
|
||||||
): SessionData {
|
accessToken: String = "anAccessToken",
|
||||||
|
refreshToken: String? = "aRefreshToken",
|
||||||
|
): SessionData {
|
||||||
return SessionData(
|
return SessionData(
|
||||||
userId = sessionId,
|
userId = sessionId,
|
||||||
deviceId = deviceId,
|
deviceId = deviceId,
|
||||||
accessToken = "anAccessToken",
|
accessToken = accessToken,
|
||||||
refreshToken = "aRefreshToken",
|
refreshToken = refreshToken,
|
||||||
homeserverUrl = "aHomeserverUrl",
|
homeserverUrl = "aHomeserverUrl",
|
||||||
oidcData = null,
|
oidcData = null,
|
||||||
slidingSyncProxy = null,
|
slidingSyncProxy = null,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue