Skip to content

Commit

Permalink
Change tests according to the acceptance criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
mdimjasevic committed Oct 30, 2023
1 parent f87b3b3 commit f45127d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
30 changes: 22 additions & 8 deletions integration/test/Test/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,38 @@ testAddUnreachableUserFromFederatingBackend :: HasCallStack => App ()
testAddUnreachableUserFromFederatingBackend = do
resourcePool <- asks resourcePool
runCodensity (acquireResources 1 resourcePool) $ \[cDom] -> do
(alice, chadId, conv) <- runCodensity (startDynamicBackend cDom mempty) $ \_ -> do
(alice, chad, chad1, qcnv) <- runCodensity (startDynamicBackend cDom mempty) $ \_ -> do
ownDomain <- make OwnDomain & asString
otherDomain <- make OtherDomain & asString
[alice, bob, charlie, chad] <-
createAndConnectUsers [ownDomain, otherDomain, cDom.berDomain, cDom.berDomain]
chad1 <- objId $ bindResponse (addClient chad def) $ getJSON 201

conv <- withWebSockets [bob, charlie] $ \wss -> do
qcnv <- withWebSockets [bob, charlie] $ \wss -> do
conv <-
postConversation alice (defProteus {qualifiedUsers = [bob, charlie]})
>>= getJSON 201
forM_ wss $ awaitMatch 5 isMemberJoinNotif
pure conv
chadId <- chad %. "qualified_id"
pure (alice, chadId, conv)
let qcnv = conv %. "qualified_id"
pure qcnv
pure (alice, chad, chad1, qcnv)

bindResponse (addMembers alice conv def {users = [chadId]}) $ \resp -> do
resp.status `shouldMatchInt` 533
resp.jsonBody %. "unreachable_backends" `shouldMatchSet` [cDom.berDomain]
chadId <- chad %. "qualified_id"
bindResponse (addMembers alice qcnv def {users = [chad]}) $ \resp -> do
resp.status `shouldMatchInt` 200
let event = resp.jsonBody
shouldMatch (event %. "qualified_conversation") qcnv
shouldMatch (event %. "type") "conversation.member-join"
shouldMatch (event %. "from") (objId alice)
members <- event %. "data.users" & asList
memberQids <- for members (%. "qualified_id")
memberQids `shouldMatch` [chadId]

runCodensity (startDynamicBackend cDom mempty) $ \_ -> do
n <- awaitNotification chad chad1 noValue 10 isMemberJoinNotif
members <- n %. "payload.0.data.users" & asList
memberQids <- for members (%. "qualified_id")
memberQids `shouldMatch` [chadId]

testAddUnreachable :: HasCallStack => App ()
testAddUnreachable = do
Expand Down
26 changes: 20 additions & 6 deletions integration/test/Test/MLS/Unreachable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,34 @@ testAddUnreachableUserFromFederatingBackend :: HasCallStack => App ()
testAddUnreachableUserFromFederatingBackend = do
resourcePool <- asks resourcePool
runCodensity (acquireResources 1 resourcePool) $ \[cDom] -> do
mp <- runCodensity (startDynamicBackend cDom mempty) $ \_ -> do
((alice, chad), mp, qcnv) <- runCodensity (startDynamicBackend cDom mempty) $ \_ -> do
ownDomain <- make OwnDomain & asString
otherDomain <- make OtherDomain & asString
[alice, bob, charlie, chad] <-
createAndConnectUsers [ownDomain, otherDomain, cDom.berDomain, cDom.berDomain]

[alice1, bob1, charlie1, chad1] <- traverse (createMLSClient def) [alice, bob, charlie, chad]
traverse_ uploadNewKeyPackage [bob1, charlie1, chad1]
void $ createNewGroup alice1
qcnv <- snd <$> createNewGroup alice1
withWebSockets [bob, charlie] $ \wss -> do
void $ createAddCommit alice1 [bob, charlie] >>= sendAndConsumeCommitBundle
forM_ wss $ awaitMatch 5 isMemberJoinNotif
createAddCommit alice1 [chad]
mp <- createAddCommit alice1 [chad]
pure ((alice, chad), mp, qcnv)

bindResponse (postMLSCommitBundle mp.sender (mkBundle mp)) $ \resp -> do
resp.status `shouldMatchInt` 533
resp.jsonBody %. "unreachable_backends" `shouldMatchSet` [cDom.berDomain]
resp <- sendAndConsumeCommitBundle mp
chadId <- chad %. "qualified_id"
events <- resp %. "events" & asList
do
event <- assertOne events
shouldMatch (event %. "qualified_conversation") qcnv
shouldMatch (event %. "type") "conversation.member-join"
shouldMatch (event %. "from") (objId alice)
members <- event %. "data" %. "users" & asList
memberQids <- for members $ \mem -> mem %. "qualified_id"
shouldMatch memberQids [chadId]

runCodensity (startDynamicBackend cDom mempty) $ \_ ->
withWebSocket chad $ \ws -> do
n <- awaitMatch 10 isMemberJoinNotif ws
n %. "data.qualified_target" `shouldMatch` chadId

0 comments on commit f45127d

Please sign in to comment.