From c8d2377a5d90ca316480582806d32d47c96ccae1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 6 Feb 2025 16:11:54 +0100 Subject: [PATCH] Add unit test for SecureBackupRootState --- .../impl/root/SecureBackupRootStateTest.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/root/SecureBackupRootStateTest.kt diff --git a/features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/root/SecureBackupRootStateTest.kt b/features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/root/SecureBackupRootStateTest.kt new file mode 100644 index 0000000000..1e4f58a84a --- /dev/null +++ b/features/securebackup/impl/src/test/kotlin/io/element/android/features/securebackup/impl/root/SecureBackupRootStateTest.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.securebackup.impl.root + +import com.google.common.truth.Truth.assertThat +import io.element.android.libraries.architecture.AsyncData +import io.element.android.libraries.matrix.api.encryption.BackupState +import io.element.android.libraries.matrix.test.AN_EXCEPTION +import org.junit.Test + +class SecureBackupRootStateTest { + @Test + fun `isKeyStorageEnabled should be true for all these backup states`() { + listOf( + BackupState.CREATING, + BackupState.ENABLING, + BackupState.RESUMING, + BackupState.DOWNLOADING, + BackupState.ENABLED, + ).forEach { backupState -> + assertThat(aSecureBackupRootState(backupState = backupState).isKeyStorageEnabled).isTrue() + } + } + + @Test + fun `isKeyStorageEnabled should be false for all these backup states`() { + listOf( + BackupState.WAITING_FOR_SYNC, + BackupState.DISABLING, + ).forEach { backupState -> + assertThat(aSecureBackupRootState(backupState = backupState).isKeyStorageEnabled).isFalse() + } + } + + @Test + fun `isKeyStorageEnabled should have value depending on doesBackupExistOnServer when state is UNKNOWN`() { + assertThat( + aSecureBackupRootState( + backupState = BackupState.UNKNOWN, + doesBackupExistOnServer = AsyncData.Success(true), + ).isKeyStorageEnabled + ).isTrue() + + listOf( + AsyncData.Uninitialized, + AsyncData.Loading(), + AsyncData.Failure(AN_EXCEPTION), + AsyncData.Success(false), + ).forEach { doesBackupExistOnServer -> + assertThat( + aSecureBackupRootState( + backupState = BackupState.UNKNOWN, + doesBackupExistOnServer = doesBackupExistOnServer, + ).isKeyStorageEnabled + ).isFalse() + } + } +}