From 5b0d0f19ce73436b8dcb1b5a194d6785740b03ff Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Mon, 18 Aug 2025 15:14:39 +0000 Subject: [PATCH] core: add tests for forwarding of connection deleting events in support scope (#6197) --- tests/ChatTests/Groups.hs | 169 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/tests/ChatTests/Groups.hs b/tests/ChatTests/Groups.hs index 58415e3826..2ab46ee657 100644 --- a/tests/ChatTests/Groups.hs +++ b/tests/ChatTests/Groups.hs @@ -212,6 +212,9 @@ chatGroupTests = do it "should forward group wide message (x.grp.info) to all members, including in review" testScopedSupportForwardAll it "should not forward messages between support scopes" testScopedSupportDontForwardBetweenScopes it "should forward file inside support scope" testScopedSupportForwardFile + it "should forward member removal in support scope in review (x.grp.mem.del)" testScopedSupportForwardMemberRemoval + it "should forward admin removal in support scope in review (x.grp.mem.del, relay forwards it was removed)" testScopedSupportForwardAdminRemoval + it "should forward group deletion in support scope in review (x.grp.del)" testScopedSupportForwardGroupDeletion it "should send messages to admins and members" testSupportCLISendCommand it "should correctly maintain unread stats for support chats on reading chat items" testScopedSupportUnreadStatsOnRead it "should correctly maintain unread stats for support chats on deleting chat items" testScopedSupportUnreadStatsOnDelete @@ -7578,6 +7581,172 @@ testScopedSupportForwardFile = ] dan <## "completed receiving file 1 (test.jpg) from bob" +testScopedSupportForwardMemberRemoval :: HasCallStack => TestParams -> IO () +testScopedSupportForwardMemberRemoval = + testChat5 aliceProfile bobProfile cathProfile danProfile eveProfile $ + \alice bob cath dan eve -> do + createGroup4 "team" alice (bob, GRAdmin) (cath, GRMember) (dan, GRModerator) + setupReviewForward alice bob cath dan eve + + -- bob removes eve, eve and dan receive member removal message + bob ##> "/_remove #1 5" + concurrentlyN_ + [ bob <## "#team: you removed eve from the group", + alice <## "#team: bob removed eve from the group", + dan <## "#team: bob removed eve from the group", + do + eve <## "#team: bob removed you from the group" + eve <## "use /d #team to delete the group" + ] + + alice ##> "#team (support: eve) hi" + alice <## "bad chat command: support member not current or pending" + bob ##> "#team (support: eve) hi" + bob <## "bad chat command: support member not current or pending" + dan ##> "#team (support: eve) hi" + dan <## "bad chat command: support member not current or pending" + eve ##> "/groups" + eve <## "#team (you are removed, delete local copy: /d #team)" + +setupReviewForward :: TestCC -> TestCC -> TestCC -> TestCC -> TestCC -> IO () +setupReviewForward alice bob cath dan eve = do + alice ##> "/set admission review #team all" + alice <## "changed member admission rules" + concurrentlyN_ + [ do + bob <## "alice updated group #team:" + bob <## "changed member admission rules", + do + cath <## "alice updated group #team:" + cath <## "changed member admission rules", + do + dan <## "alice updated group #team:" + dan <## "changed member admission rules" + ] + + alice ##> "/create link #team" + gLink <- getGroupLink alice "team" GRMember True + eve ##> ("/c " <> gLink) + eve <## "connection request sent!" + alice <## "eve (Eve): accepting request to join group #team..." + concurrentlyN_ + [ alice <## "#team: eve connected and pending review", + eve + <### [ "#team: alice accepted you to the group, pending review", + "#team: joining the group...", + "#team: you joined the group, connecting to group moderators for admission to group", + "#team: member bob (Bob) is connected", + "#team: member dan (Daniel) is connected" + ], + do + bob <## "#team: alice added eve (Eve) to the group (connecting and pending review...), use /_accept member #1 5 to accept member" + bob <## "#team: new member eve is connected and pending review, use /_accept member #1 5 to accept member", + do + dan <## "#team: alice added eve (Eve) to the group (connecting and pending review...), use /_accept member #1 5 to accept member" + dan <## "#team: new member eve is connected and pending review, use /_accept member #1 5 to accept member" + ] + + setupGroupForwarding alice bob eve + setupGroupForwarding alice bob dan + + -- alice forwards messages between bob and eve, bob and dan + eve #> "#team (support) 3" + [alice, dan] *<# "#team (support: eve) eve> 3" + bob <# "#team (support: eve) eve> 3 [>>]" + + dan #> "#team (support: eve) 4" + alice <# "#team (support: eve) dan> 4" + bob <# "#team (support: eve) dan> 4 [>>]" + eve <# "#team (support) dan> 4" + + bob #> "#team (support: eve) 5" + alice <# "#team (support: eve) bob> 5" + dan <# "#team (support: eve) bob> 5 [>>]" + eve <# "#team (support) bob> 5 [>>]" + +testScopedSupportForwardAdminRemoval :: HasCallStack => TestParams -> IO () +testScopedSupportForwardAdminRemoval = + testChat5 aliceProfile bobProfile cathProfile danProfile eveProfile $ + \alice bob cath dan eve -> do + createGroup4 "team" alice (bob, GROwner) (cath, GRMember) (dan, GRModerator) + setupReviewForward alice bob cath dan eve + + -- bob removes eve, eve and dan receive member removal message + bob ##> "/rm team alice" + concurrentlyN_ + [ bob <## "#team: you removed alice from the group", + do + alice <## "#team: bob removed you from the group" + alice <## "use /d #team to delete the group", + cath <## "#team: bob removed alice from the group", + dan <## "#team: bob removed alice from the group", + eve <## "#team: bob removed alice from the group" + ] + + -- there is no forwarding admin anymore between bob and cath, + -- so messages between bob and eve, bob and dan don't get delivered + -- (this is not a desired behavior, just a test demonstration/proof of current implementation) + eve #> "#team (support) hi" + concurrentlyN_ + [ dan <# "#team (support: eve) eve> hi", + (bob "#team (support: eve) hey" + concurrentlyN_ + [ eve <# "#team (support) dan> hey", + (bob "#team (support: eve) hello" + concurrentlyN_ + [ (eve "/groups" + alice <## "#team (you are removed, delete local copy: /d #team)" + +testScopedSupportForwardGroupDeletion :: HasCallStack => TestParams -> IO () +testScopedSupportForwardGroupDeletion = + testChat5 aliceProfile bobProfile cathProfile danProfile eveProfile $ + \alice bob cath dan eve -> do + createGroup4 "team" alice (bob, GROwner) (cath, GRMember) (dan, GRModerator) + setupReviewForward alice bob cath dan eve + + -- if bob deletes the group, alice forwards it to eve and dan + bob ##> "/d #team" + concurrentlyN_ + [ bob <## "#team: you deleted the group", + do + alice <## "#team: bob deleted the group" + alice <## "use /d #team to delete the local copy of the group", + do + cath <## "#team: bob deleted the group" + cath <## "use /d #team to delete the local copy of the group", + do + dan <## "#team: bob deleted the group" + dan <## "use /d #team to delete the local copy of the group", + do + eve <## "#team: bob deleted the group" + eve <## "use /d #team to delete the local copy of the group" + ] + + alice ##> "/groups" + alice <## "#team (group deleted, delete local copy: /d #team)" + bob ##> "/groups" + bob <## "you have no groups!" + bob <## "to create: /g " + cath ##> "/groups" + cath <## "#team (group deleted, delete local copy: /d #team)" + dan ##> "/groups" + dan <## "#team (group deleted, delete local copy: /d #team)" + eve ##> "/groups" + eve <## "#team (group deleted, delete local copy: /d #team)" + testSupportCLISendCommand :: HasCallStack => TestParams -> IO () testSupportCLISendCommand = testChat2 aliceProfile bobProfile $ \alice bob -> do