diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-04 08:10:46 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-04 08:47:15 +0100 |
| commit | 1083bb7758a2dfe3f2861bf802627cec16933861 (patch) | |
| tree | 11bcec09bc5d32eeb72de801bc2337c8098bb728 /lambda-calcul/haskell/test/Minilang/ServerSpec.hs | |
| parent | 51194425997225de7b7ca83e26b76b9a82f0e10d (diff) | |
| download | lambda-nantes-1083bb7758a2dfe3f2861bf802627cec16933861.tar.gz | |
Default REPL to Untyped language
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/ServerSpec.hs')
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/ServerSpec.hs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs index 309ded8..6a25ec5 100644 --- a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs @@ -1,15 +1,31 @@ +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} + module Minilang.ServerSpec where +import Data.Aeson (eitherDecode, FromJSON) +import Minilang.API (Score) import Minilang.Server (serveAPI) import Network.Wai (Application) import Test.Hspec (Spec, it) -import Test.Hspec.Wai (get, shouldRespondWith, with) +import Test.Hspec.Wai (get, matchBody, shouldRespondWith, with) +import Test.Hspec.Wai.Matcher (MatchBody (..)) +import Data.Data (Proxy (..)) spec :: Spec spec = with app $ it "GET /api/leaderboard returns empty list of scores" $ do get "/api/leaderboard" - `shouldRespondWith` "[]" + `shouldRespondWith` 200 {matchBody = arrayOfLengthOf (Proxy @Score) 2} + +arrayOfLengthOf :: forall elem proxy . (FromJSON elem) => proxy elem -> Int -> MatchBody +arrayOfLengthOf _ len = MatchBody $ \_ actual -> + case eitherDecode actual of + Right (scores :: [elem]) -> + if length scores == len + then Nothing + else Just $ "Expected array of length " ++ show len ++ ", but got " ++ show (length scores) + Left err -> Just $ "Failed to decode JSON: " ++ err app :: IO Application app = pure serveAPI |
