git.iko.soy/typeable/servant
on master help sign in
client test suite: testing ReqBody
a0c675fSönke Hahn
test/Servant/ClientSpec.hs+13−6
@@ -13,8 +13,8 @@ import Network.Wai
13import Network.Wai.Handler.Warp
13import Network.Wai.Handler.Warp
14import Test.Hspec
14import Test.Hspec
15
15
16−import Servant.Client
17import Servant.API
16import Servant.API
17+import Servant.Client
18import Servant.Server
18import Servant.Server
19
19
20import Servant.ServerSpec
20import Servant.ServerSpec
@@ -22,6 +22,7 @@ import Servant.ServerSpec
22type Api =
22type Api =
23 "get" :> Get Person
23 "get" :> Get Person
24 :<|> "capture" :> Capture "name" String :> Get Person
24 :<|> "capture" :> Capture "name" String :> Get Person
25+ :<|> "body" :> ReqBody Person :> Post Person
25api :: Proxy Api
26api :: Proxy Api
26api = Proxy
27api = Proxy
27
28
@@ -29,22 +30,28 @@ server :: Application
29server = serve api (
30server = serve api (
30 return alice
31 return alice
31 :<|> (\ name -> return $ Person name 0)
32 :<|> (\ name -> return $ Person name 0)
33+ :<|> return
32 )
34 )
33
35
34withServer :: (URIAuth -> IO a) -> IO a
36withServer :: (URIAuth -> IO a) -> IO a
35withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
37withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
36
38
37−getA :: URIAuth -> EitherT String IO Person
39+getGet :: URIAuth -> EitherT String IO Person
38−getB :: String -> URIAuth -> EitherT String IO Person
40+getCapture :: String -> URIAuth -> EitherT String IO Person
39−(getA :<|> getB) = client api
41+getBody :: Person -> URIAuth -> EitherT String IO Person
42+(getGet :<|> getCapture :<|> getBody) = client api
40
43
41spec :: Spec
44spec :: Spec
42spec = do
45spec = do
43 it "Servant.API.Get" $ withServer $ \ host -> do
46 it "Servant.API.Get" $ withServer $ \ host -> do
44− runEitherT (getA host) `shouldReturn` Right alice
47+ runEitherT (getGet host) `shouldReturn` Right alice
45
48
46 it "Servant.API.Capture" $ withServer $ \ host -> do
49 it "Servant.API.Capture" $ withServer $ \ host -> do
47− runEitherT (getB "Paula" host) `shouldReturn` Right (Person "Paula" 0)
50+ runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0)
51+
52+ it "Servant.API.ReqBody" $ withServer $ \ host -> do
53+ let p = Person "Clara" 42
54+ runEitherT (getBody p host) `shouldReturn` Right p
48
55
49
56
50-- * utils
57-- * utils