Home > Net >  how to make dates dynamic in query string in url in wiremock
how to make dates dynamic in query string in url in wiremock

Time:06-22

My request url in mapping.json

"request" : {
    "url": "/abc/v1/?FromDate=2022-06-18&ToDate=2022-06-18",
    "method" : "GET"
}

I want to make FromDate and ToDate dynamic in above url in my wiremock mapping so that FromDate = 6 weeks from today minus 1 month and Todate = today minus 1 day .

CodePudding user response:

WireMock has a dynamic date matching feature for this purpose.

First you need to switch to matching the URL just on the path, then specify the two date parameters in their own matchers.

Assuming you want to use dates only (not full timestamps) you'll need to set the format appropriately and truncate the expected value to the nearest day.

So the result would be something like:

"request": {
    "method": "GET",
    "urlPath": "/abc/v1",

    "queryParams": {
      "FromDate": {
        "after": "now -1 months",
        "actualFormat": "dd/MM/yyyy",
        "truncateExpected": "first hour of day"
      },

      "ToDate": {
        "equalToDateTime": "now -1 days",
        "actualFormat": "dd/MM/yyyy",
        "truncateExpected": "first hour of day"
      }
    }
  }

CodePudding user response:

Thanks so much Tom .I get the following error after using the above suggestion

Query: FromDate [after] now -1 months<<<<< Query does not match 
Query: ToDate [equalToDateTime] now -1 days<<<<< Query does not match
  • Related