-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit test module for TeamInvitationSubsystem.
- Loading branch information
Showing
9 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
libs/wire-subsystems/test/unit/Wire/MockInterpreters/EnterpriseLoginSubsystem.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Wire.MockInterpreters.EnterpriseLoginSubsystem where | ||
|
||
import Imports | ||
import Polysemy | ||
import Wire.EnterpriseLoginSubsystem | ||
|
||
-- HINT: This is used to test AuthenticationSubsystem, ...; not to test itself! | ||
enterpriseLoginSubsystemTestInterpreter :: InterpreterFor EnterpriseLoginSubsystem r | ||
enterpriseLoginSubsystemTestInterpreter = | ||
interpret \case | ||
LockDomain _ -> undefined -- :: Domain -> EnterpriseLoginSubsystem m () | ||
UnlockDomain _ -> undefined -- :: Domain -> EnterpriseLoginSubsystem m () | ||
PreAuthorizeDomain _ -> undefined -- :: Domain -> EnterpriseLoginSubsystem m () | ||
UnAuthorizeDomain _ -> undefined -- :: Domain -> EnterpriseLoginSubsystem m () | ||
UpdateDomainRegistration _ _ -> undefined -- :: Domain -> DomainRegistrationUpdate -> EnterpriseLoginSubsystem m () | ||
DeleteDomain _ -> undefined -- :: Domain -> EnterpriseLoginSubsystem m () | ||
GetDomainRegistration _ -> undefined -- :: Domain -> EnterpriseLoginSubsystem m DomainRegistration | ||
GuardEmailDomainRegistrationState _ _ _ -> undefined -- :: InvitationFlow -> TeamId -> EmailAddress -> EnterpriseLoginSubsystem m () |
96 changes: 96 additions & 0 deletions
96
libs/wire-subsystems/test/unit/Wire/TeamInvitationSubsystem/InterpreterSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} | ||
|
||
module Wire.TeamInvitationSubsystem.InterpreterSpec (spec) where | ||
|
||
import Data.Domain | ||
import Data.Id | ||
import Data.Misc (PlainTextPassword8) | ||
import Data.Qualified | ||
import Data.Text.Encoding (decodeUtf8) | ||
import Data.Time | ||
import Imports | ||
import Polysemy | ||
import Polysemy.Error | ||
import Polysemy.Input | ||
import Polysemy.State | ||
import Polysemy.TinyLog | ||
import System.Random (StdGen, mkStdGen) | ||
import Test.Hspec | ||
import Test.Hspec.QuickCheck | ||
import Test.QuickCheck | ||
import Wire.API.Allowlists (AllowlistEmailDomains (AllowlistEmailDomains)) | ||
import Wire.API.Password as Password | ||
import Wire.API.User | ||
import Wire.API.User qualified as User | ||
import Wire.API.User.Auth | ||
import Wire.API.User.Password | ||
import Wire.AuthenticationSubsystem | ||
import Wire.AuthenticationSubsystem.Interpreter | ||
import Wire.EmailSubsystem | ||
import Wire.EnterpriseLoginSubsystem | ||
import Wire.GalleyAPIAccess | ||
import Wire.HashPassword | ||
import Wire.InvitationStore | ||
import Wire.MockInterpreters | ||
import Wire.PasswordResetCodeStore | ||
import Wire.PasswordStore | ||
import Wire.Sem.Logger.TinyLog | ||
import Wire.Sem.Now (Now) | ||
import Wire.Sem.Random | ||
import Wire.SessionStore | ||
import Wire.StoredUser | ||
import Wire.TeamInvitationSubsystem | ||
import Wire.TeamInvitationSubsystem.Error | ||
import Wire.TeamInvitationSubsystem.Interpreter | ||
import Wire.UserKeyStore | ||
import Wire.UserStore | ||
import Wire.UserSubsystem | ||
|
||
type AllEffects = | ||
[ Error TeamInvitationSubsystemError, | ||
TinyLog, | ||
GalleyAPIAccess, | ||
Random, | ||
State StdGen, | ||
InvitationStore, | ||
State (Map (TeamId, InvitationId) StoredInvitation), | ||
State (Map (InvitationCode) StoredInvitation), | ||
Now, | ||
State UTCTime, | ||
EmailSubsystem, | ||
State (Map EmailAddress [SentMail]), | ||
UserSubsystem, | ||
EnterpriseLoginSubsystem | ||
] | ||
|
||
runAllEffects :: Sem AllEffects a -> Either TeamInvitationSubsystemError a | ||
runAllEffects = | ||
run | ||
. enterpriseLoginSubsystemTestInterpreter | ||
. userSubsystemTestInterpreter [] | ||
. evalState mempty | ||
. emailSubsystemInterpreter | ||
. evalState defaultTime | ||
. interpretNowAsState | ||
. evalState mempty | ||
. evalState mempty | ||
. inMemoryInvitationStoreInterpreter | ||
. evalState (mkStdGen 3) -- deterministic randomness, good for tests. :) | ||
. randomToStatefulStdGen | ||
. miniGalleyAPIAccess Nothing undefined | ||
. discardTinyLogs | ||
. runError | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "InviteUser" $ do | ||
focus . prop "works (TODO: better description pls)" $ | ||
\() -> | ||
let cfg = | ||
TeamInvitationSubsystemConfig | ||
{ maxTeamSize = 50, | ||
teamInvitationTimeout = 3_000_000 | ||
} | ||
outcome = runAllEffects . runTeamInvitationSubsystem cfg $ do | ||
pure () | ||
in outcome === Right () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters