From 0537ccde0789451a308e5b496abef387ceb7d2fc Mon Sep 17 00:00:00 2001 From: David Perez Date: Fri, 23 Feb 2024 11:12:20 -0600 Subject: [PATCH] BIT-1939: Add collection IDs back to network response (#1059) --- .../vault/repository/VaultRepositoryImpl.kt | 1 + .../vault/repository/VaultRepositoryTest.kt | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryImpl.kt index 677f8b501..459f5c26d 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryImpl.kt @@ -895,6 +895,7 @@ class VaultRepositoryImpl( ) } } + .map { it.copy(collectionIds = cipherView.collectionIds) } .onSuccess { // Save the send immediately, regardless of whether the decrypt succeeds vaultDiskSource.saveCipher(userId = userId, cipher = it) diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt index a7df30788..199312c18 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt @@ -3382,7 +3382,10 @@ class VaultRepositoryTest { val mockByteArray = byteArrayOf(1, 2) val mockAttachmentEncryptResult = createMockAttachmentEncryptResult(number = 1) val mockAttachmentJsonResponse = createMockAttachmentJsonResponse(number = 1) - val mockCipherResponse = createMockCipher(number = 1) + val mockCipherResponse = createMockCipher(number = 1).copy(collectionIds = null) + val mockUpdatedCipherResponse = createMockCipher(number = 1).copy( + collectionIds = listOf("mockId-1"), + ) coEvery { vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView) } returns mockCipher.asSuccess() @@ -3412,12 +3415,12 @@ class VaultRepositoryTest { ) } returns mockCipherResponse.asSuccess() coEvery { - vaultDiskSource.saveCipher(userId = userId, cipher = mockCipherResponse) + vaultDiskSource.saveCipher(userId = userId, cipher = mockUpdatedCipherResponse) } just runs coEvery { vaultSdkSource.decryptCipher( userId = userId, - cipher = mockCipherResponse.toEncryptedSdkCipher(), + cipher = mockUpdatedCipherResponse.toEncryptedSdkCipher(), ) } returns Throwable("Fail").asFailure() @@ -3453,7 +3456,10 @@ class VaultRepositoryTest { val mockByteArray = byteArrayOf(1, 2) val mockAttachmentEncryptResult = createMockAttachmentEncryptResult(number = 1) val mockAttachmentJsonResponse = createMockAttachmentJsonResponse(number = 1) - val mockCipherResponse = createMockCipher(number = 1) + val mockCipherResponse = createMockCipher(number = 1).copy(collectionIds = null) + val mockUpdatedCipherResponse = createMockCipher(number = 1).copy( + collectionIds = listOf("mockId-1"), + ) coEvery { vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView) } returns mockCipher.asSuccess() @@ -3483,12 +3489,12 @@ class VaultRepositoryTest { ) } returns mockCipherResponse.asSuccess() coEvery { - vaultDiskSource.saveCipher(userId = userId, cipher = mockCipherResponse) + vaultDiskSource.saveCipher(userId = userId, cipher = mockUpdatedCipherResponse) } just runs coEvery { vaultSdkSource.decryptCipher( userId = userId, - cipher = mockCipherResponse.toEncryptedSdkCipher(), + cipher = mockUpdatedCipherResponse.toEncryptedSdkCipher(), ) } returns mockCipherView.asSuccess()