mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
Add API for updating a cipher (#354)
This commit is contained in:
committed by
Álison Fernandes
parent
266db5cc04
commit
bfc0e9831c
+15
-2
@@ -19,7 +19,7 @@ class CiphersServiceTest : BaseServiceTest() {
|
||||
|
||||
@Test
|
||||
fun `createCipher should return the correct response`() = runTest {
|
||||
server.enqueue(MockResponse().setBody(CREATE_CIPHER_SUCCESS_JSON))
|
||||
server.enqueue(MockResponse().setBody(CREATE_UPDATE_CIPHER_SUCCESS_JSON))
|
||||
val result = ciphersService.createCipher(
|
||||
body = createMockCipherJsonRequest(number = 1),
|
||||
)
|
||||
@@ -28,9 +28,22 @@ class CiphersServiceTest : BaseServiceTest() {
|
||||
result.getOrThrow(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `updateCipher should return the correct response`() = runTest {
|
||||
server.enqueue(MockResponse().setBody(CREATE_UPDATE_CIPHER_SUCCESS_JSON))
|
||||
val result = ciphersService.updateCipher(
|
||||
cipherId = "cipher-id-1",
|
||||
body = createMockCipherJsonRequest(number = 1),
|
||||
)
|
||||
assertEquals(
|
||||
createMockCipher(number = 1),
|
||||
result.getOrThrow(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private const val CREATE_CIPHER_SUCCESS_JSON = """
|
||||
private const val CREATE_UPDATE_CIPHER_SUCCESS_JSON = """
|
||||
{
|
||||
"notes": "mockNotes-1",
|
||||
"attachments": [
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkSend
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.SendData
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.UpdateCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultState
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult
|
||||
@@ -1484,6 +1485,83 @@ class VaultRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `updateCipher with encryptCipher failure should return UpdateCipherResult failure`() =
|
||||
runTest {
|
||||
val cipherId = "cipherId1234"
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(cipherView = mockCipherView)
|
||||
} returns IllegalStateException().asFailure()
|
||||
|
||||
val result = vaultRepository.updateCipher(
|
||||
cipherId = cipherId,
|
||||
cipherView = mockCipherView,
|
||||
)
|
||||
|
||||
assertEquals(UpdateCipherResult.Error, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `updateCipher with ciphersService updateCipher failure should return UpdateCipherResult failure`() =
|
||||
runTest {
|
||||
val cipherId = "cipherId1234"
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(cipherView = mockCipherView)
|
||||
} returns createMockSdkCipher(number = 1).asSuccess()
|
||||
coEvery {
|
||||
ciphersService.updateCipher(
|
||||
cipherId = cipherId,
|
||||
body = createMockCipherJsonRequest(number = 1),
|
||||
)
|
||||
} returns IllegalStateException().asFailure()
|
||||
|
||||
val result = vaultRepository.updateCipher(
|
||||
cipherId = cipherId,
|
||||
cipherView = mockCipherView,
|
||||
)
|
||||
|
||||
assertEquals(UpdateCipherResult.Error, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `updateCipher with ciphersService updateCipher success should return UpdateCipherResult success`() =
|
||||
runTest {
|
||||
val cipherId = "cipherId1234"
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(cipherView = mockCipherView)
|
||||
} returns createMockSdkCipher(number = 1).asSuccess()
|
||||
coEvery {
|
||||
ciphersService.updateCipher(
|
||||
cipherId = cipherId,
|
||||
body = createMockCipherJsonRequest(number = 1),
|
||||
)
|
||||
} returns createMockCipher(number = 1).asSuccess()
|
||||
coEvery {
|
||||
syncService.sync()
|
||||
} returns Result.success(createMockSyncResponse(1))
|
||||
coEvery {
|
||||
vaultSdkSource.decryptCipherList(listOf(createMockSdkCipher(1)))
|
||||
} returns listOf(createMockCipherView(1)).asSuccess()
|
||||
coEvery {
|
||||
vaultSdkSource.decryptFolderList(listOf(createMockSdkFolder(1)))
|
||||
} returns listOf(createMockFolderView(1)).asSuccess()
|
||||
coEvery {
|
||||
vaultSdkSource.decryptSendList(listOf(createMockSdkSend(1)))
|
||||
} returns listOf(createMockSendView(1)).asSuccess()
|
||||
|
||||
val result = vaultRepository.updateCipher(
|
||||
cipherId = cipherId,
|
||||
cipherView = mockCipherView,
|
||||
)
|
||||
|
||||
assertEquals(UpdateCipherResult.Success, result)
|
||||
}
|
||||
|
||||
//region Helper functions
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user