@@ -10,6 +10,7 @@ module Servant.ServerSpec where
11import Data.Aeson
11import Data.Aeson
12import Data.Proxy
12import Data.Proxy
13+import Data.String.Conversions
13import GHC.Generics
14import GHC.Generics
14import Network.HTTP.Types
15import Network.HTTP.Types
15import Network.Wai
16import Network.Wai
@@ -20,6 +21,7 @@ import Test.Hspec.Wai
20import Servant.API.Get
21import Servant.API.Get
21import Servant.API.GetParam
22import Servant.API.GetParam
22import Servant.API.Post
23import Servant.API.Post
24+import Servant.API.Raw
23import Servant.API.RQBody
25import Servant.API.RQBody
24import Servant.API.Sub
26import Servant.API.Sub
25import Servant.API.Union
27import Servant.API.Union
@@ -60,6 +62,7 @@ spec = do
61 getParamSpec
63 getParamSpec
@@ -67,7 +70,8 @@ type GetApi = Get Person
67getApi :: Proxy GetApi
70getApi :: Proxy GetApi
68getApi = Proxy
71getApi = Proxy
70−getSpec :: Spec = do
73+getSpec :: Spec
71 describe "Servant.API.Get" $ do
75 describe "Servant.API.Get" $ do
72 with (return (serve getApi (return alice))) $ do
76 with (return (serve getApi (return alice))) $ do
73 it "allows to GET a Person" $ do
77 it "allows to GET a Person" $ do
@@ -118,6 +122,32 @@ postSpec = do
125+type RawApi = "foo" :> Raw
126+rawApi :: Proxy RawApi
128+rawApplication :: Show a => (Request -> a) -> Application
129+rawApplication f request respond = respond $ responseLBS ok200 [] (cs $ show $ f request)
133+ describe "Servant.API.Raw" $ do
134+ it "runs applications" $ do
135+ (flip runSession) (serve rawApi (rawApplication (const (42 :: Integer)))) $ do
136+ response <- Network.Wai.Test.request defaultRequest{
140+ simpleBody response `shouldBe` "42"
142+ it "gets the pathInfo unmodified" $ do
143+ (flip runSession) (serve rawApi (rawApplication pathInfo)) $ do
144+ response <- Network.Wai.Test.request defaultRequest{
148+ simpleBody response `shouldBe` cs (show ["foo" :: String])
121type UnionApi =
151type UnionApi =
122 "foo" :> Get Person
152 "foo" :> Get Person
123 :<|> "bar" :> Get Animal
153 :<|> "bar" :> Get Animal