How to verify in postman regardless of the number of results that all of data in the response returns id, firstname, lastname etc
Here is what response look like:
[
{
"id": 1,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 4
},
{
"id": 5,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 8
},
{
"id": 9,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 12
}
]
I want to verify two things:
1) The response returns id, first_name, last_name, email
2) All the first_name is equal to "Sebastian" regardless there is only one result or 100
This is what i tried however, it only works for one result:
const jsonData = pm.response.json();
pm.test('Has data', function() {
pm.expect(jsonData).to.have.property('first_name');
pm.expect(jsonData).to.have.property('last_name');
pm.expect(jsonData).to.have.property('email');
pm.expect(jsonData).to.have.property('id');
});