Skip to content

Commit

Permalink
[feat] move testInternalGetConStatusesAll to new testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
MangoIV committed Dec 13, 2023
1 parent a1225f5 commit 1e72c77
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
18 changes: 18 additions & 0 deletions integration/test/API/BrigInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module API.BrigInternal where

import API.Common
import Data.Aeson qualified as Aeson
import Data.Aeson.Types (Pair)
import Data.Function
import Data.Maybe
import Testlib.Prelude
Expand Down Expand Up @@ -187,3 +188,20 @@ deleteFederationRemoteTeam domain remoteDomain team = do
req <- baseRequest domain Brig Unversioned $ joinHttpPath ["i", "federation", "remotes", d, "teams", t]
res <- submit "DELETE" req
res.status `shouldMatchInt` 200

getConnStatusForUsers :: (HasCallStack, MakesValue users) => users -> Domain -> App Response
getConnStatusForUsers users domain = do
usersList <-
asList users >>= \us -> do
dom <- us `for` (%. "qualified_id.domain")
dom `for_` (`shouldMatch` make domain)
us `for` (%. "id")
usersJSON <- make usersList
getConnStatusInternal ["from" .= usersJSON] domain

getConnStatusInternal :: (HasCallStack) => [Pair] -> Domain -> App Response
getConnStatusInternal body dom = do
req <- baseRequest dom Brig Unversioned do
joinHttpPath ["i", "users", "connections-status", "v2"]
submit "POST" do
req & addJSONObject body
44 changes: 43 additions & 1 deletion integration/test/Test/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
module Test.Connection where

import API.Brig (getConnection, postConnection, putConnection)
import API.BrigInternal (getConnStatusForUsers)
import API.Galley
import SetupHelpers
import Testlib.Prelude
Expand All @@ -38,7 +39,7 @@ testConnectWithRemoteUser owningDomain = do
qIds <- for others (%. "qualified_id")
qIds `shouldMatchSet` [aliceId]

testRemoteUserGetsDeleted :: App ()
testRemoteUserGetsDeleted :: HasCallStack => App ()
testRemoteUserGetsDeleted = do
alice <- randomUser OwnDomain def

Expand Down Expand Up @@ -92,6 +93,47 @@ testRemoteUserGetsDeleted = do
getConnection alice charlie `waitForResponse` \resp ->
resp.status `shouldMatchInt` 404

testInternalGetConStatusesAll :: HasCallStack => App ()
testInternalGetConStatusesAll = do
startDynamicBackends [mempty] \[dynBackend] -> do
let mkFiveUsers dom = replicateM 5 do
randomUser dom def
alices <- mkFiveUsers OwnDomain
bobs <- mkFiveUsers OwnDomain
charlies <- mkFiveUsers OtherDomain
dylans <- mkFiveUsers dynBackend
for_ alices \alicei -> do
let connectWith users = do
for_ users \useri ->
postConnection alicei useri `bindResponse` \resp ->
resp.status `shouldMatchInt` 201
putConnection (head users) alicei "accepted" `bindResponse` \resp ->
resp.status `shouldMatchOneOf` [Number 200, Number 204]
-- local: connect each alice, accept only one
connectWith bobs
-- remote 1 & 2: connect each alice, accept only one
connectWith charlies
connectWith dylans

getConnStatusForUsers alices OwnDomain `bindResponse` \resp -> do
resp.status `shouldMatchInt` 200
conns <- asList resp.json
let statusIs f =
filterM
do
\conn -> do
s <- conn %. "status" & asString
pure $ f s
conns

sent <- statusIs (== "sent")
accepted <- statusIs (== "accepted")
other <- statusIs \v -> v /= "sent" && v /= "accepted"

length other `shouldMatchInt` 0
length accepted `shouldMatchInt` 15
length sent `shouldMatchInt` 60

assertConnectionStatus ::
( HasCallStack,
MakesValue userFrom,
Expand Down
2 changes: 1 addition & 1 deletion integration/test/Test/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ testNotificationsForOfflineBackends = do

-- FUTUREWORK: Uncomment after fixing this bug: https://wearezeta.atlassian.net/browse/WPB-3664
-- void $ awaitNotification downUser1 downClient1 (Just newMsgNotif) 1 isOtherUser2LeaveUpConvNotif
-- void $ awaitNotification otherUser otherClient (Just newMsgNotif) 1 isDelUserLeaveDownConvNotif
void $ awaitNotification otherUser otherClient (Just newMsgNotif) isDelUserLeaveDownConvNotif

delUserDeletedNotif <- nPayload $ awaitNotification downUser1 downClient1 (Just newMsgNotif) isDeleteUserNotif
objQid delUserDeletedNotif `shouldMatch` objQid delUser

0 comments on commit 1e72c77

Please sign in to comment.