diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-04 22:02:53 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-04 22:02:53 +0100 |
| commit | 958cd52392185fc31333c1b208948046d7a9e635 (patch) | |
| tree | f4688c6c4b48a775596b0dc1766aeabe3627ffb7 /lambda-calcul/haskell/test | |
| parent | db4ecd7a93086585937b9b45970f4f4c4e1838a3 (diff) | |
| download | lambda-nantes-958cd52392185fc31333c1b208948046d7a9e635.tar.gz | |
Keep registered users
Diffstat (limited to 'lambda-calcul/haskell/test')
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/ServerSpec.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs index 6a3b6d5..33fbd69 100644 --- a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs @@ -4,6 +4,7 @@ module Minilang.ServerSpec where import Control.Concurrent.STM (newTVarIO) +import Control.Monad (void) import Data.Aeson (FromJSON, eitherDecode, encode) import Data.ByteString (isInfixOf, toStrict) import qualified Data.ByteString as BS @@ -11,7 +12,7 @@ import qualified Data.ByteString.Base64.Lazy as Base64 import Data.ByteString.Lazy (ByteString) import Data.Data (Proxy (..)) import Minilang.API (Score, User (..), newToken) -import Minilang.App (Env (..)) +import Minilang.App (Env (..), makeEnv) import Minilang.Server (serveAPI) import Network.Wai (Application) import Network.Wai.Test (SResponse) @@ -47,6 +48,12 @@ spec = with (app testSeed) $ do else Just ("Expected token " ++ show token ++ ", but got " ++ show t) } + it "POST /api/register returns 400 given user is already registered" $ do + let user = encode $ User "alice" + void $ postJSON "/api/register" user + postJSON "/api/register" user + `shouldRespondWith` 400 + postJSON :: BS.ByteString -> ByteString -> WaiSession () SResponse postJSON url = request "POST" url [("Content-Type", "application/json")] @@ -61,7 +68,7 @@ arrayOfLengthOf _ len = MatchBody $ \_ actual -> app :: StdGen -> IO Application app g = do - env <- Env <$> newTVarIO g + env <- makeEnv g pure $ serveAPI env testSeed :: StdGen |
