mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Add test on RustClientSessionDelegate
This commit is contained in:
+53
@@ -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(),
|
||||||
|
)
|
||||||
+1
-3
@@ -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(),
|
||||||
|
|||||||
+5
-3
@@ -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,
|
||||||
|
|||||||
+4
-2
@@ -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",
|
||||||
|
accessToken: String = "anAccessToken",
|
||||||
|
refreshToken: String? = "aRefreshToken",
|
||||||
): SessionData {
|
): 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user