check greater than or less than in wiremock

1.2k views Asked by At

I have a situation where I need to check the amount and return the response accordingly.

If the amount is >=100, then response would be different, else for amount < 100, i need to send error response.

Please refer the sample json in request body.

{ "accountName":"ABCZYZ", "specialCode":"MYCODE", "amount":"100", "currencyType":"MYCURRENCY" }

Below is my wiremock mapping file

{ "request": { "urlPattern": "/some/url", "method": "POST", "bodyPatterns" : [ { "matchesJsonPath" : "$[?(@.amount < 100)]" } ] },

"response": { "status": 200, "body": "MY_REPONSE_IN_JSON_FORMAT" } }

I am facing issue reagrding the above matching pattern.

Could anyone please help me for the same?

Thanks M

1

There are 1 answers

3
Barath On

Try changing "100" to 100

tested like below :

Request :

{
    "accountName": "ABCZYZ",
    "specialCode": "MYCODE",
    "amount": 100,
    "currencyType": "MYCURRENCY"
}

JsonPath:

$[?(@.amount <= 100)]

Response:

[{"accountName":"ABCZYZ","specialCode":"MYCODE","amount":100,"currencyType":"MYCURRENCY"}]