@@ -10,6 +10,7 @@ module Servant.ServerSpec where
1010
1111import Data.Aeson
1212import Data.Proxy
13+import Data.String.Conversions
1314import GHC.Generics
1415import Network.HTTP.Types
1516import Network.Wai
@@ -20,6 +21,7 @@ import Test.Hspec.Wai
2021import Servant.API.Get
2122import Servant.API.GetParam
2223import Servant.API.Post
24+import Servant.API.Raw
2325import Servant.API.RQBody
2426import Servant.API.Sub
2527import Servant.API.Union
@@ -60,6 +62,7 @@ spec = do
6062 getSpec
6163 getParamSpec
6264 postSpec
65+ rawSpec
6366 unionSpec
6467
6568
@@ -67,7 +70,8 @@ type GetApi = Get Person
6770getApi :: Proxy GetApi
6871getApi = Proxy
6972
70−getSpec :: Spec = do
73+getSpec :: Spec
74+getSpec = do
7175 describe "Servant.API.Get" $ do
7276 with (return (serve getApi (return alice))) $ do
7377 it "allows to GET a Person" $ do
@@ -118,6 +122,32 @@ postSpec = do
118122 }
119123
120124
125+type RawApi = "foo" :> Raw
126+rawApi :: Proxy RawApi
127+rawApi = Proxy
128+rawApplication :: Show a => (Request -> a) -> Application
129+rawApplication f request respond = respond $ responseLBS ok200 [] (cs $ show $ f request)
130+
131+rawSpec :: Spec
132+rawSpec = do
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{
137+ pathInfo = ["foo"]
138+ }
139+ liftIO $ do
140+ simpleBody response `shouldBe` "42"
141+
142+ it "gets the pathInfo unmodified" $ do
143+ (flip runSession) (serve rawApi (rawApplication pathInfo)) $ do
144+ response <- Network.Wai.Test.request defaultRequest{
145+ pathInfo = ["foo"]
146+ }
147+ liftIO $ do
148+ simpleBody response `shouldBe` cs (show ["foo" :: String])
149+
150+
121151type UnionApi =
122152 "foo" :> Get Person
123153 :<|> "bar" :> Get Animal