1

I'm trying to return stubbed date in Wiremock. The expected date is today in ISO format yyyy-MM-dd. I cannot make it work. Here's the error:

.pointInTime [equalToDateTime] now +0 seconds| 2022-04-13}

Here's my relevant part of the mapping:

{
  "matchesJsonPath": {
    "expression": "$.pointInTime",
    "equalToDateTime": "now",
    "actualFormat": "yyyy-MM-dd"
  }

As far I can say, Wiremock has problems with dealing with dates only without time part.

EDIT I tried to use answers from post given by @Sambit without no luck.

{
   "matchesJsonPath":{
      "expression":"$.pointInTime",
      "equalToDateTime":"{{now timezone='Europe/Warsaw'}}"
   }
}

Here's the now... part is tried as literal:

$.pointInTime [equalToDateTime] {{now timezone='Europe/Warsaw'}}> but was 2022-04-13

menteith
  • 596
  • 14
  • 51
  • May be useful for you https://stackoverflow.com/questions/57602585/wiremock-date-format – Sambit Apr 13 '22 at 08:40
  • If using @Sambit's answer, you'll need to specify a format in your `equalToDateTime` => `"equalToDateTime": "{{now timezone='Europe/Warsaw' format='yyyy-MM-dd'}}"`, otherwise it will include hours/minutes/seconds. You may also want to try triple brackets instead of double... I've found the behavior to be frustratingly inconsistent (tbf, I haven't dug into why and when to use three vs. two => `{{{}}}` vs `{{}}`) – agoff Apr 13 '22 at 13:25
  • @agoff Thanks for this. I tried your solution but it failed to work. I also tried triple brackets. Each time Wiremock interprets what is inside `{}` as string literl. – menteith Apr 13 '22 at 20:19

1 Answers1

0

The solution is to truncate the expected value (the one represented by now) to the first hour of the day so that you're matching date only with date only:

{
  "matchesJsonPath": {
      "expression": "$.pointInTime",
      "equalToDateTime": "now",
      "truncateExpected": "first hour of day"
  }
}
Tom
  • 3,471
  • 21
  • 14