File: StaticSpec.hs

package info (click to toggle)
haskell-wai-middleware-static 0.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104 kB
  • sloc: haskell: 244; makefile: 5
file content (41 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{-# LANGUAGE OverloadedStrings #-}
module Network.Wai.Middleware.StaticSpec (spec) where

import           Test.Hspec hiding (shouldReturn)
import           Test.Hspec.Expectations.Lifted
import           Test.Hspec.Wai
import           Test.Mockery.Directory

import           Web.Scotty (scottyApp)
import           Network.Wai.Test (SResponse(..))
import           Network.HTTP.Types.Status

import           Network.Wai.Middleware.Static

spec :: Spec
spec = around_ inTempDirectory $ do
  describe "static" $ with (static `fmap` scottyApp (return ())) $ do
    before_ (writeFile "foo.html" "some content") $ do
      context "on HEAD" $ do
        it "serves static file" $ do
          request "HEAD" "/foo.html" [] "" `shouldReturn` SResponse {
            simpleStatus = status200
          , simpleHeaders = [("Content-Type", "text/html")]
          , simpleBody = "some content"
          }

      context "on GET" $ do
        it "serves static file" $ do
          get "/foo.html" `shouldReturn` SResponse {
            simpleStatus = status200
          , simpleHeaders = [("Content-Type", "text/html")]
          , simpleBody = "some content"
          }

      context "otherwise" $ do
        it "serves upstream" $ do
          post "/foo.html" "" `shouldReturn` SResponse {
            simpleStatus = status404
          , simpleHeaders = [("Content-Type", "text/html")]
          , simpleBody = "<h1>404: File Not Found!</h1>"
          }