From c825a1dd1dcb82a7070227cbcbefdfff95b33209 Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Fri, 13 Dec 2024 06:12:08 -0300 Subject: [PATCH] test: add tests for old format parser in capabilities (#3173) --- .../api/v0/user/client/ClientApiV0Test.kt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/client/ClientApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/client/ClientApiV0Test.kt index dd3280dde52..574ef891390 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/client/ClientApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/client/ClientApiV0Test.kt @@ -24,9 +24,9 @@ import com.wire.kalium.mocks.responses.ClientResponseJson import com.wire.kalium.mocks.responses.RegisterClientRequestJson import com.wire.kalium.mocks.responses.RegisterTokenJson import com.wire.kalium.mocks.responses.UpdateClientRequestJson -import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO import com.wire.kalium.network.api.authenticated.client.UpdateClientCapabilitiesRequest +import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.v0.authenticated.ClientApiV0 import com.wire.kalium.network.exceptions.KaliumException import com.wire.kalium.network.utils.NetworkResponse @@ -58,7 +58,26 @@ internal class ClientApiV0Test : ApiTest() { val clientApi: ClientApi = ClientApiV0(networkClient) val response = clientApi.registerClient(REGISTER_CLIENT_REQUEST.serializableData) assertTrue(response.isSuccessful()) - assertEquals(response.value, VALID_REGISTER_CLIENT_RESPONSE.serializableData) + assertEquals(VALID_REGISTER_CLIENT_RESPONSE.serializableData, response.value) + } + + @Test + fun givenAValidRegisterClientRequest_whenCallingTheRegisterClientEndpointWithOldFormat_theRequestShouldBeConfiguredCorrectly() = + runTest { + val networkClient = mockAuthenticatedNetworkClient( + VALID_REGISTER_CLIENT_OLD_RESPONSE.rawJson, + statusCode = HttpStatusCode.Created, + assertion = { + assertPost() + assertJson() + assertNoQueryParams() + assertPathEqual(PATH_CLIENTS) + } + ) + val clientApi: ClientApi = ClientApiV0(networkClient) + val response = clientApi.registerClient(REGISTER_CLIENT_REQUEST.serializableData) + assertTrue(response.isSuccessful()) + assertEquals(VALID_REGISTER_CLIENT_OLD_RESPONSE.serializableData, response.value) } @Test @@ -93,6 +112,7 @@ internal class ClientApiV0Test : ApiTest() { assertTrue(response.isSuccessful()) } + @Test fun givenAValidUpdateClientCapabilitiesRequest_whenCallingTheUpdateClientEndpoint_theRequestShouldBeConfiguredCorrectly() = runTest { @@ -172,6 +192,7 @@ internal class ClientApiV0Test : ApiTest() { const val PATH_CLIENTS = "/clients" val REGISTER_CLIENT_REQUEST = RegisterClientRequestJson.valid val VALID_REGISTER_CLIENT_RESPONSE = ClientResponseJson.valid + val VALID_REGISTER_CLIENT_OLD_RESPONSE = ClientResponseJson.validCapabilitiesObject val UPDATE_CLIENT_REQUEST = UpdateClientRequestJson.valid val ERROR_RESPONSE = ErrorResponseJson.valid.serializableData val VALID_PUSH_TOKEN_REQUEST = RegisterTokenJson.validPushTokenRequest