@@ -3,8 +3,10 @@
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE FlexibleInstances #-}
55{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE PolyKinds #-}
67{-# LANGUAGE ScopedTypeVariables #-}
78{-# LANGUAGE TypeOperators #-}
9+{-# LANGUAGE TypeFamilies #-}
810{-# LANGUAGE TypeSynonymInstances #-}
911{-# LANGUAGE FlexibleInstances #-}
1012
@@ -13,7 +15,7 @@ module Servant.ServerSpec where
1315#if !MIN_VERSION_base(4,8,0)
1416import Control.Applicative ((<$>))
1517#endif
16−import Control.Monad (forM_, when)
18+import Control.Monad (forM_, when, unless)
1719import Control.Monad.Trans.Except (ExceptT, throwE)
1820import Data.Aeson (FromJSON, ToJSON, decode', encode)
1921import Data.ByteString.Conversion ()
@@ -23,82 +25,144 @@ import Data.String (fromString)
2325import Data.String.Conversions (cs)
2426import qualified Data.Text as T
2527import GHC.Generics (Generic)
26−import Network.HTTP.Types (hAccept, hContentType,
27− methodDelete, methodGet, methodHead,
28− methodPatch, methodPost, methodPut,
29− ok200, parseQuery, Status(..))
28+import Network.HTTP.Types (Status (..), hAccept, hContentType,
29+ methodDelete, methodGet,
30+ methodHead, methodPatch,
31+ methodPost, methodPut, ok200,
32+ parseQuery)
3033import Network.Wai (Application, Request, pathInfo,
3134 queryString, rawQueryString,
32− responseLBS, responseBuilder)
33−import Network.Wai.Internal (Response(ResponseBuilder))
35+ responseBuilder, responseLBS)
36+import Network.Wai.Internal (Response (ResponseBuilder))
3437import Network.Wai.Test (defaultRequest, request,
35− runSession, simpleBody)
38+ runSession, simpleBody,
39+ simpleHeaders, simpleStatus)
3640import Servant.API ((:<|>) (..), (:>), Capture, Delete,
37− Get, Header (..), Headers,
38− HttpVersion, IsSecure (..), JSON,
39− Patch, PlainText, Post, Put,
41+ Get, Header (..),
42+ Headers, HttpVersion,
43+ IsSecure (..), JSON,
44+ NoContent (..), Patch, PlainText,
45+ Post, Put,
4046 QueryFlag, QueryParam, QueryParams,
4147 Raw, RemoteHost, ReqBody,
42− addHeader)
43−import Servant.Server (Server, serve, ServantErr(..), err404)
44−import Test.Hspec (Spec, describe, it, shouldBe)
48+ StdMethod (..), Verb, addHeader)
49+import Servant.Server (ServantErr (..), Server, err404,
50+ serve)
51+import Test.Hspec (Spec, context, describe, it,
52+ shouldBe, shouldContain)
4553import Test.Hspec.Wai (get, liftIO, matchHeaders,
46− matchStatus, post, request,
54+ matchStatus, request,
4755 shouldRespondWith, with, (<:>))
48−import Servant.Server.Internal.RoutingApplication (toApplication, RouteResult(..))
56+
57+import Servant.Server.Internal.RoutingApplication
58+ (toApplication, RouteResult(..))
4959import Servant.Server.Internal.Router
5060 (tweakResponse, runRouter,
5161 Router, Router'(LeafRouter))
5262
5363
54−-- * test data types
55−
56−data Person = Person {
57− name :: String,
58− age :: Integer
59− }
60− deriving (Eq, Show, Generic)
61−
62−instance ToJSON Person
63−instance FromJSON Person
64−
65−alice :: Person
66−alice = Person "Alice" 42
67−
68−data Animal = Animal {
69− species :: String,
70− numberOfLegs :: Integer
71− }
72− deriving (Eq, Show, Generic)
73−
74−instance ToJSON Animal
75−instance FromJSON Animal
76−
77−jerry :: Animal
78−jerry = Animal "Mouse" 4
79−
80−tweety :: Animal
81−tweety = Animal "Bird" 2
82−
83−
84−-- * specs
64+-- * Specs
8565
8666spec :: Spec
8767spec = do
68+ verbSpec
8869 captureSpec
89− getSpec
90− headSpec
91− postSpec
92− putSpec
93− patchSpec
9470 queryParamSpec
71+ reqBodySpec
9572 headerSpec
9673 rawSpec
97− unionSpec
98− routerSpec
74+ alternativeSpec
9975 responseHeadersSpec
100− miscReqCombinatorsSpec
101−
76+ routerSpec
77+ miscCombinatorSpec
78+
79+------------------------------------------------------------------------------
80+-- * verbSpec {{{
81+------------------------------------------------------------------------------
82+
83+type VerbApi method status
84+ = Verb method status '[JSON] Person
85+ :<|> "noContent" :> Verb method status '[JSON] NoContent
86+ :<|> "header" :> Verb method status '[JSON] (Headers '[Header "H" Int] Person)
87+ :<|> "headerNC" :> Verb method status '[JSON] (Headers '[Header "H" Int] NoContent)
88+
89+verbSpec :: Spec
90+verbSpec = describe "Servant.API.Verb" $ do
91+ let server :: Server (VerbApi method status)
92+ server = return alice
93+ :<|> return NoContent
94+ :<|> return (addHeader 5 alice)
95+ :<|> return (addHeader 10 NoContent)
96+ get200 = Proxy :: Proxy (VerbApi 'GET 200)
97+ post210 = Proxy :: Proxy (VerbApi 'POST 210)
98+ put203 = Proxy :: Proxy (VerbApi 'PUT 203)
99+ delete280 = Proxy :: Proxy (VerbApi 'DELETE 280)
100+ patch214 = Proxy :: Proxy (VerbApi 'PATCH 214)
101+ wrongMethod m = if m == methodPatch then methodPost else methodPatch
102+ test desc api method (status :: Int) = context desc $
103+
104+ with (return $ serve api server) $ do
105+
106+ -- HEAD and 214/215 need not return bodies
107+ unless (status `elem` [214, 215] || method == methodHead) $
108+ it "returns the person" $ do
109+ response <- Test.Hspec.Wai.request method "/" [] ""
110+ liftIO $ statusCode (simpleStatus response) `shouldBe` status
111+ liftIO $ decode' (simpleBody response) `shouldBe` Just alice
112+
113+ it "returns no content on NoContent" $ do
114+ response <- Test.Hspec.Wai.request method "/noContent" [] ""
115+ liftIO $ statusCode (simpleStatus response) `shouldBe` status
116+ liftIO $ simpleBody response `shouldBe` ""
117+
118+ -- HEAD should not return body
119+ when (method == methodHead) $
120+ it "HEAD returns no content body" $ do
121+ response <- Test.Hspec.Wai.request method "/" [] ""
122+ liftIO $ simpleBody response `shouldBe` ""
123+
124+ it "throws 405 on wrong method " $ do
125+ Test.Hspec.Wai.request (wrongMethod method) "/" [] ""
126+ `shouldRespondWith` 405
127+
128+ it "returns headers" $ do
129+ response1 <- Test.Hspec.Wai.request method "/header" [] ""
130+ liftIO $ statusCode (simpleStatus response1) `shouldBe` status
131+ liftIO $ simpleHeaders response1 `shouldContain` [("H", "5")]
132+
133+ response2 <- Test.Hspec.Wai.request method "/header" [] ""
134+ liftIO $ statusCode (simpleStatus response2) `shouldBe` status
135+ liftIO $ simpleHeaders response2 `shouldContain` [("H", "5")]
136+
137+ it "handles trailing '/' gracefully" $ do
138+ response <- Test.Hspec.Wai.request method "/headerNC/" [] ""
139+ liftIO $ statusCode (simpleStatus response) `shouldBe` status
140+
141+ it "returns 406 if the Accept header is not supported" $ do
142+ Test.Hspec.Wai.request method "" [(hAccept, "crazy/mime")] ""
143+ `shouldRespondWith` 406
144+
145+ it "responds if the Accept header is supported" $ do
146+ response <- Test.Hspec.Wai.request method ""
147+ [(hAccept, "application/json")] ""
148+ liftIO $ statusCode (simpleStatus response) `shouldBe` status
149+
150+ it "sets the Content-Type header" $ do
151+ response <- Test.Hspec.Wai.request method "" [] ""
152+ liftIO $ simpleHeaders response `shouldContain`
153+ [("Content-Type", "application/json")]
154+
155+ test "GET 200" get200 methodGet 200
156+ test "POST 210" post210 methodPost 210
157+ test "PUT 203" put203 methodPut 203
158+ test "DELETE 280" delete280 methodDelete 280
159+ test "PATCH 214" patch214 methodPatch 214
160+ test "GET 200 with HEAD" get200 methodHead 200
161+
162+-- }}}
163+------------------------------------------------------------------------------
164+-- * captureSpec {{{
165+------------------------------------------------------------------------------
102166
103167type CaptureApi = Capture "legs" Integer :> Get '[JSON] Animal
104168captureApi :: Proxy CaptureApi
@@ -128,63 +192,10 @@ captureSpec = do
128192 it "strips the captured path snippet from pathInfo" $ do
129193 get "/captured/foo" `shouldRespondWith` (fromString (show ["foo" :: String]))
130194
131−
132−type GetApi = Get '[JSON] Person
133− :<|> "empty" :> Get '[] ()
134− :<|> "post" :> Post '[] ()
135−getApi :: Proxy GetApi
136−getApi = Proxy
137−
138−getSpec :: Spec
139−getSpec = do
140− describe "Servant.API.Get" $ do
141− let server = return alice :<|> return () :<|> return ()
142− with (return $ serve getApi server) $ do
143−
144− it "allows to GET a Person" $ do
145− response <- get "/"
146− return response `shouldRespondWith` 200
147− liftIO $ decode' (simpleBody response) `shouldBe` Just alice
148−
149− it "throws 405 (wrong method) on POSTs" $ do
150− post "/" "" `shouldRespondWith` 405
151− post "/empty" "" `shouldRespondWith` 405
152−
153− it "returns 204 if the type is '()'" $ do
154− get "/empty" `shouldRespondWith` ""{ matchStatus = 204 }
155−
156− it "returns 406 if the Accept header is not supported" $ do
157− Test.Hspec.Wai.request methodGet "" [(hAccept, "crazy/mime")] ""
158− `shouldRespondWith` 406
159−
160−
161−headSpec :: Spec
162−headSpec = do
163− describe "Servant.API.Head" $ do
164− let server = return alice :<|> return () :<|> return ()
165− with (return $ serve getApi server) $ do
166−
167− it "allows to GET a Person" $ do
168− response <- Test.Hspec.Wai.request methodHead "/" [] ""
169− return response `shouldRespondWith` 200
170− liftIO $ decode' (simpleBody response) `shouldBe` (Nothing :: Maybe Person)
171−
172− it "does not allow HEAD to POST route" $ do
173− response <- Test.Hspec.Wai.request methodHead "/post" [] ""
174− return response `shouldRespondWith` 405
175−
176− it "throws 405 (wrong method) on POSTs" $ do
177− post "/" "" `shouldRespondWith` 405
178− post "/empty" "" `shouldRespondWith` 405
179−
180− it "returns 204 if the type is '()'" $ do
181− response <- Test.Hspec.Wai.request methodHead "/empty" [] ""
182− return response `shouldRespondWith` ""{ matchStatus = 204 }
183−
184− it "returns 406 if the Accept header is not supported" $ do
185− Test.Hspec.Wai.request methodHead "" [(hAccept, "crazy/mime")] ""
186− `shouldRespondWith` 406
187−
195+-- }}}
196+------------------------------------------------------------------------------
197+-- * queryParamSpec {{{
198+------------------------------------------------------------------------------
188199
189200type QueryParamApi = QueryParam "name" String :> Get '[JSON] Person
190201 :<|> "a" :> QueryParams "names" String :> Get '[JSON] Person
@@ -269,131 +280,41 @@ queryParamSpec = do
269280 name = "Alice"
270281 }
271282
272−type PostApi =
273− ReqBody '[JSON] Person :> Post '[JSON] Integer
274− :<|> "bla" :> ReqBody '[JSON] Person :> Post '[JSON] Integer
275− :<|> "empty" :> Post '[] ()
276−
277−postApi :: Proxy PostApi
278−postApi = Proxy
279−
280−postSpec :: Spec
281−postSpec = do
282− describe "Servant.API.Post and .ReqBody" $ do
283− let server = return . age :<|> return . age :<|> return ()
284− with (return $ serve postApi server) $ do
285− let post' x = Test.Hspec.Wai.request methodPost x [(hContentType
286− , "application/json;charset=utf-8")]
287−
288− it "allows to POST a Person" $ do
289− post' "/" (encode alice) `shouldRespondWith` "42"{
290− matchStatus = 201
291− }
292−
293− it "allows alternative routes if all have request bodies" $ do
294− post' "/bla" (encode alice) `shouldRespondWith` "42"{
295− matchStatus = 201
296− }
297−
298− it "handles trailing '/' gracefully" $ do
299− post' "/bla/" (encode alice) `shouldRespondWith` "42"{
300− matchStatus = 201
301− }
302−
303− it "correctly rejects invalid request bodies with status 400" $ do
304− post' "/" "some invalid body" `shouldRespondWith` 400
305−
306− it "returns 204 if the type is '()'" $ do
307− post' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
308−
309− it "responds with 415 if the request body media type is unsupported" $ do
310− let post'' x = Test.Hspec.Wai.request methodPost x [(hContentType
311− , "application/nonsense")]
312− post'' "/" "anything at all" `shouldRespondWith` 415
313−
314−type PutApi =
315− ReqBody '[JSON] Person :> Put '[JSON] Integer
316− :<|> "bla" :> ReqBody '[JSON] Person :> Put '[JSON] Integer
317− :<|> "empty" :> Put '[] ()
318−
319−putApi :: Proxy PutApi
320−putApi = Proxy
321−
322−putSpec :: Spec
323−putSpec = do
324− describe "Servant.API.Put and .ReqBody" $ do
325− let server = return . age :<|> return . age :<|> return ()
326− with (return $ serve putApi server) $ do
327− let put' x = Test.Hspec.Wai.request methodPut x [(hContentType
328− , "application/json;charset=utf-8")]
283+-- }}}
284+------------------------------------------------------------------------------
285+-- * reqBodySpec {{{
286+------------------------------------------------------------------------------
287+type ReqBodyApi = ReqBody '[JSON] Person :> Post '[JSON] Person
288+ :<|> "blah" :> ReqBody '[JSON] Person :> Put '[JSON] Integer
329289
330− it "allows to put a Person" $ do
331− put' "/" (encode alice) `shouldRespondWith` "42"{
332− matchStatus = 200
333− }
334−
335− it "allows alternative routes if all have request bodies" $ do
336− put' "/bla" (encode alice) `shouldRespondWith` "42"{
337− matchStatus = 200
338− }
290+reqBodyApi :: Proxy ReqBodyApi
291+reqBodyApi = Proxy
339292
340− it "handles trailing '/' gracefully" $ do
341− put' "/bla/" (encode alice) `shouldRespondWith` "42"{
342− matchStatus = 200
343− }
293+reqBodySpec :: Spec
294+reqBodySpec = describe "Servant.API.ReqBody" $ do
344295
345− it "correctly rejects invalid request bodies with status 400" $ do
346− put' "/" "some invalid body" `shouldRespondWith` 400
296+ let server :: Server ReqBodyApi
297+ server = return :<|> return . age
298+ mkReq method x = Test.Hspec.Wai.request method x
299+ [(hContentType, "application/json;charset=utf-8")]
347300
348− it "returns 204 if the type is '()'" $ do
349− put' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
301+ with (return $ serve reqBodyApi server) $ do
350302
351− it "responds with 415 if the request body media type is unsupported" $ do
352− let put'' x = Test.Hspec.Wai.request methodPut x [(hContentType
353− , "application/nonsense")]
354− put'' "/" "anything at all" `shouldRespondWith` 415
303+ it "passes the argument to the handler" $ do
304+ response <- mkReq methodPost "" (encode alice)
305+ liftIO $ decode' (simpleBody response) `shouldBe` Just alice
355306
356−type PatchApi =
357− ReqBody '[JSON] Person :> Patch '[JSON] Integer
358− :<|> "bla" :> ReqBody '[JSON] Person :> Patch '[JSON] Integer
359− :<|> "empty" :> Patch '[] ()
307+ it "rejects invalid request bodies with status 400" $ do
308+ mkReq methodPut "/blah" "some invalid body" `shouldRespondWith` 400
360309
361−patchApi :: Proxy PatchApi
362−patchApi = Proxy
310+ it "responds with 415 if the request body media type is unsupported" $ do
311+ Test.Hspec.Wai.request methodPost "/"
312+ [(hContentType, "application/nonsense")] "" `shouldRespondWith` 415
363313
364−patchSpec :: Spec
365−patchSpec = do
366− describe "Servant.API.Patch and .ReqBody" $ do
367− let server = return . age :<|> return . age :<|> return ()
368− with (return $ serve patchApi server) $ do
369− let patch' x = Test.Hspec.Wai.request methodPatch x [(hContentType
370− , "application/json;charset=utf-8")]
371−
372− it "allows to patch a Person" $ do
373− patch' "/" (encode alice) `shouldRespondWith` "42"{
374− matchStatus = 200
375− }
376−
377− it "allows alternative routes if all have request bodies" $ do
378− patch' "/bla" (encode alice) `shouldRespondWith` "42"{
379− matchStatus = 200
380− }
381−
382− it "handles trailing '/' gracefully" $ do
383− patch' "/bla/" (encode alice) `shouldRespondWith` "42"{
384− matchStatus = 200
385− }
386−
387− it "correctly rejects invalid request bodies with status 400" $ do
388− patch' "/" "some invalid body" `shouldRespondWith` 400
389−
390− it "returns 204 if the type is '()'" $ do
391− patch' "empty" "" `shouldRespondWith` ""{ matchStatus = 204 }
392−
393− it "responds with 415 if the request body media type is unsupported" $ do
394− let patch'' x = Test.Hspec.Wai.request methodPatch x [(hContentType
395− , "application/nonsense")]
396− patch'' "/" "anything at all" `shouldRespondWith` 415
314+-- }}}
315+------------------------------------------------------------------------------
316+-- * headerSpec {{{
317+------------------------------------------------------------------------------
397318
398319type HeaderApi a = Header "MyHeader" a :> Delete '[JSON] ()
399320headerApi :: Proxy (HeaderApi a)
@@ -411,23 +332,30 @@ headerSpec = describe "Servant.API.Header" $ do
411332 expectsString Nothing = error "Expected a string"
412333
413334 with (return (serve headerApi expectsInt)) $ do
414− let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader" ,"5")]
335+ let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "5")]
415336
416337 it "passes the header to the handler (Int)" $
417− delete' "/" "" `shouldRespondWith` 204
338+ delete' "/" "" `shouldRespondWith` 200
418339
419340 with (return (serve headerApi expectsString)) $ do
420− let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader" ,"more from you")]
341+ let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "more from you")]
421342
422343 it "passes the header to the handler (String)" $
423− delete' "/" "" `shouldRespondWith` 204
344+ delete' "/" "" `shouldRespondWith` 200
424345
346+-- }}}
347+------------------------------------------------------------------------------
348+-- * rawSpec {{{
349+------------------------------------------------------------------------------
425350
426351type RawApi = "foo" :> Raw
352+
427353rawApi :: Proxy RawApi
428354rawApi = Proxy
355+
429356rawApplication :: Show a => (Request -> a) -> Application
430−rawApplication f request_ respond = respond $ responseLBS ok200 [] (cs $ show $ f request_)
357+rawApplication f request_ respond = respond $ responseLBS ok200 []
358+ (cs $ show $ f request_)
431359
432360rawSpec :: Spec
433361rawSpec = do
@@ -448,7 +376,10 @@ rawSpec = do
448376 liftIO $ do
449377 simpleBody response `shouldBe` cs (show ["bar" :: String])
450378
451−
379+-- }}}
380+------------------------------------------------------------------------------
381+-- * alternativeSpec {{{
382+------------------------------------------------------------------------------
452383type AlternativeApi =
453384 "foo" :> Get '[JSON] Person
454385 :<|> "bar" :> Get '[JSON] Animal
@@ -456,11 +387,12 @@ type AlternativeApi =
456387 :<|> "bar" :> Post '[JSON] Animal
457388 :<|> "bar" :> Put '[JSON] Animal
458389 :<|> "bar" :> Delete '[JSON] ()
459−unionApi :: Proxy AlternativeApi
460−unionApi = Proxy
461390
462−unionServer :: Server AlternativeApi
463−unionServer =
391+alternativeApi :: Proxy AlternativeApi
392+alternativeApi = Proxy
393+
394+alternativeServer :: Server AlternativeApi
395+alternativeServer =
464396 return alice
465397 :<|> return jerry
466398 :<|> return "a string"
@@ -468,10 +400,10 @@ unionServer =
468400 :<|> return jerry
469401 :<|> return ()
470402
471−unionSpec :: Spec
472−unionSpec = do
403+alternativeSpec :: Spec
404+alternativeSpec = do
473405 describe "Servant.API.Alternative" $ do
474− with (return $ serve unionApi unionServer) $ do
406+ with (return $ serve alternativeApi alternativeServer) $ do
475407
476408 it "unions endpoints" $ do
477409 response <- get "/foo"
@@ -488,7 +420,10 @@ unionSpec = do
488420
489421 it "returns 404 if the path does not exist" $ do
490422 get "/nonexistent" `shouldRespondWith` 404
491−
423+-- }}}
424+------------------------------------------------------------------------------
425+-- * responseHeaderSpec {{{
426+------------------------------------------------------------------------------
492427type ResponseHeadersApi =
493428 Get '[JSON] (Headers '[Header "H1" Int, Header "H2" String] String)
494429 :<|> Post '[JSON] (Headers '[Header "H1" Int, Header "H2" String] String)
@@ -505,26 +440,29 @@ responseHeadersSpec :: Spec
505440responseHeadersSpec = describe "ResponseHeaders" $ do
506441 with (return $ serve (Proxy :: Proxy ResponseHeadersApi) responseHeadersServer) $ do
507442
508− let methods = [(methodGet, 200), (methodPost, 201), (methodPut, 200), (methodPatch, 200)]
443+ let methods = [methodGet, methodPost, methodPut, methodPatch]
509444
510445 it "includes the headers in the response" $
511− forM_ methods $ \(method, expected) ->
446+ forM_ methods $ \method ->
512447 Test.Hspec.Wai.request method "/" [] ""
513448 `shouldRespondWith` "\"hi\""{ matchHeaders = ["H1" <:> "5", "H2" <:> "kilroy"]
514− , matchStatus = expected
449+ , matchStatus = 200
515450 }
516451
517452 it "responds with not found for non-existent endpoints" $
518− forM_ methods $ \(method,_) ->
453+ forM_ methods $ \method ->
519454 Test.Hspec.Wai.request method "blahblah" [] ""
520455 `shouldRespondWith` 404
521456
522457 it "returns 406 if the Accept header is not supported" $
523− forM_ methods $ \(method,_) ->
458+ forM_ methods $ \method ->
524459 Test.Hspec.Wai.request method "" [(hAccept, "crazy/mime")] ""
525460 `shouldRespondWith` 406
526461
527−
462+-- }}}
463+------------------------------------------------------------------------------
464+-- * routerSpec {{{
465+------------------------------------------------------------------------------
528466routerSpec :: Spec
529467routerSpec = do
530468 describe "Servant.Server.Internal.Router" $ do
@@ -543,6 +481,10 @@ routerSpec = do
543481 it "calls f on route result" $ do
544482 get "" `shouldRespondWith` 202
545483
484+-- }}}
485+------------------------------------------------------------------------------
486+-- * miscCombinatorSpec {{{
487+------------------------------------------------------------------------------
546488type MiscCombinatorsAPI
547489 = "version" :> HttpVersion :> Get '[JSON] String
548490 :<|> "secure" :> IsSecure :> Get '[JSON] String
@@ -561,8 +503,8 @@ miscServ = versionHandler
561503 secureHandler NotSecure = return "not secure"
562504 hostHandler = return . show
563505
564−miscReqCombinatorsSpec :: Spec
565−miscReqCombinatorsSpec = with (return $ serve miscApi miscServ) $
506+miscCombinatorSpec :: Spec
507+miscCombinatorSpec = with (return $ serve miscApi miscServ) $
566508 describe "Misc. combinators for request inspection" $ do
567509 it "Successfully gets the HTTP version specified in the request" $
568510 go "/version" "\"HTTP/1.0\""
@@ -574,3 +516,35 @@ miscReqCombinatorsSpec = with (return $ serve miscApi miscServ) $
574516 go "/host" "\"0.0.0.0:0\""
575517
576518 where go path res = Test.Hspec.Wai.get path `shouldRespondWith` res
519+-- }}}
520+------------------------------------------------------------------------------
521+-- * Test data types {{{
522+------------------------------------------------------------------------------
523+
524+data Person = Person {
525+ name :: String,
526+ age :: Integer
527+ }
528+ deriving (Eq, Show, Generic)
529+
530+instance ToJSON Person
531+instance FromJSON Person
532+
533+alice :: Person
534+alice = Person "Alice" 42
535+
536+data Animal = Animal {
537+ species :: String,
538+ numberOfLegs :: Integer
539+ }
540+ deriving (Eq, Show, Generic)
541+
542+instance ToJSON Animal
543+instance FromJSON Animal
544+
545+jerry :: Animal
546+jerry = Animal "Mouse" 4
547+
548+tweety :: Animal
549+tweety = Animal "Bird" 2
550+-- }}}