Skip to content

Commit e10e66e

Browse files
committed
Add End2end test for deleting a user
1 parent e2bca95 commit e10e66e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

services/brig/test/integration/API/User/Util.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ import qualified Data.Vector as Vec
5050
import Federation.Util (withTempMockFederator)
5151
import Gundeck.Types (Notification (..))
5252
import Imports
53+
import qualified Test.Tasty.Cannon as WS
5354
import Test.Tasty.HUnit
5455
import Util
56+
import qualified Wire.API.Event.Conversation as Conv
5557
import qualified Wire.API.Federation.API.Brig as F
5658
import Wire.API.Federation.GRPC.Types hiding (body, path)
5759
import qualified Wire.API.Federation.GRPC.Types as F
@@ -462,3 +464,15 @@ matchDeleteUserNotification quid n = do
462464
etype @?= Just "user.delete"
463465
eUnqualifiedId @?= Just (qUnqualified quid)
464466
eQualifiedId @?= Just quid
467+
468+
matchConvLeaveNotification :: Qualified ConvId -> Qualified UserId -> [Qualified UserId] -> Notification -> IO ()
469+
matchConvLeaveNotification conv remover removeds n = do
470+
let e = List1.head (WS.unpackPayload n)
471+
ntfTransient n @?= False
472+
Conv.evtConv e @?= conv
473+
Conv.evtType e @?= Conv.MemberLeave
474+
Conv.evtFrom e @?= remover
475+
sorted (Conv.evtData e) @?= sorted (Conv.EdMembersLeave (Conv.QualifiedUserIdList removeds))
476+
where
477+
sorted (Conv.EdMembersLeave (Conv.QualifiedUserIdList m)) = Conv.EdMembersLeave (Conv.QualifiedUserIdList (sort m))
478+
sorted x = x

services/brig/test/integration/Federation/End2end.hs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
module Federation.End2end where
1919

2020
import API.Search.Util
21-
import API.User.Util (getUserClientsQualified)
21+
import API.User.Util
2222
import Bilge
2323
import Bilge.Assert ((!!!), (<!!), (===))
2424
import Brig.API.Client (pubClient)
@@ -98,7 +98,8 @@ spec _brigOpts mg brig galley cannon _federator brigTwo galleyTwo =
9898
test mg "leave a remote conversation" $ leaveRemoteConversation brig galley brigTwo galleyTwo,
9999
test mg "include remote users to new conversation" $ testRemoteUsersInNewConv brig galley brigTwo galleyTwo,
100100
test mg "send a message to a remote user" $ testSendMessage brig brigTwo galleyTwo cannon,
101-
test mg "send a message in a remote conversation" $ testSendMessageToRemoteConv brig brigTwo galley galleyTwo cannon
101+
test mg "send a message in a remote conversation" $ testSendMessageToRemoteConv brig brigTwo galley galleyTwo cannon,
102+
test mg "delete user connected to remotes and in conversation with remotes" $ testDeleteUser brig brigTwo galley galleyTwo cannon
102103
]
103104

104105
-- | Path covered by this test:
@@ -595,3 +596,26 @@ testSendMessageToRemoteConv brig1 brig2 galley1 galley2 cannon1 = do
595596
@?= EdOtrMessage
596597
( OtrMessage bobClient aliceClient (toBase64Text msgText) (Just "")
597598
)
599+
600+
testDeleteUser :: Brig -> Brig -> Galley -> Galley -> Cannon -> Http ()
601+
testDeleteUser brig1 brig2 galley1 galley2 cannon1 = do
602+
alice <- userQualifiedId <$> randomUser brig1
603+
bobDel <- userQualifiedId <$> randomUser brig2
604+
605+
connectUsersEnd2End brig1 brig2 alice bobDel
606+
607+
conv1 <-
608+
fmap cnvQualifiedId . responseJsonError
609+
=<< createConversation galley1 (qUnqualified alice) [bobDel]
610+
<!! const 201 === statusCode
611+
612+
conv2 <-
613+
fmap cnvQualifiedId . responseJsonError
614+
=<< createConversation galley2 (qUnqualified bobDel) [alice]
615+
<!! const 201 === statusCode
616+
617+
WS.bracketR cannon1 (qUnqualified alice) $ \wsAlice -> do
618+
deleteUser (qUnqualified bobDel) (Just defPassword) brig2 !!! const 200 === statusCode
619+
WS.assertMatch_ (5 # Second) wsAlice $ matchDeleteUserNotification bobDel
620+
WS.assertMatch_ (5 # Second) wsAlice $ matchConvLeaveNotification conv1 bobDel [bobDel]
621+
WS.assertMatch_ (5 # Second) wsAlice $ matchConvLeaveNotification conv2 bobDel [bobDel]

0 commit comments

Comments
 (0)