Add the decrypted SendView to the UpdateSendResult (#568)

This commit is contained in:
David Perez 2024-01-10 16:43:49 -06:00 committed by Álison Fernandes
parent 9f95c26c2f
commit b7d843486b
3 changed files with 49 additions and 7 deletions

View file

@ -429,7 +429,14 @@ class VaultRepositoryImpl(
is UpdateSendResponseJson.Success -> {
vaultDiskSource.saveSend(userId = userId, send = response.send)
UpdateSendResult.Success
vaultSdkSource
.decryptSend(
userId = userId,
send = response.send.toEncryptedSdkSend(),
)
.getOrNull()
?.let { UpdateSendResult.Success(sendView = it) }
?: UpdateSendResult.Error(errorMessage = null)
}
}
},

View file

@ -1,14 +1,16 @@
package com.x8bit.bitwarden.data.vault.repository.model
import com.bitwarden.core.SendView
/**
* Models result of updating a send.
*/
sealed class UpdateSendResult {
/**
* Send updated successfully.
* Send was updated successfully and contains the decrypted [SendView].
*/
data object Success : UpdateSendResult()
data class Success(val sendView: SendView) : UpdateSendResult()
/**
* Generic error while updating a send. The optional [errorMessage] may be displayed directly

View file

@ -1528,6 +1528,37 @@ class VaultRepositoryTest {
)
}
@Test
@Suppress("MaxLineLength")
fun `updateSend with sendsService updateSend success and decryption error should return UpdateSendResult Error with a null message`() =
runTest {
fakeAuthDiskSource.userState = MOCK_USER_STATE
val userId = "mockId-1"
val sendId = "sendId1234"
val mockSendView = createMockSendView(number = 1)
coEvery {
vaultSdkSource.encryptSend(userId = userId, sendView = mockSendView)
} returns createMockSdkSend(number = 1).asSuccess()
val mockSend = createMockSend(number = 1)
coEvery {
sendsService.updateSend(
sendId = sendId,
body = createMockSendJsonRequest(number = 1),
)
} returns UpdateSendResponseJson.Success(send = mockSend).asSuccess()
coEvery {
vaultSdkSource.decryptSend(userId = userId, send = createMockSdkSend(number = 1))
} returns Throwable("Fail").asFailure()
coEvery { vaultDiskSource.saveSend(userId = userId, send = mockSend) } just runs
val result = vaultRepository.updateSend(
sendId = sendId,
sendView = mockSendView,
)
assertEquals(UpdateSendResult.Error(errorMessage = null), result)
}
@Test
@Suppress("MaxLineLength")
fun `updateSend with sendsService updateSend Success response should return UpdateSendResult success`() =
@ -1545,9 +1576,11 @@ class VaultRepositoryTest {
sendId = sendId,
body = createMockSendJsonRequest(number = 1),
)
} returns UpdateSendResponseJson
.Success(send = mockSend)
.asSuccess()
} returns UpdateSendResponseJson.Success(send = mockSend).asSuccess()
val mockSendViewResult = createMockSendView(number = 2)
coEvery {
vaultSdkSource.decryptSend(userId = userId, send = createMockSdkSend(number = 1))
} returns mockSendViewResult.asSuccess()
coEvery { vaultDiskSource.saveSend(userId = userId, send = mockSend) } just runs
val result = vaultRepository.updateSend(
@ -1555,7 +1588,7 @@ class VaultRepositoryTest {
sendView = mockSendView,
)
assertEquals(UpdateSendResult.Success, result)
assertEquals(UpdateSendResult.Success(mockSendViewResult), result)
}
//region Helper functions