Hello folks, do you know if im using well the date...
# wiremock-java
s
Hello folks, do you know if im using well the dates functions (now) ? "bodyPatterns": [{ "matchesXPath" : { "expression": "//PickUp/Date/text()", "equalTo": "{{now + 7 days}}", "actualFormat" : "yyyy-MM-dd" } }] When i put the date hardcoded works well "bodyPatterns": [{ "matchesXPath" : { "expression": "//PickUp/Date/text()", "equalTo": "2024-08-08", "actualFormat" : "yyyy-MM-dd" } }]
l
I don't think that request matchers (like the
equalTo
) can be used with handlebars expressions. You might need to take a look at
equalToDateTime
where you can do the
now
+ offset without the need for handlebars expressions. Something like this maybe:
Copy code
"bodyPatterns" : [ {
      "matchesXPath" : {
        "expression" : "//PickUp/Date/text()",
        "equalToDateTime" : "now +7 days",
        "actualFormat": "yyyy-MM-dd"
      }
    } ]
More information about the dates and time can be found here - https://wiremock.org/docs/request-matching/#dates-and-times
s
Thank you so much for your response. I tried this and other keys as "before", etc.. but is not working 😕
Seem the date generated with "now +7 days" is diferent that 2024-08-08
I also check using "now" passing actual date to request and same result :S . As i show in the next capture
image.png
l
Ah, I see. I think the problem is that
now
returns a date/time so you are effectively comparing an incoming date
2024-08-08T00:00:00Z
with a value where the time portion is populate with the time when
now
was executed. Try to truncate the expected:
Copy code
"bodyPatterns": [{
      "matchesXPath" : {
        "expression": "//PickUp/Date/text()",
        "equalToDateTime" : "now +7 days",
        "actualFormat" : "yyyy-MM-dd",
        "truncateExpected": "first hour of day"
      }
    }]
s
Ok, now (xD) is working. Sorry for the joke but im happy jajaja. Thank you so much Lee. If you come to Alicante, you a beer for free :P
I had also tried "truncate" but not truncateExpected
l
Awesome, glad it is working
❤️ 1