mirror of
https://github.com/bitwarden/android.git
synced 2026-04-28 11:58:40 -05:00
PM-30774: Add archiving and unarchiving network requests (#6356)
This commit is contained in:
@@ -26,6 +26,22 @@ import retrofit2.http.Query
|
||||
@Suppress("TooManyFunctions")
|
||||
internal interface CiphersApi {
|
||||
|
||||
/**
|
||||
* Archive a cipher.
|
||||
*/
|
||||
@PUT("ciphers/{cipherId}/archive")
|
||||
suspend fun archiveCipher(
|
||||
@Path("cipherId") cipherId: String,
|
||||
): NetworkResult<Unit>
|
||||
|
||||
/**
|
||||
* Unarchive a cipher.
|
||||
*/
|
||||
@PUT("ciphers/{cipherId}/unarchive")
|
||||
suspend fun unarchiveCipher(
|
||||
@Path("cipherId") cipherId: String,
|
||||
): NetworkResult<Unit>
|
||||
|
||||
/**
|
||||
* Create a cipher.
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,16 @@ import java.io.File
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
interface CiphersService {
|
||||
/**
|
||||
* Attempt to archive a cipher.
|
||||
*/
|
||||
suspend fun archiveCipher(cipherId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Attempt to unarchive a cipher.
|
||||
*/
|
||||
suspend fun unarchiveCipher(cipherId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Attempt to create a cipher.
|
||||
*/
|
||||
|
||||
@@ -39,6 +39,18 @@ internal class CiphersServiceImpl(
|
||||
private val json: Json,
|
||||
private val clock: Clock,
|
||||
) : CiphersService {
|
||||
override suspend fun archiveCipher(
|
||||
cipherId: String,
|
||||
): Result<Unit> = ciphersApi
|
||||
.archiveCipher(cipherId = cipherId)
|
||||
.toResult()
|
||||
|
||||
override suspend fun unarchiveCipher(
|
||||
cipherId: String,
|
||||
): Result<Unit> = ciphersApi
|
||||
.unarchiveCipher(cipherId = cipherId)
|
||||
.toResult()
|
||||
|
||||
override suspend fun createCipher(
|
||||
body: CipherJsonRequest,
|
||||
): Result<CreateCipherResponseJson> =
|
||||
|
||||
@@ -27,7 +27,6 @@ import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.encodeToString
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -65,6 +64,22 @@ class CiphersServiceTest : BaseServiceTest() {
|
||||
unmockkStatic(Uri::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `archiveCipher should execute the archiveCipher API`() = runTest {
|
||||
server.enqueue(MockResponse().setResponseCode(200))
|
||||
val cipherId = "cipherId"
|
||||
val result = ciphersService.archiveCipher(cipherId = cipherId)
|
||||
assertEquals(Unit, result.getOrThrow())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unarchiveCipher should execute the unarchiveCipher API`() = runTest {
|
||||
server.enqueue(MockResponse().setResponseCode(200))
|
||||
val cipherId = "cipherId"
|
||||
val result = ciphersService.unarchiveCipher(cipherId = cipherId)
|
||||
assertEquals(Unit, result.getOrThrow())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createCipher should return the correct response`() = runTest {
|
||||
server.enqueue(MockResponse().setBody(CREATE_RESTORE_UPDATE_CIPHER_SUCCESS_JSON))
|
||||
|
||||
Reference in New Issue
Block a user