From 15225d3a51adbf5d70ed38ae4bd416869389738c Mon Sep 17 00:00:00 2001 From: Jacob Persson <7156+typfel@users.noreply.github.com> Date: Mon, 24 Jul 2023 10:20:38 +0200 Subject: [PATCH] fix: updating isMLSCapable (#1905) * fix: updating isMLSCapable It should be possible to update isMlsCapable from false to true but not the other way around. * chore: add comment explaining update logic for is_mls_capable --- .../com/wire/kalium/persistence/Clients.sq | 2 +- .../persistence/dao/client/ClientDAOTest.kt | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Clients.sq b/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Clients.sq index 1452753ecfa..302666233e8 100644 --- a/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Clients.sq +++ b/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Clients.sq @@ -42,7 +42,7 @@ model = coalesce(excluded.model, model), is_valid = is_valid, last_active = coalesce(excluded.last_active, last_active), mls_public_keys = excluded.mls_public_keys, -is_mls_capable = is_mls_capable; +is_mls_capable = excluded.is_mls_capable OR is_mls_capable; -- it's not possible to remove mls capability once added selectAllClients: SELECT * FROM Client; diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/client/ClientDAOTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/client/ClientDAOTest.kt index d34161f319f..16f5f02f099 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/client/ClientDAOTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/client/ClientDAOTest.kt @@ -185,6 +185,32 @@ class ClientDAOTest : BaseDatabaseTest() { assertEquals(listOf(client, client2), result) } + @Test + fun givenIsMLSCapableIsFalse_whenUpdatingAClient_thenItShouldUpdatedToTrue() = runTest { + val user = user + userDAO.insertUser(user) + clientDAO.insertClient(insertedClient.copy( + isMLSCapable = false + )) + clientDAO.insertClient(insertedClient.copy( + isMLSCapable = true + )) + assertTrue { clientDAO.getClientsOfUserByQualifiedID(userId).first().isMLSCapable } + } + + @Test + fun givenIsMLSCapableIsTrue_whenUpdatingAClient_thenItShouldRemainTrue() = runTest { + val user = user + userDAO.insertUser(user) + clientDAO.insertClient(insertedClient.copy( + isMLSCapable = true + )) + clientDAO.insertClient(insertedClient.copy( + isMLSCapable = false + )) + assertTrue { clientDAO.getClientsOfUserByQualifiedID(userId).first().isMLSCapable } + } + @Test fun whenInsertingANewClient_thenIsMustBeMarkedAsValid() = runTest { val user = user