From 2935f08cf27a73fd157e5f46cafbc5e6095ae3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Dimja=C5=A1evi=C4=87?= Date: Thu, 3 Jun 2021 10:21:56 +0200 Subject: [PATCH 1/2] Introduces the HasGalley class - It allows to access a Galley instance in a monad implementing the class. --- services/galley/test/integration/API.hs | 60 +++++++++----------- services/galley/test/integration/API/Util.hs | 14 ++++- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/services/galley/test/integration/API.hs b/services/galley/test/integration/API.hs index fff6f41a9ca..99b8537ebe6 100644 --- a/services/galley/test/integration/API.hs +++ b/services/galley/test/integration/API.hs @@ -888,12 +888,11 @@ testAddRemoteMember = do opts <- view tsGConf g <- view tsGalley (resp, _) <- - liftIO $ - withTempMockFederator - opts - remoteDomain - (const [mkProfile remoteBob (Name "bob")]) - (postQualifiedMembers' g alice (remoteBob :| []) convId) + withTempMockFederator + opts + remoteDomain + (const [mkProfile remoteBob (Name "bob")]) + (postQualifiedMembers' g alice (remoteBob :| []) convId) e <- responseJsonUnsafe <$> (pure resp (pure resp postConv alice [] (Just "remote gossip") [] Nothing Nothing opts <- view tsGConf g <- view tsGalley - liftIO $ do - (resp, _) <- - withTempMockFederator - opts - remoteDomain - (const [mkProfile remoteCharlie (Name "charlie")]) - (postQualifiedMembers' g alice (remoteBob :| [remoteCharlie]) convId) - statusCode resp @?= 400 - let err = responseJsonUnsafe resp :: Object - (err ^. at "label") @?= Just "unknown-remote-user" + (resp, _) <- + withTempMockFederator + opts + remoteDomain + (const [mkProfile remoteCharlie (Name "charlie")]) + (postQualifiedMembers' g alice (remoteBob :| [remoteCharlie]) convId) + liftIO $ statusCode resp @?= 400 + let err = responseJsonUnsafe resp :: Object + liftIO $ (err ^. at "label") @?= Just "unknown-remote-user" testAddDeletedRemoteUser :: TestM () testAddDeletedRemoteUser = do @@ -979,16 +976,15 @@ testAddDeletedRemoteUser = do convId <- decodeConvId <$> postConv alice [] (Just "remote gossip") [] Nothing Nothing opts <- view tsGConf g <- view tsGalley - liftIO $ do - (resp, _) <- - withTempMockFederator - opts - remoteDomain - (const [(mkProfile remoteBob (Name "bob")) {profileDeleted = True}]) - (postQualifiedMembers' g alice (remoteBob :| []) convId) - statusCode resp @?= 400 - let err = responseJsonUnsafe resp :: Object - (err ^. at "label") @?= Just "unknown-remote-user" + (resp, _) <- + withTempMockFederator + opts + remoteDomain + (const [(mkProfile remoteBob (Name "bob")) {profileDeleted = True}]) + (postQualifiedMembers' g alice (remoteBob :| []) convId) + liftIO $ statusCode resp @?= 400 + let err = responseJsonUnsafe resp :: Object + liftIO $ (err ^. at "label") @?= Just "unknown-remote-user" testAddRemoteMemberInvalidDomain :: TestM () testAddRemoteMemberInvalidDomain = do diff --git a/services/galley/test/integration/API/Util.hs b/services/galley/test/integration/API/Util.hs index 6ae81905b6c..b4836c8206b 100644 --- a/services/galley/test/integration/API/Util.hs +++ b/services/galley/test/integration/API/Util.hs @@ -22,13 +22,13 @@ module API.Util where import qualified API.SQS as SQS import Bilge hiding (timeout) import Bilge.Assert +import Bilge.TestSession import Brig.Types import Brig.Types.Intra (ConnectionStatus (ConnectionStatus), UserAccount (..), UserSet (..)) import Brig.Types.Team.Invitation import Brig.Types.User.Auth (CookieLabel (..)) -import Control.Exception (finally) import Control.Lens hiding (from, to, (#), (.=)) -import Control.Monad.Catch (MonadCatch) +import Control.Monad.Catch (MonadCatch, finally) import Control.Monad.Except (ExceptT, runExceptT) import Control.Retry (constantDelay, exponentialBackoff, limitRetries, retrying) import Data.Aeson hiding (json) @@ -101,6 +101,16 @@ import qualified Wire.API.User.Client as Client ------------------------------------------------------------------------------- -- API Operations +-- | A class for monads with access to a Galley instance +class HasGalley m where + viewGalley :: m GalleyR + +instance HasGalley TestM where + viewGalley = view tsGalley + +instance (HasGalley m, Monad m) => HasGalley (SessionT m) where + viewGalley = lift viewGalley + symmPermissions :: [Perm] -> Permissions symmPermissions p = let s = Set.fromList p in fromJust (newPermissions s s) From dcc4e60c3adad915903798513dc087e6e6a72eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Dimja=C5=A1evi=C4=87?= Date: Thu, 3 Jun 2021 11:12:25 +0200 Subject: [PATCH 2/2] Hi CI