Debian Codegraph @

test/Network/Wai/Middleware/StaticSpec.hs

raw
1 {-# LANGUAGE OverloadedStrings #-}
2 module Network.Wai.Middleware.StaticSpec (spec) where
3
4 import Test.Hspec hiding (shouldReturn)
5 import Test.Hspec.Expectations.Lifted
6 import Test.Hspec.Wai
7 import Test.Mockery.Directory
8
9 import Web.Scotty (scottyApp)
10 import Network.Wai.Test (SResponse(..))
11 import Network.HTTP.Types.Status
12
13 import Network.Wai.Middleware.Static
14
15 spec :: Spec
16 spec = around_ inTempDirectory $ do
17 describe "static" $ with (static `fmap` scottyApp (return ())) $ do
18 before_ (writeFile "foo.html" "some content") $ do
19 context "on HEAD" $ do
20 it "serves static file" $ do
21 request "HEAD" "/foo.html" [] "" `shouldReturn` SResponse {
22 simpleStatus = status200
23 , simpleHeaders = [("Content-Type", "text/html")]
24 , simpleBody = "some content"
25 }
26
27 context "on GET" $ do
28 it "serves static file" $ do
29 get "/foo.html" `shouldReturn` SResponse {
30 simpleStatus = status200
31 , simpleHeaders = [("Content-Type", "text/html")]
32 , simpleBody = "some content"
33 }
34
35 context "otherwise" $ do
36 it "serves upstream" $ do
37 post "/foo.html" "" `shouldReturn` SResponse {
38 simpleStatus = status404
39 , simpleHeaders = [("Content-Type", "text/html")]
40 , simpleBody = "<h1>404: File Not Found!</h1>"
41 }