Skip to content

Commit

Permalink
ping pong test
Browse files Browse the repository at this point in the history
  • Loading branch information
battermann committed Oct 7, 2024
1 parent 102eb0e commit 3321d48
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions integration/test/Test/Events.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Test.Events (testConsumeEventsOneWebSocket, testConsumeEventsNewWebSockets) where
module Test.Events where

import API.Brig
import API.BrigCommon
Expand All @@ -22,7 +22,7 @@ testConsumeEventsOneWebSocket = do
clientId <- objId client

withNewWebSocket alice clientId $ \eventsChan ackChan -> do
deliveryTag <- assertEvent eventsChan $ \(e :: Value) -> do
deliveryTag <- assertEvent eventsChan $ \e -> do
e %. "payload.0.type" `shouldMatch` "user.client-add"
e %. "payload.0.client.id" `shouldMatch` clientId
e %. "delivery_tag"
Expand All @@ -33,7 +33,7 @@ testConsumeEventsOneWebSocket = do
handle <- randomHandle
putHandle alice handle >>= assertSuccess

assertEvent eventsChan $ \(e :: Value) -> do
assertEvent eventsChan $ \e -> do
e %. "payload.0.type" `shouldMatch` "user.update"
e %. "payload.0.user.handle" `shouldMatch` handle

Expand All @@ -44,7 +44,7 @@ testConsumeEventsNewWebSockets = do
clientId <- objId client

withNewWebSocket alice clientId $ \eventsChan ackChan -> do
deliveryTag <- assertEvent eventsChan $ \(e :: Value) -> do
deliveryTag <- assertEvent eventsChan $ \e -> do
e %. "payload.0.type" `shouldMatch` "user.client-add"
e %. "payload.0.client.id" `shouldMatch` clientId
e %. "delivery_tag"
Expand All @@ -60,10 +60,21 @@ testConsumeEventsNewWebSockets = do
putHandle alice handle >>= assertSuccess

void $ withNewWebSocket alice clientId $ \eventsChan _ -> do
assertEvent eventsChan $ \(e :: Value) -> do
assertEvent eventsChan $ \e -> do
e %. "payload.0.type" `shouldMatch` "user.update"
e %. "payload.0.user.handle" `shouldMatch` handle

testPingPong :: (HasCallStack) => App ()
testPingPong = do
alice <- randomUser OwnDomain def
client <- addClient alice def {acapabilities = Just ["consumable-notifications"]} >>= getJSON 201
clientId <- objId client

withNewWebSocket alice clientId $ \eventsChan ackChan -> do
assertEvent eventsChan $ const $ pure ()
sendMsg ackChan $ object ["type" .= "ping"]
assertEvent eventsChan $ \e -> e %. "type" `shouldMatch` "pong"

----------------------------------------------------------------------
-- helpers

Expand Down Expand Up @@ -126,5 +137,3 @@ eventsWebSocket user clientId eventsChan ackChan = do
WS.defaultConnectionOptions
caHdrs
app

-- TODO: test pingpong? or drop it?

0 comments on commit 3321d48

Please sign in to comment.