At work we have a function to parse a response in yesod-test to a JSON value. This seemed pretty widely helpful to me, would you want such a function in yesod-test?
-- | Parses the response body from JSON and returns it.
requireJsonParse :: FromJSON a => YesodExample App a
requireJsonParse = do
YT.withResponse $ \ (SResponse _status headers body) -> do
unless
((hContentType, "application/json; charset=utf-8") `elem` headers)
(failure $ T.pack $ "Expected `Content-Type: application/json; charset=utf-8` in the headers, got: " ++ show headers)
case eitherDecode' body of
Left err -> failure $ T.concat ["Failed to parse JSON response; error: ", T.pack err]
Right v -> return v
It might fit more into the existing naming schemes of yesod-test if it was named assertJsonParse (or assertJSONParse) and took a string parameter for the assertion name.
At work we have a function to parse a response in yesod-test to a JSON value. This seemed pretty widely helpful to me, would you want such a function in yesod-test?
It might fit more into the existing naming schemes of yesod-test if it was named
assertJsonParse(orassertJSONParse) and took a string parameter for the assertion name.