new issue: I have a test that triggers my service ...
# help
b
new issue: I have a test that triggers my service to make two "paged" requests to wiremock. The url pattern will be identical in both cases, but the first one contains a query parameter "after", while the other will not have the "after" query parameter at all. With mockserver I used a callback to decide what response to send based on the presence or absence of that query parameter. In WireMock, I was thinking maybe I just make two separate stubs:
wiremock.stubFor(
get(urlPathEqualTo(teamMembershipUrl))
.withQueryParam("after", equalTo(after))
with the second stub omitting the query parameter. Unfortunately what I'm actually hitting is that all requests are hitting the stub that omits the query parameter every time, which results in an infinite loop in my service code. So I guess the question here is, is there a better way to do this or do I need to rely on another response transformer?
l
Two stubs seems like a good option. Would the
absent
matcher work in this instance ?
Copy code
{
  "mappings": [
    {
      "request": {
        "urlPath": "/thing/1",
        "method": "GET",
        "queryParameters": {
          "after": {
            "equalTo": "4"
          }
        }
      },
      "response": {
        "status": 200,
        "body": "Body content for stub with after parameter"
      }
    },
    {
      "request": {
        "urlPath": "/thing/1",
        "method": "GET",
        "queryParameters": {
          "after": {
            "absent": true
          }
        }
      },
      "response": {
        "status": 200,
        "body": "Body content for stub without after parameter"
      }
    }
  ]
}
b
I'm not using json based stubbing - how would I modify that to work in-code?
l
There are examples on the docs page here - https://wiremock.org/docs/request-matching/#absence
b
ahh, absent(). Perfect, thank you, that fixed it
and with that... I think I have it working. Thanks for the help
🙌 2