|
| 1 | +/* |
| 2 | + * Copyright 2025 New Vector Ltd. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | + * Please see LICENSE files in the repository root for full details. |
| 6 | + */ |
| 7 | + |
| 8 | +package io.element.android.features.securebackup.impl.root |
| 9 | + |
| 10 | +import com.google.common.truth.Truth.assertThat |
| 11 | +import io.element.android.libraries.architecture.AsyncData |
| 12 | +import io.element.android.libraries.matrix.api.encryption.BackupState |
| 13 | +import io.element.android.libraries.matrix.test.AN_EXCEPTION |
| 14 | +import org.junit.Test |
| 15 | + |
| 16 | +class SecureBackupRootStateTest { |
| 17 | + @Test |
| 18 | + fun `isKeyStorageEnabled should be true for all these backup states`() { |
| 19 | + listOf( |
| 20 | + BackupState.CREATING, |
| 21 | + BackupState.ENABLING, |
| 22 | + BackupState.RESUMING, |
| 23 | + BackupState.DOWNLOADING, |
| 24 | + BackupState.ENABLED, |
| 25 | + ).forEach { backupState -> |
| 26 | + assertThat(aSecureBackupRootState(backupState = backupState).isKeyStorageEnabled).isTrue() |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + fun `isKeyStorageEnabled should be false for all these backup states`() { |
| 32 | + listOf( |
| 33 | + BackupState.WAITING_FOR_SYNC, |
| 34 | + BackupState.DISABLING, |
| 35 | + ).forEach { backupState -> |
| 36 | + assertThat(aSecureBackupRootState(backupState = backupState).isKeyStorageEnabled).isFalse() |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun `isKeyStorageEnabled should have value depending on doesBackupExistOnServer when state is UNKNOWN`() { |
| 42 | + assertThat( |
| 43 | + aSecureBackupRootState( |
| 44 | + backupState = BackupState.UNKNOWN, |
| 45 | + doesBackupExistOnServer = AsyncData.Success(true), |
| 46 | + ).isKeyStorageEnabled |
| 47 | + ).isTrue() |
| 48 | + |
| 49 | + listOf( |
| 50 | + AsyncData.Uninitialized, |
| 51 | + AsyncData.Loading(), |
| 52 | + AsyncData.Failure(AN_EXCEPTION), |
| 53 | + AsyncData.Success(false), |
| 54 | + ).forEach { doesBackupExistOnServer -> |
| 55 | + assertThat( |
| 56 | + aSecureBackupRootState( |
| 57 | + backupState = BackupState.UNKNOWN, |
| 58 | + doesBackupExistOnServer = doesBackupExistOnServer, |
| 59 | + ).isKeyStorageEnabled |
| 60 | + ).isFalse() |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments