From 35baaa62093d70c785fd3de75adeeabf7b8c7b33 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 28 Dec 2023 16:33:53 +0100 Subject: [PATCH] Add missing test for SecureBackupEnablePresenter --- .../enable/SecureBackupEnablePresenterTest.kt | 21 +++++++++++++++++++ .../test/encryption/FakeEncryptionService.kt | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/enable/SecureBackupEnablePresenterTest.kt b/features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/enable/SecureBackupEnablePresenterTest.kt index 5aa223cf93..7bc051662b 100644 --- a/features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/enable/SecureBackupEnablePresenterTest.kt +++ b/features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/enable/SecureBackupEnablePresenterTest.kt @@ -22,6 +22,7 @@ import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.architecture.Async import io.element.android.libraries.matrix.api.encryption.EncryptionService +import io.element.android.libraries.matrix.test.AN_EXCEPTION import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService import io.element.android.tests.testutils.WarmUpRule import kotlinx.coroutines.test.runTest @@ -58,6 +59,26 @@ class SecureBackupEnablePresenterTest { } } + @Test + fun `present - user enable backup with error`() = runTest { + val encryptionService = FakeEncryptionService() + encryptionService.givenEnableBackupsFailure(AN_EXCEPTION) + val presenter = createPresenter(encryptionService = encryptionService) + moleculeFlow(RecompositionMode.Immediate) { + presenter.present() + }.test { + val initialState = awaitItem() + initialState.eventSink(SecureBackupEnableEvents.EnableBackup) + val loadingState = awaitItem() + assertThat(loadingState.enableAction).isInstanceOf(Async.Loading::class.java) + val errorState = awaitItem() + assertThat(errorState.enableAction).isEqualTo(Async.Failure(AN_EXCEPTION)) + errorState.eventSink(SecureBackupEnableEvents.DismissDialog) + val finalState = awaitItem() + assertThat(finalState.enableAction).isEqualTo(Async.Uninitialized) + } + } + private fun createPresenter( encryptionService: EncryptionService = FakeEncryptionService(), ) = SecureBackupEnablePresenter( diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt index aafb2e8074..fe13d9766d 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt @@ -36,7 +36,14 @@ class FakeEncryptionService : EncryptionService { private var recoverFailure: Exception? = null private var doesBackupExistOnServerResult: Result = Result.success(true) + private var enableBackupsFailure: Exception? = null + + fun givenEnableBackupsFailure(exception: Exception?) { + enableBackupsFailure = exception + } + override suspend fun enableBackups(): Result = simulateLongTask { + enableBackupsFailure?.let { return Result.failure(it) } return Result.success(Unit) }