PM-30774: Add archiving and unarchiving network requests (#6356)

This commit is contained in:
David Perez
2026-01-14 08:49:01 -06:00
committed by GitHub
parent 6d72d3a1c9
commit a9b1623f8b
9 changed files with 463 additions and 1 deletions

View File

@@ -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.
*/

View File

@@ -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.
*/

View File

@@ -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> =

View File

@@ -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))