From 9ae739a4057ce998035a4320d81793056ba3b37e Mon Sep 17 00:00:00 2001 From: Gonzalo Gran Crespo Date: Fri, 22 Sep 2023 15:21:49 +0200 Subject: [PATCH] fix: added test with archived conversations --- ...serveConversationListDetailsUseCaseTest.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt index 7cffbc0693f..05fd44e0560 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt @@ -47,6 +47,8 @@ import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue @Suppress("LongMethod") @Ignore // TODO @@ -87,6 +89,54 @@ class ObserveConversationListDetailsUseCaseTest { .wasInvoked(exactly = once) } } + @Test + fun givenSomeConversationsWithArchivedValues_whenFetchingOnlyNonArchived_thenTheseConversationsShouldNotBeReturned() = runTest { + // Given + val groupConversation1 = TestConversation.GROUP().copy(archived = true) + val group2Id = ConversationId("OtherId","someDomain") + val groupConversation2 = TestConversation.GROUP().copy(id = group2Id, archived = false) + val selfConversation = TestConversation.SELF() + val conversations = listOf(selfConversation, groupConversation1, groupConversation2) + val selfConversationDetails = ConversationDetails.Self(selfConversation) + val fetchArchivedConversations = false + val groupConversationDetails1 = + ConversationDetails.Group( + groupConversation1, + LegalHoldStatus.DISABLED, + lastMessage = null, + isSelfUserMember = true, + isSelfUserCreator = true, + unreadEventCount = emptyMap(), + selfRole = Conversation.Member.Role.Member + ) + val groupConversationDetails2 = + ConversationDetails.Group( + groupConversation2, + LegalHoldStatus.DISABLED, + lastMessage = null, + isSelfUserMember = true, + isSelfUserCreator = true, + unreadEventCount = emptyMap(), + selfRole = Conversation.Member.Role.Member + ) + + val (arrangement, observeConversationsUseCase) = Arrangement() + .withConversationsList(conversations) + .withSuccessfulConversationsDetailsListUpdates(groupConversation1, listOf(groupConversationDetails1)) + .withSuccessfulConversationsDetailsListUpdates(groupConversation2, listOf(groupConversationDetails2)) + .withSuccessfulConversationsDetailsListUpdates(selfConversation, listOf(selfConversationDetails)) + .arrange() + + // When + observeConversationsUseCase(fetchArchivedConversations).test { + val conversationDetailsList = awaitItem() + + // Then + assertFalse(conversationDetailsList.contains(groupConversationDetails2)) + assertTrue(conversationDetailsList.contains(selfConversationDetails)) + assertTrue(conversationDetailsList.contains(groupConversationDetails1)) + } + } @Test fun givenSomeConversations_whenObservingDetailsList_thenObserveConversationDetailsShouldBeCalledForEachID() = runTest {