Skip to content

Commit

Permalink
Test: dequeueing a payload bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
mdimjasevic committed Jan 26, 2024
1 parent c10068c commit f8d8b54
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Util.Options
import Wire.API.Federation.API
import Wire.API.Federation.API.Brig
import Wire.API.Federation.API.Common
import Wire.API.Federation.API.Galley
import Wire.API.Federation.BackendNotifications
import Wire.API.RawJson
import Wire.BackendNotificationPusher
Expand Down Expand Up @@ -93,6 +94,43 @@ spec = do
getVectorWith env.backendNotificationMetrics.pushedCounter getCounter
`shouldReturn` [(domainText targetDomain, 1)]

it "should push notification bundles" $ do
let returnSuccess _ = pure ("application/json", Aeson.encode EmptyResponse)
let origDomain = Domain "origin.example.com"
targetDomain = Domain "target.example.com"
-- Just using 'arbitrary' could generate a very big list, making tests very
-- slow. Make me wonder if notification pusher should even try to parse the
-- actual content, seems like wasted compute power.
notifContent <-
generate $
ClientRemovedRequest <$> arbitrary <*> arbitrary <*> arbitrary
let bundle = toBundle @'OnClientRemovedTag (RequestId "N/A") origDomain notifContent
envelope <- newMockEnvelope
let msg =
Q.newMsg
{ Q.msgBody = Aeson.encode bundle,
Q.msgContentType = Just "application/json"
}
runningFlag <- newMVar ()
(env, fedReqs) <-
withTempMockFederator [] returnSuccess . runTestAppT $ do
wait =<< pushNotification runningFlag targetDomain (msg, envelope)
ask

readIORef envelope.acks `shouldReturn` 1
readIORef envelope.rejections `shouldReturn` []
fedReqs
`shouldBe` [ FederatedRequest
{ frTargetDomain = targetDomain,
frOriginDomain = origDomain,
frComponent = Brig,
frRPC = "on-client-removed",
frBody = Aeson.encode notifContent
}
]
getVectorWith env.backendNotificationMetrics.pushedCounter getCounter
`shouldReturn` [(domainText targetDomain, 1)]

it "should reject invalid notifications" $ do
let returnSuccess _ = pure ("application/json", Aeson.encode EmptyResponse)
envelope <- newMockEnvelope
Expand Down

0 comments on commit f8d8b54

Please sign in to comment.