#Integrated Testing for a controller with middleware

1 messages · Page 1 of 1 (latest)

desert pawn
#

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?

blissful panther
#

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

desert pawn
blissful panther
#

I don't have any major issues with making it public

#

@keen helm any objections?

keen helm
#

@blissful panther Why isn't the existing performTest() with beforeRequest closure adequate here?

blissful panther
#

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

keen helm
#

Works for me, then

desert pawn
#

Should I open an issue?

keen helm
#

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 😅)

blissful panther
#

@desert pawn feel free to do a PR if you like!