Skip to content

Commit 627b738

Browse files
committed
add test
1 parent f7cd069 commit 627b738

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

integration/test/Test/UserGroup.hs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,78 @@ testUserGroupUpdateChannelsNonExisting = do
429429
>>= getJSON 201
430430
>>= objConvId
431431
updateUserGroupChannels bob gid [convId.id_] >>= assertLabel 404 "user-group-not-found"
432+
433+
testUserGroupAddUserToGroupWithChannels :: (HasCallStack) => App ()
434+
testUserGroupAddUserToGroupWithChannels = do
435+
(alice, tid, [bob, charlie]) <- createTeam OwnDomain 3
436+
bobId <- asString $ bob %. "id"
437+
charlieId <- asString $ charlie %. "id"
438+
439+
-- Create user group with bob as initial member
440+
ug <-
441+
createUserGroup alice (object ["name" .= "test group", "members" .= [bobId]])
442+
>>= getJSON 200
443+
gid <- ug %. "id" & asString
444+
445+
-- Create a conversation (channel) for the team
446+
convId <-
447+
postConversation alice (defProteus {team = Just tid})
448+
>>= getJSON 201
449+
>>= objConvId
450+
451+
-- Associate the channel with the user group
452+
updateUserGroupChannels alice gid [convId.id_] >>= assertSuccess
453+
454+
-- Add charlie to the group using addUserToGroup
455+
addUserToGroup alice gid charlieId >>= assertSuccess
456+
457+
-- Verify charlie is now in the channel
458+
bindResponse (getConversation alice convId) $ \resp -> do
459+
resp.status `shouldMatchInt` 200
460+
members <- resp.json %. "members" %. "others" >>= asList
461+
memberIds <- for members ((%. "qualified_id") >=> (%. "id") >=> asString)
462+
memberIds `shouldMatchSet` [charlieId]
463+
464+
testUserGroupAddUsersToGroupWithChannels :: (HasCallStack) => App ()
465+
testUserGroupAddUsersToGroupWithChannels = do
466+
(alice, tid, [bob, charlie, dave, eve]) <- createTeam OwnDomain 5
467+
bobId <- asString $ bob %. "id"
468+
charlieId <- asString $ charlie %. "id"
469+
daveId <- asString $ dave %. "id"
470+
eveId <- asString $ eve %. "id"
471+
472+
-- Create user group with bob as initial member
473+
ug <-
474+
createUserGroup alice (object ["name" .= "test group", "members" .= [bobId]])
475+
>>= getJSON 200
476+
gid <- ug %. "id" & asString
477+
478+
-- Create two conversations (channels) for the team
479+
convId1 <-
480+
postConversation alice (defProteus {team = Just tid})
481+
>>= getJSON 201
482+
>>= objConvId
483+
convId2 <-
484+
postConversation alice (defProteus {team = Just tid})
485+
>>= getJSON 201
486+
>>= objConvId
487+
488+
-- Associate both channels with the user group
489+
updateUserGroupChannels alice gid [convId1.id_, convId2.id_] >>= assertSuccess
490+
491+
-- Add charlie, dave, and eve to the group using addUsersToGroup
492+
addUsersToGroup alice gid [charlieId, daveId, eveId] >>= assertSuccess
493+
494+
-- Verify all three users are now in the first channel
495+
bindResponse (getConversation alice convId1) $ \resp -> do
496+
resp.status `shouldMatchInt` 200
497+
members <- resp.json %. "members" %. "others" >>= asList
498+
memberIds <- mapM ((%. "qualified_id") >=> (%. "id") >=> asString) members
499+
memberIds `shouldMatchSet` [charlieId, daveId, eveId]
500+
501+
-- Verify all three users are now in the second channel
502+
bindResponse (getConversation alice convId2) $ \resp -> do
503+
resp.status `shouldMatchInt` 200
504+
members <- resp.json %. "members" %. "others" >>= asList
505+
memberIds <- mapM ((%. "qualified_id") >=> (%. "id") >=> asString) members
506+
memberIds `shouldMatchSet` [charlieId, daveId, eveId]

0 commit comments

Comments
 (0)