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 e250c3f commit c5c294c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
37 changes: 20 additions & 17 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 "do list a self conversation 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
let (errMsg, justOrNothing, listCnvs) =
if isBelowV3
then ("The MLS self-conversation is listed", isNothing, listConvIdsV2)
else ("The MLS self-conversation is not listed", isJust, listConvIds)
alice <- randomUser
let paginationOpts = GetPaginatedConversationIds Nothing (toRange (Proxy @100))
convs :: ConvIdsPage <-
convIds :: ConvIdsPage <-
responseJsonError
=<< listConvIds alice paginationOpts
=<< listCnvs 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)
liftIO $
assertBool "The MLS self-conversation is not listed" (isJust mMLSSelf)
convs <-
forM (mtpResults convIds) (responseJsonError <=< getConvQualified alice)
let mMLSSelf = foldr (<|>) Nothing $ guard . isMLSSelf <$> convs
liftIO $ assertBool errMsg (justOrNothing mMLSSelf)
where
isMLSSelf conv =
cnvType conv == SelfConv
&& protocolTag (cnvProtocol conv) == ProtocolMLSTag

testSelfConversationOtherUser :: TestM ()
testSelfConversationOtherUser = do
Expand Down
16 changes: 13 additions & 3 deletions services/galley/test/integration/API/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ import Wire.API.User.Client.Prekey
-- API Operations

addPrefix :: Request -> Request
addPrefix r = r {HTTP.path = "v" <> toHeader latestVersion <> "/" <> removeSlash (HTTP.path r)}
addPrefix = addPrefixAtVersion maxBound

addPrefixAtVersion :: Version -> Request -> Request
addPrefixAtVersion v r = r {HTTP.path = "v" <> toHeader v <> "/" <> removeSlash (HTTP.path r)}
where
removeSlash s = case B8.uncons s of
Just ('/', s') -> s'
_ -> s
latestVersion :: Version
latestVersion = maxBound

-- | A class for monads with access to a Sem r instance
class HasGalley m where
Expand Down Expand Up @@ -1048,6 +1049,15 @@ listConvIds u paginationOpts = do
. zUser u
. json paginationOpts

listConvIdsV2 :: UserId -> GetPaginatedConversationIds -> TestM ResponseLBS
listConvIdsV2 u paginationOpts = do
g <- fmap (addPrefixAtVersion V2 .) (view tsUnversionedGalley)
post $
g
. path "/conversations/list-ids"
. zUser u
. json paginationOpts

-- | Does not page through conversation list
listRemoteConvs :: Domain -> UserId -> TestM [Qualified ConvId]
listRemoteConvs remoteDomain uid = do
Expand Down

0 comments on commit c5c294c

Please sign in to comment.