|
| 1 | +/* |
| 2 | + * Wire |
| 3 | + * Copyright (C) 2024 Wire Swiss GmbH |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see http://www.gnu.org/licenses/. |
| 17 | + */ |
| 18 | +package com.wire.kalium.network.api.authenticated.client |
| 19 | + |
| 20 | +import kotlinx.serialization.SerializationException |
| 21 | +import kotlinx.serialization.json.Json |
| 22 | +import kotlin.test.Test |
| 23 | +import kotlin.test.assertEquals |
| 24 | +import kotlin.test.assertFailsWith |
| 25 | + |
| 26 | + |
| 27 | +class ClientCapabilityDTOSerializerTest { |
| 28 | + |
| 29 | + private val json = Json { ignoreUnknownKeys = true } |
| 30 | + |
| 31 | + @Test |
| 32 | + fun serialize_legal_hold_implicit_consent() { |
| 33 | + val capability = ClientCapabilityDTO.LegalHoldImplicitConsent |
| 34 | + val result = json.encodeToString(ClientCapabilityDTO.serializer(), capability) |
| 35 | + assertEquals("\"legalhold-implicit-consent\"", result) |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + fun serialize_unknown_capability() { |
| 40 | + val capability = ClientCapabilityDTO.Unknown("custom-capability") |
| 41 | + val result = json.encodeToString(ClientCapabilityDTO.serializer(), capability) |
| 42 | + assertEquals("\"custom-capability\"", result) |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + fun deserialize_legal_hold_implicit_consent() { |
| 47 | + val jsonString = "\"legalhold-implicit-consent\"" |
| 48 | + val result = json.decodeFromString(ClientCapabilityDTO.serializer(), jsonString) |
| 49 | + assertEquals(ClientCapabilityDTO.LegalHoldImplicitConsent, result) |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun deserialize_unknown_capability() { |
| 54 | + val jsonString = "\"unknown-capability\"" |
| 55 | + val result = json.decodeFromString(ClientCapabilityDTO.serializer(), jsonString) |
| 56 | + assertEquals(ClientCapabilityDTO.Unknown("unknown-capability"), result) |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + fun deserialization_fails_on_invalid_json_format() { |
| 61 | + val invalidJson = "12345" // Invalid format for a string |
| 62 | + assertFailsWith<SerializationException> { |
| 63 | + json.decodeFromString(ClientCapabilityDTO.serializer(), invalidJson) |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments