Hey! I'm having some trouble setting up my wiremoc...
# general
d
Hey! I'm having some trouble setting up my wiremock mapping logic using response templating helpers. I'm trying to understand how to access the request body inside of a
#eq
block - whatever I have setup now is always returning with the false condition. The simplified object coming in is
Copy code
{
  lender-type: 'installment',
  cuId: '1234'
}
The goal is to use response templating to choose which json file to return. I have these sections in my mapping file:
Copy code
"bodyPatterns": [{ 
  "mathesJsonPath": "[?($.lenderId == 'installment')]"
}]
and then further down:
Copy code
"response": {
  "bodyFileName": "{{#eq (jsonPath request.body '$.cuId') '1234'}}respseon_file_A.json{{else}}response_file_B.json{{/eq}}"
}
The
matchesJsonPath
bit seems to work fine as I know I am getting into this mapping file. The problem I'm running into as stated further up above is that when I try to test this logic, the
#eq
block is always returning
response_file_B.json
, no matter what
cuId
field is getting passed. I'm assuming I have some bad character spacing in the handlebars syntax and not to sure how to debug it. Is there anything obvious that I'm doing wrong?
1
a
What version of WireMock are you using? With your example, I was able to successfully retrieve file A or file B depending on
cuId
value.
👀 1
And you’re positive that the
matchesJsonPath
part is working, and you aren’t matching a separate mapping?
d
wiremock-jre3-standalone
2.35.0
Yes, I actually removed all other mapping files to ensure that that wasn't the case - there is only one mapping file in my directory at this point
a
Hmm… And you’ve restarted WireMock since making those changes?
d
Yep 😕
a
Any chance you can give the full mapping and a complete example request body? Might be something going on there
d
Copy code
{
  "name": "installment_mapping",
  "request": {
    "method": "POST",
    "url": "/lender",
    "headers": {
      "Content-Type": {
        "equalTo": "application/json"
      }
    },
    "bodyPatterns": [
      {
        "matchesJsonPath": "[?($.lender-type== 'installment')]"
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "bodyFileName": "{{#eq (jsonPath request.body '$.cuId') '1234'}}response_file_A.json{{else}}response_file_B.json{{/eq}}"
  }
}
Was actually about to ask if the full mapping file might help 😂 The request body is
Copy code
<http://localhost:8080/partner-service/lender>
{
    "firstName": "Danman",
    "lastName": "Mandan",
    "lender-type": "installment",
    "cuId": 1234
}
...actually think I just discovered that changing
cuId
from int to string in the request payload triggers the correct response 🤦
Yeah, I've got it figured out now - was improperly parsing for a string instead of an int in the handlebar
a
haha nice! glad you were able to get it sorted 😄
d
Same 🙂 - thank you for being my rubber duck 😂