Postman jetpacks - testing embedded data
I have a test in the postman and the response is returned with "nested" data. By that I mean we have a response "data" section and a "messages" section. There are a ton of other fields inside the data and these are the ones I need to validate with Jetpacks. How can I get to these fields?
here is what the json response looks like:
{
"Data": {
"QRCode_ID": 168,
"Repairer_ID": null,
"AssignedToEmployee_ID": null,
"TaskName": "003021919913",
"DueDate": "2015-07-02T00:12:53.597",
"DueDateTimeSpan": 1959471956224,
"TaskStatus_ID": 1,
"Description": "due 6/30, 5:00",
"TaskUrgency_ID": null,
"TaskType_ID": null,
"DueDateDisplay": "2015-07-02 00:12",.......
}
},
"Messages": [
"success"
]
}
And here is my postman test looks like this:
var data = JSON.parse(responseBody);
tests["Verify QRCode_ID is correct"] = data.QRCode_ID === 168;
source to share
You can test nested data in the same way you test data that is not nested (using dot notation)
I created a very quick dummy service that returns the following json:
{
"one": "1",
"two": "2",
"three": {
"four": "4",
"five": "5"
}
}
In the following snippet, I am testing (using dot notation) the values in the nested object. Specifically, I claim that object three has properties four and five, which are set to "4" and "5" respectively:
var data = JSON.parse(responseBody);
tests["4"] = data.three.four === "4";
tests["5"] = data.three.five === "5";
Here's my setup in postman with the corresponding json response:
Here are my test results:
source to share