From 81a40f5534b138fe48d23e592698a2f31b794486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Dimja=C5=A1evi=C4=87?= Date: Tue, 22 Nov 2022 18:19:30 +0100 Subject: [PATCH] WIP: Adjust tests for listing the MLS self-conversation --- services/galley/test/integration/API/MLS.hs | 35 +++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/services/galley/test/integration/API/MLS.hs b/services/galley/test/integration/API/MLS.hs index 86af944becb..5b042306828 100644 --- a/services/galley/test/integration/API/MLS.hs +++ b/services/galley/test/integration/API/MLS.hs @@ -190,7 +190,8 @@ tests s = testGroup "Self conversation" [ test s "create a self conversation" testSelfConversation, - test s "list a self conversation automatically" testSelfConversationList, + test s "list a self conversation automatically below v3" $ testSelfConversationList True, + test s "list a self conversation automatically from v3" $ testSelfConversationList False, test s "attempt to add another user to a conversation fails" testSelfConversationOtherUser, test s "attempt to leave fails" testSelfConversationLeave ] @@ -2157,26 +2158,28 @@ testSelfConversation = do WS.assertNoEvent (1 # WS.Second) wss -- | The MLS self-conversation should be available even without explicitly --- creating it by calling `GET /conversations/mls-self`. -testSelfConversationList :: TestM () -testSelfConversationList = do +-- creating it by calling `GET /conversations/mls-self` starting from version 3 +-- of the client API and should not be listed in versions less than 3. +testSelfConversationList :: Bool -> TestM () +testSelfConversationList isBelowV3 = do alice <- randomUser let paginationOpts = GetPaginatedConversationIds Nothing (toRange (Proxy @100)) - convs :: ConvIdsPage <- + convIds :: ConvIdsPage <- responseJsonError - =<< listConvIds alice paginationOpts + =<< listConvIds alice paginationOpts -- TODO(md): call v2 of the endpoint if 'isBelowV3' Qualified ConvId -> TestM (Maybe Conversation) - maybeMLSSelf (Just acc) _ = pure (Just acc) - maybeMLSSelf Nothing qcnv = do - conv <- responseJsonError =<< getConvQualified alice qcnv - let isMLSSelf = - cnvType conv == SelfConv - && protocolTag (cnvProtocol conv) == ProtocolMLSTag - pure (guard isMLSSelf $> conv) - mMLSSelf <- foldM maybeMLSSelf Nothing (mtpResults convs) + convs <- + forM (mtpResults convIds) (responseJsonError <=< getConvQualified alice) + let mMLSSelf = foldr (<|>) Nothing $ getMLSSelf <$> convs liftIO $ - assertBool "The MLS self-conversation is not listed" (isJust mMLSSelf) + if isBelowV3 + then assertBool "The MLS self-conversation is listed" (isNothing mMLSSelf) + else assertBool "The MLS self-conversation is not listed" (isJust mMLSSelf) + where + isMLSSelf conv = + cnvType conv == SelfConv + && protocolTag (cnvProtocol conv) == ProtocolMLSTag + getMLSSelf c = guard (isMLSSelf c) $> c testSelfConversationOtherUser :: TestM () testSelfConversationOtherUser = do