Skip to content

Commit

Permalink
Add test for old /users/prekey endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
smatting committed Feb 23, 2021
1 parent 4ff518c commit e2c2812
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions services/brig/test/integration/API/User/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import qualified Test.Tasty.Cannon as WS
import Test.Tasty.HUnit
import UnliftIO (mapConcurrently)
import Util
import Wire.API.User.Client (UserClientMap (..), UserClients (..))
import Wire.API.UserMap (QualifiedUserMap (..), UserMap (..))

tests :: ConnectionLimit -> Opt.Timeout -> Opt.Opts -> Manager -> Brig -> Cannon -> Galley -> TestTree
Expand All @@ -61,6 +62,7 @@ tests _cl _at opts p b c g =
test p "get /users/<localdomain>/:uid/prekeys - 200" $ testQualifiedGetUserPrekeys b opts,
test p "get /users/:uid/prekeys/:client - 200" $ testGetClientPrekey b,
test p "get /users/<localdomain>/:uid/prekeys/:client - 200" $ testQualifiedGetClientPrekey b opts,
test p "post /users/prekeys" $ testMultiUserGetPrekeys b,
test p "post /users/list-clients - 200" $ testListClientsBulk opts b,
test p "post /clients - 201 (pwd)" $ testAddGetClient True b c,
test p "post /clients - 201 (no pwd)" $ testAddGetClient False b c,
Expand Down Expand Up @@ -253,6 +255,31 @@ testQualifiedGetClientPrekey brig opts = do
const 200 === statusCode
const (Just $ cpk) === responseJsonMaybe

testMultiUserGetPrekeys :: Brig -> Http ()
testMultiUserGetPrekeys brig = do
xs <- generateClients 3 brig
let userClients =
UserClients $
Map.fromList $
xs <&> \(uid, c, _lpk, _cpk) ->
(uid, Set.fromList [clientId c])

let expectedUserClientMap =
UserClientMap $
Map.fromList $
xs <&> \(uid, c, _lpk, cpk) ->
(uid, Map.singleton (clientId c) (Just (prekeyData cpk)))

post
( brig
. paths ["users", "prekeys"]
. contentJson
. body (RequestBodyLBS $ encode userClients)
)
!!! do
const 200 === statusCode
const (Right $ expectedUserClientMap) === responseJsonEither

testTooManyClients :: Opt.Opts -> Brig -> Http ()
testTooManyClients opts brig = do
uid <- userId <$> randomUser brig
Expand Down

0 comments on commit e2c2812

Please sign in to comment.