Skip to content

Commit

Permalink
Fixup: test
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Feb 6, 2024
1 parent 7987390 commit 44a8377
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions services/brig/test/integration/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Cassandra qualified as C
import Cassandra qualified as Cass
import Cassandra.Util
import Control.Exception (ErrorCall (ErrorCall), throwIO)
import Control.Lens ((^.), (^?!))
import Control.Lens ((%~), (^.), (^?!), _1, _2)
import Data.Aeson qualified as Aeson
import Data.Aeson.Lens qualified as Aeson
import Data.Aeson.Types qualified as Aeson
Expand Down Expand Up @@ -110,7 +110,8 @@ testEJPDRequest mgr brig brigep gundeck cargohold = do

addAsset :: ByteString -> UserId -> m Text
addAsset msg uid = do
ast <- responseJsonError =<< uploadAsset cargohold uid Asset.defAssetSettings (msg <> ": profile pic of " <> toByteString' uid)
let payload = msg <> ": profile pic of " <> toByteString' uid
ast <- responseJsonError =<< uploadAsset cargohold uid Asset.defAssetSettings payload
downloadAsset cargohold uid (ast ^. Asset.assetKey) !!! const 200 === statusCode
let newAssets =
Just
Expand All @@ -121,9 +122,7 @@ testEJPDRequest mgr brig brigep gundeck cargohold = do
userUpdate = UserUpdate Nothing Nothing newAssets Nothing
update = RequestBodyLBS . Aeson.encode $ userUpdate
put (brig . path "/self" . contentJson . zUser uid . zConn "c" . body update) !!! const 200 === statusCode
pure . cs $
let Qualified key dom = ast ^. Asset.assetKey
in toByteString' dom <> "/" <> toByteString' key
pure (cs payload)

asset11 <- addAsset "1" uid1
asset12 <- addAsset "2" uid1
Expand All @@ -138,20 +137,43 @@ testEJPDRequest mgr brig brigep gundeck cargohold = do
convs2 <- pure Nothing
pure (convs1, convs2)

let check :: HasCallStack => EJPDResponseBody -> EJPDResponseBody -> m ()
check want have = do
liftIO $ assertEqual "" (withoutAssetsB want) (withoutAssetsB have)
checkAssets want have

withoutAssetsB :: EJPDResponseBody -> EJPDResponseBody
withoutAssetsB = EJPDResponseBody . fmap withoutAssetsI . ejpdResponseBody

withoutAssetsI :: EJPDResponseItem -> EJPDResponseItem
withoutAssetsI i =
i
{ ejpdResponseAssets = Nothing,
ejpdResponseContacts = Set.map (_2 %~ withoutAssetsI) <$> ejpdResponseContacts i,
ejpdResponseTeamContacts = (_1 %~ Set.map withoutAssetsI) <$> ejpdResponseTeamContacts i
}

checkAssets :: EJPDResponseBody -> EJPDResponseBody -> m ()
checkAssets
(fmap ejpdResponseAssets . ejpdResponseBody -> (want :: [Maybe (Set Text)]))
(fmap ejpdResponseAssets . ejpdResponseBody -> (have :: [Maybe (Set Text)])) =
error $ show (want, have)

do
let req = EJPDRequestBody [handle1]
usr1 = mkUsr1 Nothing Nothing convs1 assets1
want = EJPDResponseBody [usr1]
have <- ejpdRequestClient brigep mgr Nothing req
liftIO $ assertEqual "" want have
pure ()
-- check want have

do
let req = EJPDRequestBody [handle1, handle2]
usr1 = mkUsr1 Nothing Nothing convs1 assets1
usr2 = mkUsr2 Nothing Nothing convs2 assets2
want = EJPDResponseBody [usr1, usr2]
have <- ejpdRequestClient brigep mgr Nothing req
liftIO $ assertEqual "" want have
check want have

do
let req = EJPDRequestBody [handle2]
Expand All @@ -160,7 +182,7 @@ testEJPDRequest mgr brig brigep gundeck cargohold = do
want = EJPDResponseBody [usr2]

have <- ejpdRequestClient brigep mgr (Just True) req
liftIO $ assertEqual "" want have
check want have

do
let req = EJPDRequestBody [handle1, handle2]
Expand All @@ -169,7 +191,7 @@ testEJPDRequest mgr brig brigep gundeck cargohold = do
usr3 = mkUsr3 Nothing Nothing Nothing Nothing
want = EJPDResponseBody [usr1, usr2]
have <- ejpdRequestClient brigep mgr (Just True) req
liftIO $ assertEqual "" want have
check want have

testFeatureConferenceCallingByAccount :: forall m. (TestConstraints m) => Opt.Opts -> Manager -> Cass.ClientState -> Brig -> Endpoint -> Galley -> m ()
testFeatureConferenceCallingByAccount (Opt.optSettings -> settings) mgr db brig brigep galley = do
Expand Down

0 comments on commit 44a8377

Please sign in to comment.