https://linen.dev logo
#help
Title
# help
c

Carlos Roig

06/22/2023, 7:50 AM
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

Shlomy Sheps

06/22/2023, 8:05 AM
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

Carlos Roig

06/22/2023, 8:16 AM
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

Tom

06/22/2023, 8:27 AM
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

Carlos Roig

06/22/2023, 8:27 AM
its a json. I have to say that I use Wiremock configurator, so I make everything through the Console
d

Dirk Bolte

06/22/2023, 8:28 AM
"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

Carlos Roig

06/22/2023, 8:29 AM
Do I have to put that somewhere here?
d

Dirk Bolte

06/22/2023, 8:30 AM
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
2 Views