Hi again. From <https://docs.wiremock.io/response-...
# help
o
Hi again. From https://docs.wiremock.io/response-templating/conditional-logic-and-iteration/ I see the following if else example:
Copy code
{{#eq name 'Dan'}}
  <div id="dan">...</div>
{{else eq name 'Mark'}}
  <div id="mark">...</div>
{{else}}
  <div id="anon">...</div>
{{/eq}}
Out of interest where and how is the
name
parameter defined? Asking because I'm trying to
eq
with
jsonPath
and it doesn't appear to work. So for example:
Copy code
{{#eq jsonPath request.body '$.PaReq' 'authorisation_fail'}}
            <td id="threeds-sim-pa-res">authorisation_fail</td>
        {{else}}
            <td id="threeds-sim-pa-res">authorised</td>
        {{/eq}}
t
There isn’t a
name
parameter defines as standard. These examples aren’t great TBH - we should replace with some more realistic ones. That page does contain a list of all the attributes on the request model, so I’d suggest starting there to find the data you need. If you want to fetch data out of a JSON request body then
{{jsonPath request.body '$.myAttribute'}}
is the place to start
o
Sorry I wasn't clear. I do have the
{{jsonPath request.body '$.myAttribute'}}
in my code snippet. I was implying it doesn't seem to work with the
{{#eq}}
and
{{else}}
. I always get the resulting code block in the
{{else}}
block, i.e.
<td id="threeds-sim-pa-res">authorised</td>
, even if the
jsonPath request.body '$.PaReq'
is equal to
authorisation_fail
t
Can you share the full details of what you’re trying to do? Might be easier for me to make a suggestion that way.
o
So my stub is pretty standard. It's just returning an html page:
Copy code
wm.register(post(urlMatching("/3ds-simulator\\?orderCode=.*"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withTransformers("response-template")
                        .withBody(readFile("3dsSimulator.html"))
                        .withHeader("Content-Type", "text/html")));
3dsSimulator.html
looks something like:
Copy code
<table>
    <thead>
    <tr>
        <th scope="col">Name</th>
        <th scope="col">Value</th>
    </tr>
    </thead>
    <tr>
        <td><strong>PaRes</strong></td>
        {{#eq jsonPath request.body '$.PaReq' 'authorisation_fail'}}
            <td id="threeds-sim-pa-res">authorisation_fail</td>
        {{else}}
            <td id="threeds-sim-pa-res">authorised</td> <---this line is always returned
        {{/eq}}
    </tr>
    <tr>
        <td><strong>MD</strong></td>
        <td id="threeds-sim-md">{{jsonPath request.body '$.MD'}}</td>
    </tr>
</table>
I'm finding no matter the value of the
PaReq
in the POST request body is, I always get
<td id="threeds-sim-pa-res">authorised</td>
in the response body from Wiremock.
t
I think you’ll need to nest the helpers like this:
Copy code
{{#eq (jsonPath request.body '$.PaReq') 'authorisation_fail'}}
o
Hi Tom, sorry for the late response - been very busy - but this worked, thanks!