Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a note to the documentation on testing controllers #68

Open
Ryan-Gordon opened this issue Jan 13, 2019 · 1 comment
Open

Add a note to the documentation on testing controllers #68

Ryan-Gordon opened this issue Jan 13, 2019 · 1 comment

Comments

@Ryan-Gordon
Copy link
Contributor

As an exegesis user
I want a way to test my controllers
so that I can also test certain parts of the context (does the controller set the correct status code for example)

given an exegesis controller

when my controller modifies the status code

then I should be able to asset this change with access to the context object

given an exegesis controller

when my controller returns a result to the user
then I should be able review the returned payload to ensure it conforms to specs

I could try to implement this but wondering where to start.

@jwalton
Copy link
Contributor

jwalton commented Jan 14, 2019

The way I've been doing this so far is to spin up an HTTP server and test things "full stack":

https://github.com/exegesis-js/exegesis-express/blob/0bd80261e830d194c59ad6d758d3688de7b9d104/test/integrationTest.ts#L55-L69

That's maybe not the most "unit test" way to do this, though. It does have some upsides, in that you can get the full schema validation on all input parameters and on the result.

If you want something a little more "focused", maybe a function that lets you provide a controller, input parameters, and a body, and runs it and returns back the result? You could generate a dummy "TestContext" object and pass it through. It would be very nice to keep response validation here somehow, but you'd need the full OpenAPI document and either a reference to the path or a reference to the schema you expect the return type to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants