I'm writing a test method which requires 3-4 api calls. before the last assertion check.
When using app.test() method all responses are in closure form so requests are nested and really messy.
I tried app.client() get and post methods, and get HTTPClientError.emptyScheme error, it seems it requires full server url.
Then I tried to call the controller method directory but as the controller routes has some middlewares, request will not go through the middlewares when directly calling the method.
Any suggestion for how send some request to controllers and use the response in next request in Test package?
#Integrated Testing for a controller with middleware
1 messages · Page 1 of 1 (latest)
You should be able to call app.performTest() which returns a response you can use linearly
Alternatively you can spin up the app and make a request to http://localhost:\(port)/path
See how Vapor's server tests work for that
Unfortunately app.performTest() uses XCHTTPRequest which it's initializer is private.
'XCTHTTPRequest' initializer is inaccessible due to 'internal' protection level
why it does not have public initializer?
@blissful panther Why isn't the existing performTest() with beforeRequest closure adequate here?
Nested hell when making multiple requests
It made sense, pre a/a but these days we should flatten it out
IIRC we added some stuff to make it possible but clearly not all the way
Works for me, then
Should I open an issue?
I was under the impression Tim would handle it, but as he hasn't yet done so, it certainly wouldn't hurt 🙂
(That's a yes, after my inimitable fashion 😅)
@desert pawn feel free to do a PR if you like!