@@ -17,7 +17,6 @@ import Control.Monad.Trans.Except (ExceptT, throwE)
17import Data.Aeson (FromJSON, ToJSON, decode', encode)
17import Data.Aeson (FromJSON, ToJSON, decode', encode)
18import Data.ByteString.Conversion ()
18import Data.ByteString.Conversion ()
19import Data.Char (toUpper)
19import Data.Char (toUpper)
20−import Data.Monoid ((<>))
21import Data.Proxy (Proxy (Proxy))
20import Data.Proxy (Proxy (Proxy))
22import Data.String (fromString)
21import Data.String (fromString)
23import Data.String.Conversions (cs)
22import Data.String.Conversions (cs)
@@ -26,8 +25,7 @@ import GHC.Generics (Generic)
26import Network.HTTP.Types (hAccept, hContentType,
25import Network.HTTP.Types (hAccept, hContentType,
27 methodDelete, methodGet, methodHead,
26 methodDelete, methodGet, methodHead,
28 methodPatch, methodPost, methodPut,
27 methodPatch, methodPost, methodPut,
29− ok200, parseQuery, status409,
28+ ok200, parseQuery, Status(..))
31import Network.Wai (Application, Request, pathInfo,
29import Network.Wai (Application, Request, pathInfo,
32 queryString, rawQueryString,
30 queryString, rawQueryString,
33 responseLBS, responseBuilder)
31 responseLBS, responseBuilder)
@@ -99,7 +97,6 @@ spec = do
100 unionSpec
98 unionSpec
101 prioErrorsSpec
99 prioErrorsSpec
103 routerSpec
100 routerSpec
104 responseHeadersSpec
101 responseHeadersSpec
105 miscReqCombinatorsSpec
102 miscReqCombinatorsSpec
@@ -158,9 +155,9 @@ getSpec = do
158 it "returns 204 if the type is '()'" $ do
155 it "returns 204 if the type is '()'" $ do
159 get "/empty" `shouldRespondWith` ""{ matchStatus = 204 }
156 get "/empty" `shouldRespondWith` ""{ matchStatus = 204 }
161− it "returns 415 if the Accept header is not supported" $ do
158+ it "returns 406 if the Accept header is not supported" $ do
162 Test.Hspec.Wai.request methodGet "" [(hAccept, "crazy/mime")] ""
159 Test.Hspec.Wai.request methodGet "" [(hAccept, "crazy/mime")] ""
163− `shouldRespondWith` 415
160+ `shouldRespondWith` 406
166headSpec :: Spec
163headSpec :: Spec
@@ -186,9 +183,9 @@ headSpec = do
186 response <- Test.Hspec.Wai.request methodHead "/empty" [] ""
183 response <- Test.Hspec.Wai.request methodHead "/empty" [] ""
187 return response `shouldRespondWith` ""{ matchStatus = 204 }
184 return response `shouldRespondWith` ""{ matchStatus = 204 }
189− it "returns 415 if the Accept header is not supported" $ do
186+ it "returns 406 if the Accept header is not supported" $ do
190 Test.Hspec.Wai.request methodHead "" [(hAccept, "crazy/mime")] ""
187 Test.Hspec.Wai.request methodHead "" [(hAccept, "crazy/mime")] ""
191− `shouldRespondWith` 415
188+ `shouldRespondWith` 406
194type QueryParamApi = QueryParam "name" String :> Get '[JSON] Person
191type QueryParamApi = QueryParam "name" String :> Get '[JSON] Person
@@ -311,7 +308,7 @@ postSpec = do
311 it "returns 204 if the type is '()'" $ do
308 it "returns 204 if the type is '()'" $ do
312 post' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
309 post' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
314− it "responds with 415 if the requested media type is unsupported" $ do
311+ it "responds with 415 if the request body media type is unsupported" $ do
315 let post'' x = Test.Hspec.Wai.request methodPost x [(hContentType
312 let post'' x = Test.Hspec.Wai.request methodPost x [(hContentType
316 , "application/nonsense")]
313 , "application/nonsense")]
317 post'' "/" "anything at all" `shouldRespondWith` 415
314 post'' "/" "anything at all" `shouldRespondWith` 415
@@ -353,7 +350,7 @@ putSpec = do
353 it "returns 204 if the type is '()'" $ do
350 it "returns 204 if the type is '()'" $ do
354 put' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
351 put' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
356− it "responds with 415 if the requested media type is unsupported" $ do
353+ it "responds with 415 if the request body media type is unsupported" $ do
357 let put'' x = Test.Hspec.Wai.request methodPut x [(hContentType
354 let put'' x = Test.Hspec.Wai.request methodPut x [(hContentType
358 , "application/nonsense")]
355 , "application/nonsense")]
359 put'' "/" "anything at all" `shouldRespondWith` 415
356 put'' "/" "anything at all" `shouldRespondWith` 415
@@ -395,7 +392,7 @@ patchSpec = do
395 it "returns 204 if the type is '()'" $ do
392 it "returns 204 if the type is '()'" $ do
396 patch' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
393 patch' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
398− it "responds with 415 if the requested media type is unsupported" $ do
395+ it "responds with 415 if the request body media type is unsupported" $ do
399 let patch'' x = Test.Hspec.Wai.request methodPatch x [(hContentType
396 let patch'' x = Test.Hspec.Wai.request methodPatch x [(hContentType
400 , "application/nonsense")]
397 , "application/nonsense")]
401 patch'' "/" "anything at all" `shouldRespondWith` 415
398 patch'' "/" "anything at all" `shouldRespondWith` 415
@@ -524,10 +521,10 @@ responseHeadersSpec = describe "ResponseHeaders" $ do
524 Test.Hspec.Wai.request method "blahblah" [] ""
521 Test.Hspec.Wai.request method "blahblah" [] ""
525 `shouldRespondWith` 404
522 `shouldRespondWith` 404
527− it "returns 415 if the Accept header is not supported" $
524+ it "returns 406 if the Accept header is not supported" $
528 forM_ methods $ \(method,_) ->
525 forM_ methods $ \(method,_) ->
529 Test.Hspec.Wai.request method "" [(hAccept, "crazy/mime")] ""
526 Test.Hspec.Wai.request method "" [(hAccept, "crazy/mime")] ""
530− `shouldRespondWith` 415
527+ `shouldRespondWith` 406
532type PrioErrorsApi = ReqBody '[JSON] Person :> "foo" :> Get '[JSON] Integer
529type PrioErrorsApi = ReqBody '[JSON] Person :> "foo" :> Get '[JSON] Integer
@@ -578,50 +575,6 @@ prioErrorsSpec = describe "PrioErrors" $ do
578 check put' "/bar" vjson 404
575 check put' "/bar" vjson 404
579 check put' "/foo" vjson 405
576 check put' "/foo" vjson 405
581−-- | Test server error functionality.
584− let he = HttpError status409 (Just "A custom error")
585− let ib = InvalidBody "The body is invalid"
586− let wm = WrongMethod
589− describe "Servant.Server.Internal.RouteMismatch" $ do
590− it "HttpError > *" $ do
591− ib <> he `shouldBe` he
592− wm <> he `shouldBe` he
593− nf <> he `shouldBe` he
595− he <> ib `shouldBe` he
596− he <> wm `shouldBe` he
597− he <> nf `shouldBe` he
599− it "HE > InvalidBody > (WM,NF)" $ do
600− he <> ib `shouldBe` he
601− wm <> ib `shouldBe` ib
602− nf <> ib `shouldBe` ib
604− ib <> he `shouldBe` he
605− ib <> wm `shouldBe` ib
606− ib <> nf `shouldBe` ib
608− it "HE > IB > WrongMethod > NF" $ do
609− he <> wm `shouldBe` he
610− ib <> wm `shouldBe` ib
611− nf <> wm `shouldBe` wm
613− wm <> he `shouldBe` he
614− wm <> ib `shouldBe` ib
615− wm <> nf `shouldBe` wm
617− it "* > NotFound" $ do
618− he <> nf `shouldBe` he
619− ib <> nf `shouldBe` ib
620− wm <> nf `shouldBe` wm
622− nf <> he `shouldBe` he
623− nf <> ib `shouldBe` ib
624− nf <> wm `shouldBe` wm
626routerSpec :: Spec
579routerSpec :: Spec
627routerSpec = do
580routerSpec = do