git.iko.soy/typeable/servant
on master help sign in
add a testcase to very that we reject invalid json bodies with HTTP status 400
90ea565Alp Mestanogullari
src/Servant/Server.hs+1−1
@@ -36,7 +36,7 @@ toApplication ra request respond = do
36data RouteMismatch =
36data RouteMismatch =
37 NotFound -- ^ the usual "not found" error
37 NotFound -- ^ the usual "not found" error
38 | WrongMethod -- ^ a more informative "you just got the HTTP method wrong" error
38 | WrongMethod -- ^ a more informative "you just got the HTTP method wrong" error
39− | InvalidBody -- ^ an even more informative "you json request body wasn't valid" error
39+ | InvalidBody -- ^ an even more informative "your json request body wasn't valid" error
40 deriving (Eq, Show)
40 deriving (Eq, Show)
41
41
42-- |
42-- |
test/Servant/ServerSpec.hs+3
@@ -154,6 +154,9 @@ postSpec = do
154 matchStatus = 201
154 matchStatus = 201
155 }
155 }
156
156
157+ it "correctly rejects invalid request bodies with status 400" $ do
158+ post "/" "some invalid body" `shouldRespondWith` 400
159+
157
160
158type RawApi = "foo" :> Raw
161type RawApi = "foo" :> Raw
159rawApi :: Proxy RawApi
162rawApi :: Proxy RawApi