Closed JivanRoquet closed 8 months ago
I think you may be looking for the functionality provided by the hspec-wai
library. In particular, the shouldRespondWith
function may be what you are looking for. There are examples of shouldRespondWith
being used in scotty
's test suite.
Well, thanks for the answer obviously. However this lib doesn't seem to allow inspecting the response provided by the endpoint, instead just checking that it's equal to some value. E.g. you can't do "assert that this JSON list has 5 elements in it and they're all Int's".
In the end I simply chose to run the API for real and query it with a regular http client.
@JivanRoquet I suppose it's ultimately a matter of taste here (in addition to engineering elbow grease and OSS maintainership work), but aeson
's responsibility ends at "this response can be parsed as JSON and if not, here's an error". Any validation is up to the user.
You might want to add something like https://hackage.haskell.org/package/hspec-golden-aeson to your project for that.
At present, the best documentation is our test suite and our examples.
With the following endpoint:
How to test
myendpoint
with different possible inputs, for instance: