From a0c675f603865591dc54e1d0b7d8a38988131519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Hahn?= Date: Thu, 30 Oct 2014 13:08:41 +0000 Subject: [PATCH] client test suite: testing ReqBody --- test/Servant/ClientSpec.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/Servant/ClientSpec.hs b/test/Servant/ClientSpec.hs index e9e8f18a..ead73e61 100644 --- a/test/Servant/ClientSpec.hs +++ b/test/Servant/ClientSpec.hs @@ -13,8 +13,8 @@ import Network.Wai import Network.Wai.Handler.Warp import Test.Hspec -import Servant.Client import Servant.API +import Servant.Client import Servant.Server import Servant.ServerSpec @@ -22,6 +22,7 @@ import Servant.ServerSpec type Api = "get" :> Get Person :<|> "capture" :> Capture "name" String :> Get Person + :<|> "body" :> ReqBody Person :> Post Person api :: Proxy Api api = Proxy @@ -29,22 +30,28 @@ server :: Application server = serve api ( return alice :<|> (\ name -> return $ Person name 0) + :<|> return ) withServer :: (URIAuth -> IO a) -> IO a withServer action = withWaiDaemon (return server) (action . mkHost "localhost") -getA :: URIAuth -> EitherT String IO Person -getB :: String -> URIAuth -> EitherT String IO Person -(getA :<|> getB) = client api +getGet :: URIAuth -> EitherT String IO Person +getCapture :: String -> URIAuth -> EitherT String IO Person +getBody :: Person -> URIAuth -> EitherT String IO Person +(getGet :<|> getCapture :<|> getBody) = client api spec :: Spec spec = do it "Servant.API.Get" $ withServer $ \ host -> do - runEitherT (getA host) `shouldReturn` Right alice + runEitherT (getGet host) `shouldReturn` Right alice it "Servant.API.Capture" $ withServer $ \ host -> do - runEitherT (getB "Paula" host) `shouldReturn` Right (Person "Paula" 0) + runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0) + + it "Servant.API.ReqBody" $ withServer $ \ host -> do + let p = Person "Clara" 42 + runEitherT (getBody p host) `shouldReturn` Right p -- * utils