Cleanup tests.

This commit is contained in:
Benoit Marty 2025-09-01 15:03:41 +02:00
parent 75a640b986
commit 025131841b
9 changed files with 64 additions and 58 deletions

View file

@ -20,12 +20,12 @@ import org.junit.Test
class AppMigration02Test { class AppMigration02Test {
@Test @Test
fun `test migration`() = runTest { fun `test migration`() = runTest {
val sessionStore = InMemorySessionStore().apply { val sessionStore = InMemorySessionStore(
updateData(aSessionData()) initialList = listOf(aSessionData()),
} )
val sessionPreferencesStore = InMemorySessionPreferencesStore(isSessionVerificationSkipped = false) val sessionPreferencesStore = InMemorySessionPreferencesStore(isSessionVerificationSkipped = false)
val sessionPreferencesStoreFactory = FakeSessionPreferencesStoreFactory( val sessionPreferencesStoreFactory = FakeSessionPreferencesStoreFactory(
getLambda = lambdaRecorder { _, _, -> sessionPreferencesStore }, getLambda = lambdaRecorder { _, _ -> sessionPreferencesStore },
removeLambda = lambdaRecorder { _ -> } removeLambda = lambdaRecorder { _ -> }
) )
val migration = AppMigration02(sessionStore = sessionStore, sessionPreferenceStoreFactory = sessionPreferencesStoreFactory) val migration = AppMigration02(sessionStore = sessionStore, sessionPreferenceStoreFactory = sessionPreferencesStoreFactory)

View file

@ -18,14 +18,14 @@ import java.io.File
class AppMigration05Test { class AppMigration05Test {
@Test @Test
fun `empty session path should be set to an expected path`() = runTest { fun `empty session path should be set to an expected path`() = runTest {
val sessionStore = InMemorySessionStore().apply { val sessionStore = InMemorySessionStore(
updateData( initialList = listOf(
aSessionData( aSessionData(
sessionId = A_SESSION_ID.value, sessionId = A_SESSION_ID.value,
sessionPath = "", sessionPath = "",
) )
) )
} )
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path")) val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path"))
migration.migrate() migration.migrate()
val storedData = sessionStore.getSession(A_SESSION_ID.value)!! val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
@ -34,14 +34,14 @@ class AppMigration05Test {
@Test @Test
fun `non empty session path should not be impacted by the migration`() = runTest { fun `non empty session path should not be impacted by the migration`() = runTest {
val sessionStore = InMemorySessionStore().apply { val sessionStore = InMemorySessionStore(
updateData( initialList = listOf(
aSessionData( aSessionData(
sessionId = A_SESSION_ID.value, sessionId = A_SESSION_ID.value,
sessionPath = "/a/path/existing", sessionPath = "/a/path/existing",
) )
) )
} )
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path")) val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path"))
migration.migrate() migration.migrate()
val storedData = sessionStore.getSession(A_SESSION_ID.value)!! val storedData = sessionStore.getSession(A_SESSION_ID.value)!!

View file

@ -18,15 +18,15 @@ import java.io.File
class AppMigration06Test { class AppMigration06Test {
@Test @Test
fun `empty cache path should be set to an expected path`() = runTest { fun `empty cache path should be set to an expected path`() = runTest {
val sessionStore = InMemorySessionStore().apply { val sessionStore = InMemorySessionStore(
updateData( initialList = listOf(
aSessionData( aSessionData(
sessionId = A_SESSION_ID.value, sessionId = A_SESSION_ID.value,
sessionPath = "/a/path/to/a/session/AN_ID", sessionPath = "/a/path/to/a/session/AN_ID",
cachePath = "", cachePath = "",
) )
) )
} )
val migration = AppMigration06(sessionStore = sessionStore, cacheDirectory = File("/a/path/cache")) val migration = AppMigration06(sessionStore = sessionStore, cacheDirectory = File("/a/path/cache"))
migration.migrate() migration.migrate()
val storedData = sessionStore.getSession(A_SESSION_ID.value)!! val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
@ -35,14 +35,14 @@ class AppMigration06Test {
@Test @Test
fun `non empty cache path should not be impacted by the migration`() = runTest { fun `non empty cache path should not be impacted by the migration`() = runTest {
val sessionStore = InMemorySessionStore().apply { val sessionStore = InMemorySessionStore(
updateData( initialList = listOf(
aSessionData( aSessionData(
sessionId = A_SESSION_ID.value, sessionId = A_SESSION_ID.value,
cachePath = "/a/path/existing", cachePath = "/a/path/existing",
) )
) )
} )
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path/cache")) val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path/cache"))
migration.migrate() migration.migrate()
val storedData = sessionStore.getSession(A_SESSION_ID.value)!! val storedData = sessionStore.getSession(A_SESSION_ID.value)!!

View file

@ -104,9 +104,9 @@ class DefaultBugReporterTest {
) )
server.start() server.start()
val mockSessionStore = InMemorySessionStore().apply { val mockSessionStore = InMemorySessionStore(
storeData(aSessionData(sessionId = "@foo:example.com", deviceId = "ABCDEFGH")) initialList = listOf(aSessionData(sessionId = "@foo:example.com", deviceId = "ABCDEFGH"))
} )
val fakeEncryptionService = FakeEncryptionService() val fakeEncryptionService = FakeEncryptionService()
val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService) val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService)
@ -165,9 +165,9 @@ class DefaultBugReporterTest {
) )
server.start() server.start()
val mockSessionStore = InMemorySessionStore().apply { val mockSessionStore = InMemorySessionStore(
storeData(aSessionData("@foo:example.com", "ABCDEFGH")) initialList = listOf(aSessionData("@foo:example.com", "ABCDEFGH"))
} )
val fakeEncryptionService = FakeEncryptionService() val fakeEncryptionService = FakeEncryptionService()
val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService) val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService)
@ -308,9 +308,9 @@ class DefaultBugReporterTest {
fun `the log directory is initialized using the last session store data`() = runTest { fun `the log directory is initialized using the last session store data`() = runTest {
val sut = createDefaultBugReporter( val sut = createDefaultBugReporter(
buildMeta = aBuildMeta(isEnterpriseBuild = true), buildMeta = aBuildMeta(isEnterpriseBuild = true),
sessionStore = InMemorySessionStore().apply { sessionStore = InMemorySessionStore(
storeData(aSessionData(sessionId = "@alice:domain.com")) initialList = listOf(aSessionData(sessionId = "@alice:domain.com"))
} )
) )
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs/domain.com") assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs/domain.com")
} }
@ -318,9 +318,9 @@ class DefaultBugReporterTest {
@Test @Test
fun `foss build - the log directory is initialized to the root log directory`() = runTest { fun `foss build - the log directory is initialized to the root log directory`() = runTest {
val sut = createDefaultBugReporter( val sut = createDefaultBugReporter(
sessionStore = InMemorySessionStore().apply { sessionStore = InMemorySessionStore(
storeData(aSessionData(sessionId = "@alice:domain.com")) initialList = listOf(aSessionData(sessionId = "@alice:domain.com"))
} )
) )
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs") assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs")
} }

View file

@ -31,9 +31,9 @@ class SignedOutPresenterTest {
@Test @Test
fun `present - initial state`() = runTest { fun `present - initial state`() = runTest {
val aSessionData = aSessionData() val aSessionData = aSessionData()
val sessionStore = InMemorySessionStore().apply { val sessionStore = InMemorySessionStore(
storeData(aSessionData) initialList = listOf(aSessionData)
} )
val presenter = createSignedOutPresenter(sessionStore = sessionStore) val presenter = createSignedOutPresenter(sessionStore = sessionStore)
moleculeFlow(RecompositionMode.Immediate) { moleculeFlow(RecompositionMode.Immediate) {
presenter.present() presenter.present()
@ -48,9 +48,9 @@ class SignedOutPresenterTest {
@Test @Test
fun `present - sign in again`() = runTest { fun `present - sign in again`() = runTest {
val aSessionData = aSessionData() val aSessionData = aSessionData()
val sessionStore = InMemorySessionStore().apply { val sessionStore = InMemorySessionStore(
storeData(aSessionData) initialList = listOf(aSessionData)
} )
val presenter = createSignedOutPresenter(sessionStore = sessionStore) val presenter = createSignedOutPresenter(sessionStore = sessionStore)
moleculeFlow(RecompositionMode.Immediate) { moleculeFlow(RecompositionMode.Immediate) {
presenter.present() presenter.present()

View file

@ -23,11 +23,12 @@ import org.junit.Test
class RustClientSessionDelegateTest { class RustClientSessionDelegateTest {
@Test @Test
fun `saveSessionInKeychain should update the store`() = runTest { fun `saveSessionInKeychain should update the store`() = runTest {
val sessionStore = InMemorySessionStore() val sessionStore = InMemorySessionStore(
sessionStore.storeData( initialList = listOf(
aSessionData( aSessionData(
accessToken = "anAccessToken", accessToken = "anAccessToken",
refreshToken = "aRefreshToken", refreshToken = "aRefreshToken",
)
) )
) )
val sut = aRustClientSessionDelegate(sessionStore) val sut = aRustClientSessionDelegate(sessionStore)

View file

@ -24,14 +24,15 @@ class SessionPathsProviderTest {
@Test @Test
fun `if session is found, provides returns the data`() = runTest { fun `if session is found, provides returns the data`() = runTest {
val store = InMemorySessionStore() val store = InMemorySessionStore(
val sut = SessionPathsProvider(store) initialList = listOf(
store.storeData( aSessionData(
aSessionData( sessionPath = "/a/path/to/a/session",
sessionPath = "/a/path/to/a/session", cachePath = "/a/path/to/a/cache",
cachePath = "/a/path/to/a/cache", )
) )
) )
val sut = SessionPathsProvider(store)
val result = sut.provides(A_SESSION_ID)!! val result = sut.provides(A_SESSION_ID)!!
assertThat(result.fileDirectory.absolutePath).isEqualTo("/a/path/to/a/session") assertThat(result.fileDirectory.absolutePath).isEqualTo("/a/path/to/a/session")
assertThat(result.cacheDirectory.absolutePath).isEqualTo("/a/path/to/a/cache") assertThat(result.cacheDirectory.absolutePath).isEqualTo("/a/path/to/a/cache")

View file

@ -49,11 +49,13 @@ class DefaultFirebaseNewTokenHandlerTest {
val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.success(Unit) } val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.success(Unit) }
val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult) val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult)
val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler( val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler(
sessionStore = InMemorySessionStore().apply { sessionStore = InMemorySessionStore(
storeData(aSessionData(A_USER_ID.value)) initialList = listOf(
storeData(aSessionData(A_USER_ID_2.value)) aSessionData(A_USER_ID.value),
storeData(aSessionData(A_USER_ID_3.value)) aSessionData(A_USER_ID_2.value),
}, aSessionData(A_USER_ID_3.value),
)
),
matrixClientProvider = FakeMatrixClientProvider { sessionId -> matrixClientProvider = FakeMatrixClientProvider { sessionId ->
when (sessionId) { when (sessionId) {
A_USER_ID -> Result.success(aMatrixClient1) A_USER_ID -> Result.success(aMatrixClient1)
@ -88,9 +90,9 @@ class DefaultFirebaseNewTokenHandlerTest {
val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.success(Unit) } val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.success(Unit) }
val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult) val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult)
val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler( val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler(
sessionStore = InMemorySessionStore().apply { sessionStore = InMemorySessionStore(
storeData(aSessionData(A_USER_ID.value)) initialList = listOf(aSessionData(A_USER_ID.value))
}, ),
matrixClientProvider = FakeMatrixClientProvider { matrixClientProvider = FakeMatrixClientProvider {
Result.failure(IllegalStateException()) Result.failure(IllegalStateException())
}, },
@ -112,9 +114,9 @@ class DefaultFirebaseNewTokenHandlerTest {
val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.failure(AN_EXCEPTION) } val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.failure(AN_EXCEPTION) }
val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult) val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult)
val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler( val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler(
sessionStore = InMemorySessionStore().apply { sessionStore = InMemorySessionStore(
storeData(aSessionData(A_USER_ID.value)) initialList = listOf(aSessionData(A_USER_ID.value))
}, ),
matrixClientProvider = FakeMatrixClientProvider { matrixClientProvider = FakeMatrixClientProvider {
Result.success(aMatrixClient1) Result.success(aMatrixClient1)
}, },

View file

@ -15,8 +15,10 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
class InMemorySessionStore : SessionStore { class InMemorySessionStore(
private val sessionDataListFlow = MutableStateFlow<List<SessionData>>(emptyList()) initialList: List<SessionData> = emptyList(),
) : SessionStore {
private val sessionDataListFlow = MutableStateFlow(initialList)
override fun isLoggedIn(): Flow<LoggedInState> { override fun isLoggedIn(): Flow<LoggedInState> {
return sessionDataListFlow.map { return sessionDataListFlow.map {