You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MockWS {
case ("GET", ".../something") =>Action { ... }
}
Then the mocked route is not called.
It seems the mock only works is user do not define query parameters in the url(..).
While most of the time query parameters are passed via .addQueryStringParameters(..), it's still a valid usage of Play WS and would be nice if supported by MockWS.
The text was updated successfully, but these errors were encountered:
MockWS is just passing in the method and the full URL to the partial function. There's nothing stopping you from inspecting the URL to your hearts content:
defpath(url: String) = ... // extract path without query paramsMockWS {
case ("GET", url) if path(url) ==".../something"=>Action { ... }
}
To make this a bit more comfortable, you can use the SIRD matchers from Play:
importplay.api.routing.sird.UrlContextMockWS {
case ("GET", p".../something") =>Action { ... }
}
Then MockWS partial function works with only the path ".../something".
It's this behavior that I find surprising. Basically it means that to define the MockWS partial function I need to know on my production code is implemented, which I should not care about.
I didn't know SIRD matchers would work in this context, I'll give it a try.
When the production code uses code similar to the following:
wsClient .url(".../something?someQueryParam=some value") .get()
And a test defines MockWS like this:
Then the mocked route is not called.
It seems the mock only works is user do not define query parameters in the
url(..)
.While most of the time query parameters are passed via
.addQueryStringParameters(..)
, it's still a valid usage of Play WS and would be nice if supported by MockWS.The text was updated successfully, but these errors were encountered: