Good morning, I tried to find in the chat for a so...
# help
c
Good morning, I tried to find in the chat for a solution for my problem but I didn’t find anything, so I will write it then 🙂 I am sending a POST call to wiremock with a body and I would like to know if there is a way to get some of the data from the body and return it in the response of the Stub. Thanks a lot!
s
hi, can you plz explain why do you need this? usually i use the stub to make sure that the post was generated with correct payload,
c
Hi, I have a use case where I call an Endpoint to update the User data with a new Email. The Endpoint, after updating the user data, returns the new UserData object. But, as the Response of the Stub is hardcoded, the new UserData Object contains the “old” data.
The thing is that we have some Appium tests and we configured to go through Wiremock or to real Backend using a variable
This test checks that a field of the user data in the screen is updated
But when the mock response comes from wiremock, the test fails, because the data that we show is “old” data, not the updated data
Then we thought to tell wiremock to answer, in our case, the new email that we are sending in the POST call to update the user
t
You can use response templating to extract data from the request and use it in the response. What data format is the request body you are sending?
c
its a json. I have to say that I use Wiremock configurator, so I make everything through the Console
d
"jsonBody": {
"id": "{{randomValue length=32 type='ALPHANUMERIC' uppercase=false}}",
"firstKey": "{{jsonPath request.body '$.firstKey'}}",
"createdAt": "{{now}}",
"updatedAt": "{{now}}"
}
If you want a complete object, you need to use
body
:
"response": {
"body": "{"firstObject": {{{jsonPath request.body '$.firstObject'}}}}"
}
c
Do I have to put that somewhere here?
d
haven't used it, but I would tick the
enable templating
. Then probably somewhere in the response part.
haven't used that one though - I use plain Java or JSON files