on master help sign in
This test case reproduces servant issue #3.
aaf448fAlp Mestanogullari
src/Servant/Server.hs+3
@@ -29,6 +29,9 @@ import Servant.Server.Internal
29-- > where listAllBooks = ...
29-- > where listAllBooks = ...
30-- > postBook book = ...
30-- > postBook book = ...
31-- >
31-- >
32+-- > myApi :: Proxy MyApi
33+-- > myApi = Proxy
34+-- >
32-- > app :: Application
35-- > app :: Application
33-- > app = serve myApi server
36-- > app = serve myApi server
34-- >
37-- >
test/Servant/ServerSpec.hs+9−2
@@ -189,19 +189,26 @@ queryParamSpec = do
189 name = "ALICE"
189 name = "ALICE"
190 }
190 }
191
191
192+type PostApi =
193+ ReqBody Person :> Post Integer
192−type PostApi = ReqBody Person :> Post Integer
194+ :<|> "bla" :> ReqBody Person :> Post Integer
193postApi :: Proxy PostApi
195postApi :: Proxy PostApi
194postApi = Proxy
196postApi = Proxy
195
197
196postSpec :: Spec
198postSpec :: Spec
197postSpec = do
199postSpec = do
198 describe "Servant.API.Post and .ReqBody" $ do
200 describe "Servant.API.Post and .ReqBody" $ do
199− with (return (serve postApi (return . age))) $ do
201+ with (return (serve postApi (return . age :<|> return . age))) $ do
200 it "allows to POST a Person" $ do
202 it "allows to POST a Person" $ do
201 post "/" (encode alice) `shouldRespondWith` "42"{
203 post "/" (encode alice) `shouldRespondWith` "42"{
202 matchStatus = 201
204 matchStatus = 201
203 }
205 }
204
206
207+ it "allows alternative routes if all have request bodies" $ do
208+ post "/bla" (encode alice) `shouldRespondWith` "42"{
209+ matchStatus = 201
210+ }
211+
205 it "correctly rejects invalid request bodies with status 400" $ do
212 it "correctly rejects invalid request bodies with status 400" $ do
206 post "/" "some invalid body" `shouldRespondWith` 400
213 post "/" "some invalid body" `shouldRespondWith` 400
207
214