I am trying to simulate a JSON based API in which ...
# help
a
I am trying to simulate a JSON based API in which based on the value of one of the parameter from request payload ("phone"), the response would be mapped. If the value start with 5 and it contains 10 digit the success response would be triggered. I am using standalone wiremock jar for this simulation. Issue - Somehow my mapping is not working, even if I send the value of "phone" tag with more then 10 digits or digits starting with any value it is responding with the mapped response. Expectation - Based on the regex configured in mapping, the wiremock should only respond with success response only if the starting digit is 5 and total length is 10 characters. Please let me know what changes I need to make in my mapping file. Below is the content of my mapping file -
{
"name": "email_happypath", "request": { "method": "POST", "url": "/send/email", "bodyPatterns": [ { "matchesJsonPath": "$.phone", "matches": "^5\\d[9]$" } ] }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "bodyFileName": "email_happypath.json", "transformers" : ["response-template"] } }
l
I had a little play and this is what I came up with:
Copy code
{
  "name": "email_happypath",
  "request": {
    "method": "POST",
    "url": "/send/email",
    "bodyPatterns": [
      {
        "matchesJsonPath": "$[?(@.phone =~ /^5\\d{9}$/i)]"
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "jsonBody": {
      "status": "OK"
    }
  }
}
I left out your
bodyFileName
part just so I could test this out so you will have to replace the
jsonBody
in the above example. I think that should work though.
a
It worked. Thank you for your help @Lee Turner 🙂
👍 1