'Wiremock request matching with dynamic date - How to check a date in test?

I need to check in my test, that the date in request is exactly Today. How can I do this? Tried different ways from the Doc, but haven't got the desired result. Help please a poor junior qa :)

What way I tried (my collegue advised me this one, and it looks rather ok consider the documentation)

{
    "request": {
        "urlPath": "/test/calc",
        "method": "POST",
        "headers": {
            "Accept": {
                "equalTo": "application/json"
            },
            "Content-Type": {
                "equalTo": "application/json"
            }
        },
        "bodyPatterns": [
            {
                "matchesJsonPath": {
                    "expression": "$.addDate",
                    "and": [
                        {
                            "before": "now + 1 days"
                        },
                        {
                            "after": "now - 1 days"
                        }
                    ]
                },
                "equalToJson": {
                    "RequestBody": {
                        "order": {
                            "positionList": [
                                {
                                    "id": 1,
                                    "addDate": "${json-unit.any-string}",
                                    "qty": 1
                                }
                            ]
                        }
                    }
                },
                "ignoreArrayOrder": false
            }
        ]
    },
    "response": {
        "transformers": [
            "response-template"
        ],
        "status": 200,
        "bodyFileName": "v1/test-service-mock-response.json",
        "headers": {
            "Content-Type": "application/json"
        }
    }
}

I need to check parameter "addDate" in request. Date format is = "addDate": "2022-03-31".

*Also tried this variant "addDate": "{{now format='yyyy-MM-dd'}}". It didn't work as well Wiremock didn't match such requests.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source