module Test.MLS.Notifications where import API.Gundeck import MLS.Util import Notifications import SetupHelpers import Testlib.Prelude testWelcomeNotification :: (HasCallStack) => App () testWelcomeNotification :: HasCallStack => App () testWelcomeNotification = do [Value alice, Value bob] <- [Domain] -> App [Value] forall domain. (HasCallStack, MakesValue domain) => [domain] -> App [Value] createAndConnectUsers [Domain OwnDomain, Domain OtherDomain] [ClientIdentity alice1, ClientIdentity alice2, ClientIdentity bob1, ClientIdentity bob2] <- (Value -> App ClientIdentity) -> [Value] -> App [ClientIdentity] forall (t :: * -> *) (f :: * -> *) a b. (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) forall (f :: * -> *) a b. Applicative f => (a -> f b) -> [a] -> f [b] traverse (Ciphersuite -> InitMLSClient -> Value -> App ClientIdentity forall u. (MakesValue u, HasCallStack) => Ciphersuite -> InitMLSClient -> u -> App ClientIdentity createMLSClient Ciphersuite forall a. Default a => a def InitMLSClient forall a. Default a => a def) [Value alice, Value alice, Value bob, Value bob] (ClientIdentity -> App String) -> [ClientIdentity] -> App () forall (t :: * -> *) (f :: * -> *) a b. (Foldable t, Applicative f) => (a -> f b) -> t a -> f () traverse_ (HasCallStack => Ciphersuite -> ClientIdentity -> App String Ciphersuite -> ClientIdentity -> App String uploadNewKeyPackage Ciphersuite forall a. Default a => a def) [ClientIdentity alice2, ClientIdentity bob1, ClientIdentity bob2] ConvId convId <- HasCallStack => Ciphersuite -> ClientIdentity -> App ConvId Ciphersuite -> ClientIdentity -> App ConvId createNewGroup Ciphersuite forall a. Default a => a def ClientIdentity alice1 Value notif <- Value -> (WebSocket -> App Value) -> App Value forall w a. (HasCallStack, ToWSConnect w) => w -> (WebSocket -> App a) -> App a withWebSocket Value bob ((WebSocket -> App Value) -> App Value) -> (WebSocket -> App Value) -> App Value forall a b. (a -> b) -> a -> b $ \WebSocket ws -> do App Value -> App () forall (f :: * -> *) a. Functor f => f a -> f () void (App Value -> App ()) -> App Value -> App () forall a b. (a -> b) -> a -> b $ HasCallStack => ClientIdentity -> ConvId -> [Value] -> App MessagePackage ClientIdentity -> ConvId -> [Value] -> App MessagePackage createAddCommit ClientIdentity alice1 ConvId convId [Value alice, Value bob] App MessagePackage -> (MessagePackage -> App Value) -> App Value forall a b. App a -> (a -> App b) -> App b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= HasCallStack => MessagePackage -> App Value MessagePackage -> App Value sendAndConsumeCommitBundle HasCallStack => (Value -> App Bool) -> WebSocket -> App Value (Value -> App Bool) -> WebSocket -> App Value awaitMatch Value -> App Bool forall a. MakesValue a => a -> App Bool isWelcomeNotif WebSocket ws String notifId <- Value notif Value -> String -> App Value forall a. (HasCallStack, MakesValue a) => a -> String -> App Value %. String "id" App Value -> (App Value -> App String) -> App String forall a b. a -> (a -> b) -> b & App Value -> App String forall a. (HasCallStack, MakesValue a) => a -> App String asString [ClientIdentity] -> (ClientIdentity -> App Value) -> App () forall (t :: * -> *) (f :: * -> *) a b. (Foldable t, Applicative f) => t a -> (a -> f b) -> f () for_ [ClientIdentity bob1, ClientIdentity bob2] ((ClientIdentity -> App Value) -> App ()) -> (ClientIdentity -> App Value) -> App () forall a b. (a -> b) -> a -> b $ \ClientIdentity cid -> Value -> GetNotifications -> App Response forall user. (HasCallStack, MakesValue user) => user -> GetNotifications -> App Response getNotifications Value bob GetNotifications forall a. Default a => a def { since = Just notifId, client = Just cid.client, size = Just 10000 } App Response -> (Response -> App Value) -> App Value forall a b. App a -> (a -> App b) -> App b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= HasCallStack => Int -> Response -> App Value Int -> Response -> App Value getJSON Int 200