or I have to do it in the custom script?
does the Mock Script then apply to all the mock responses? (with expectation and without?)
so a script like:
var requestJsonData = $$.mockRequest.body.toJSON();
var responseJson = $$.mockResponse.json();
responseJson.AccommodationOffersRS.Offers.OfferServices.Accommodation.HotelRef.HotelID = requestJsonData.AccommodationOffersRQ.OfferFilters.AccomFilter.AccomSelectors.HotelIffCodes;
$$.mockResponse.setBody(responseJson);
should set it correctly. but it does not do anything so far…
To utilize advanced matching capabilities, leverage the Mock Custom Scripts feature. Please note that mock script priority is lower than mock expectation priority. The mock service will prioritize returning the mock expectation if the request matches its defined conditions.
I think I understand. will try and get back to you tomorrow. is my script correct?
The script seems to be correct. To further isolate the issue, try setting the response JSON with the intermediate variable or directly with the specific value you are interested in.
so. I think I know what I need.
I need an example JSON, (not a mocked one from a generator, one that I can paste from an JSON example) and then use the mocking script to switch some values I need from the request in the response.
if I do not use expectations, I do always only get the generated mocked values, which is not right by me. how can I achieve this?
thanks
yes.but that one does not work,when expectations are fullfilled. with expectation,I can send a static response,and modify its values with the script. but the script does not trigger,as the expectation matched. if I do not met the expectation, I get the faker generated response…
with that one value modified with the script if it works…
but all the other values are lore ipsum…
that the Expectation Mock ist taken, and the response from this Moc is than modified with the script?
Could you please invite me to your project as a guest so I can view the details? You can send the invitation link via private message on Discord.
I am afraid I can not do that. it is a company project
What I expect is:
- Rule in the Mock Expectation will match and give me the static response I prepared
- Mock script will awake and modify 1 value from the 1) to match the value from the Request
(I am having a meeting in 10 minutes, so I will come back to you later) but you should be able to advice me from this description. or?
If an Advanced Mock expectation is fulfilled, the Custom Mock script will not be executed.