diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-04 09:06:01 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-04 09:06:01 +0100 |
| commit | df879037d135c0b300735185d5fdc0857ed797d6 (patch) | |
| tree | 60ea569254a110be6fc53453e99312e2f16fc384 /lambda-calcul/haskell/test | |
| parent | 1083bb7758a2dfe3f2861bf802627cec16933861 (diff) | |
| download | lambda-nantes-df879037d135c0b300735185d5fdc0857ed797d6.tar.gz | |
Serve index.html when requesting '/'
Diffstat (limited to 'lambda-calcul/haskell/test')
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/ServerSpec.hs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs index 6a25ec5..962dcdc 100644 --- a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs @@ -3,22 +3,32 @@ module Minilang.ServerSpec where -import Data.Aeson (eitherDecode, FromJSON) +import Data.Aeson (FromJSON, eitherDecode) +import Data.ByteString (isInfixOf, toStrict) +import Data.Data (Proxy (..)) import Minilang.API (Score) import Minilang.Server (serveAPI) import Network.Wai (Application) import Test.Hspec (Spec, it) import Test.Hspec.Wai (get, matchBody, shouldRespondWith, with) import Test.Hspec.Wai.Matcher (MatchBody (..)) -import Data.Data (Proxy (..)) spec :: Spec -spec = with app $ +spec = with app $ do + it "GET / returns 'index.html'" $ do + get "/" + `shouldRespondWith` 200 + { matchBody = MatchBody $ \_ actual -> + if "<html>" `isInfixOf` toStrict actual + then Nothing + else Just "Expected HTML content" + } + it "GET /api/leaderboard returns empty list of scores" $ do get "/api/leaderboard" `shouldRespondWith` 200 {matchBody = arrayOfLengthOf (Proxy @Score) 2} -arrayOfLengthOf :: forall elem proxy . (FromJSON elem) => proxy elem -> Int -> MatchBody +arrayOfLengthOf :: forall elem proxy. (FromJSON elem) => proxy elem -> Int -> MatchBody arrayOfLengthOf _ len = MatchBody $ \_ actual -> case eitherDecode actual of Right (scores :: [elem]) -> |
