Skip to content

Commit

Permalink
Adjust tests for listing the MLS self-conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdimjasevic committed Nov 22, 2022
1 parent 392b1ff commit c295d3f
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down Expand Up @@ -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
<!! const 200 === statusCode
let maybeMLSSelf :: Maybe Conversation -> 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
Expand Down

0 comments on commit c295d3f

Please sign in to comment.