-
Notifications
You must be signed in to change notification settings - Fork 116
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
How to send invalid data with the client to test negative scenarios? #521
Comments
If you want to test your server implementation (the type that conforms to While the example is specific to Vapor, notice that the test itself is web framework-agnostic, the file doesn't even import Vapor. |
My goal to write a integration test (not a unit test that just calls methods without real network) that sends actual network request, and I'm just wondering, if it's possible to send invalid data using the client code generated by the Swift Code gen? |
Depends on what you mean by "invalid". If you mean malformed JSON, then the answer is no (unless you write a middleware that malforms the outgoing requests, I guess that'd work). If you mean that e.g. the server expects a string with a certain prefix and that prefix is missing, then yes, but that's purely application-logic semantics. If you want to test how your server is performing fully integrated, maybe use something like XCTVapor (if you're using Vapor) or whatever web framework you use. That should allow you to send completely arbitrary requests and verify that your server behaves as expected. |
seems to be this could work and would be the easiest , thanks!
Thanks for help |
Question
Hi all
I'd like to write a test, that verifies that my Swift Code generated API will return a 400 error, when data sent to the sever is not valid.
I'd prefer to use client code generated by swift code gen too but how can I do it?
code path I want to test in my server implementation:
basically check that I can map the enum from API to local one
my test code :
The text was updated successfully, but these errors were encountered: