Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
smatting committed Jul 14, 2021
1 parent 78f38f6 commit 393773c
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions services/galley/test/integration/API/Teams/Feature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ import Control.Monad.Catch (MonadCatch)
import Data.Aeson (FromJSON, ToJSON)
import Data.Id
import Data.List1 (list1)
import qualified Data.List1 as List1
import Data.Timeout (TimeoutUnit (Second), (#))
import Galley.Options (optSettings, setFeatureFlags)
import Galley.Types.Teams
import Gundeck.Types (Notification)
import Imports
import Network.Wai.Utilities (label)
import Test.Tasty
import qualified Test.Tasty.Cannon as WS
import Test.Tasty.HUnit ((@?=))
import TestHelpers (test)
import TestSetup
import Wire.API.Event.FeatureConfig (EventData (EdFeatureWithoutConfigChanged))
import qualified Wire.API.Event.FeatureConfig as FeatureConfig
import qualified Wire.API.Team.Feature as Public

tests :: IO TestSetup -> TestTree
Expand All @@ -45,7 +50,8 @@ tests s =
test s "SearchVisibility" testSearchVisibility,
test s "DigitalSignatures" $ testSimpleFlag @'Public.TeamFeatureDigitalSignatures Public.TeamFeatureDisabled,
test s "ValidateSAMLEmails" $ testSimpleFlag @'Public.TeamFeatureValidateSAMLEmails Public.TeamFeatureDisabled,
test s "FileSharing" $ testSimpleFlag @'Public.TeamFeatureFileSharing Public.TeamFeatureEnabled
test s "FileSharing" $ testSimpleFlag @'Public.TeamFeatureFileSharing Public.TeamFeatureEnabled,
test s "FileSharing - event" $ testSimpleFlagEvent @'Public.TeamFeatureFileSharing Public.TeamFeatureEnabled Public.TeamFeatureDisabled
]

testSSO :: TestM ()
Expand Down Expand Up @@ -267,12 +273,12 @@ testSimpleFlagEvent ::
ToJSON (Public.TeamFeatureStatus a)
) =>
Public.TeamFeatureStatusValue ->
Public.TeamFeatureStatusValue ->
TestM ()
testSimpleFlagEvent defaultValue = do
testSimpleFlagEvent defaultValue newValue = do
let feature = Public.knownTeamFeatureName @a
owner <- Util.randomUser
member <- Util.randomUser
nonMember <- Util.randomUser
tid <- Util.createNonBindingTeam "foo" owner []
Util.connectUsers owner (list1 member [])
Util.addTeamMember owner tid member (rolePermissions RoleMember) Nothing
Expand All @@ -285,21 +291,22 @@ testSimpleFlagEvent defaultValue = do
setFlagInternal statusValue =
Util.putTeamFeatureFlagInternal @a expect2xx tid (Public.TeamFeatureStatusNoConfig statusValue)

getFlag defaultValue

cannon <- view tsCannon
WS.bracketR cannon member $ \ws -> do
setFlagInternal defaultValue

setFlagInternal newValue
void . liftIO $
WS.assertMatch (5 # Second) ws $
wsAssertMemberJoinWithRole qconv qbob [qalice] roleNameWireMember

pure ()

-- wsAssertMemberJoinWithRole :: Qualified ConvId -> Qualified UserId -> [Qualified UserId] -> RoleName -> Notification -> IO ()
-- wsAssertMemberJoinWithRole conv usr new role n = do
-- let e = List1.head (WS.unpackPayload n)
-- ntfTransient n @?= False
-- evtConv e @?= conv
-- evtType e @?= Conv.MemberJoin
-- evtFrom e @?= usr
-- evtData e @?= EdMembersJoin (SimpleMembers (fmap (`SimpleMember` role) new))
wsAssertFeatureConfigUpdate feature newValue

-- clean up
setFlagInternal defaultValue
getFlag defaultValue

wsAssertFeatureConfigUpdate :: Public.TeamFeatureName -> Public.TeamFeatureStatusValue -> Notification -> IO ()
wsAssertFeatureConfigUpdate teamFeature status notification = do
let e :: FeatureConfig.Event = List1.head (WS.unpackPayload notification)
FeatureConfig._eventType e @?= FeatureConfig.Update
FeatureConfig._eventFeatureName e @?= teamFeature
FeatureConfig._eventData e @?= EdFeatureWithoutConfigChanged (Public.TeamFeatureStatusNoConfig status)

0 comments on commit 393773c

Please sign in to comment.