|
17 | 17 |
|
18 | 18 | module Test.MLS.Notifications where |
19 | 19 |
|
| 20 | +import API.Galley |
20 | 21 | import API.Gundeck |
| 22 | +import Control.Concurrent |
| 23 | +import Data.Timeout |
21 | 24 | import MLS.Util |
22 | 25 | import Notifications |
23 | 26 | import SetupHelpers |
@@ -45,3 +48,49 @@ testWelcomeNotification = do |
45 | 48 | size = Just 10000 |
46 | 49 | } |
47 | 50 | >>= getJSON 200 |
| 51 | + |
| 52 | +testNotificationPagination :: (HasCallStack) => App () |
| 53 | +testNotificationPagination = do |
| 54 | + {- |
| 55 | + Create a user with client1 |
| 56 | +
|
| 57 | + Wait for all the notifications to expire (there should be no notifications which are sent to “All Clients”, i.e. there should be no notifications in the DB where clients field is null. |
| 58 | +
|
| 59 | + Send a lot of MLS messages to this client (so that the total payload size goes over 5 MB) |
| 60 | +
|
| 61 | + Create another client (say client2) |
| 62 | +
|
| 63 | + Fetch notifications for client 2 |
| 64 | + -} |
| 65 | + |
| 66 | + let overrides = def {gundeckCfg = setField "settings.notificationTTL" (2 #> Second)} |
| 67 | + withModifiedBackend overrides $ \dom -> do |
| 68 | + -- create a user with client1 |
| 69 | + [alice, bob] <- createAndConnectUsers [dom, dom] |
| 70 | + [alice1, bob1] <- traverse (createMLSClient def) [alice, bob] |
| 71 | + traverse_ (uploadNewKeyPackage def) [alice1, bob1] |
| 72 | + |
| 73 | + conv <- postConversation alice1 defMLS >>= getJSON 201 |
| 74 | + _convQid <- conv %. "qualified_id" |
| 75 | + convId <- objConvId conv |
| 76 | + createGroup def alice1 convId |
| 77 | + void $ createAddCommit alice1 convId [bob] >>= sendAndConsumeCommitBundle |
| 78 | + |
| 79 | + -- let notifs expire |
| 80 | + liftIO $ threadDelay 2_300_000 |
| 81 | + |
| 82 | + -- bob sends alice > 5MB of MLS messages |
| 83 | + let payload = replicate 20_000 '.' |
| 84 | + forM_ [1 :: Int .. 260] $ \i -> do |
| 85 | + print i |
| 86 | + void $ createApplicationMessage convId bob1 payload >>= sendAndConsumeMessage |
| 87 | + |
| 88 | + -- create new client for alice, fetch notifications, and check response consistency. |
| 89 | + alice2 :: ClientIdentity <- createMLSClient def alice |
| 90 | + getNotifications |
| 91 | + alice |
| 92 | + def {since = Nothing, size = Nothing, client = Just alice2.client} |
| 93 | + `bindResponse` \resp -> do |
| 94 | + resp.status `shouldMatchInt` 200 |
| 95 | + resp.json %. "has_more" `shouldMatch` False |
| 96 | + resp.json %. "notifications" `shouldMatch` ([] :: [()]) |
0 commit comments