Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduces the HasGalley class #1568

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions services/galley/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <!! const 200 === statusCode)
liftIO $ do
evtConv e @?= convId
Expand Down Expand Up @@ -936,12 +935,11 @@ testGetRemoteConversation = do
opts <- view tsGConf
g <- view tsGalley
(resp, _) <-
liftIO $
withTempMockFederator
opts
remoteDomain
(const remoteConversationResponse)
(getConvQualified' g alice remoteConv)
withTempMockFederator
opts
remoteDomain
(const remoteConversationResponse)
(getConvQualified' g alice remoteConv)
conv :: Conversation <- responseJsonUnsafe <$> (pure resp <!! const 200 === statusCode)
liftIO $ do
let actual = cmOthers $ cnvMembers conv
Expand All @@ -959,16 +957,15 @@ testAddRemoteMemberFailure = do
convId <- decodeConvId <$> 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
Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions services/galley/test/integration/API/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down