To assert that the array in the response body DOES NOT contain a string value in all its elements

Hi all,
I’m new to writing Postman tests, so I need some help.
I want to add an assertion to confirm that a string value IS NOT present in all the elements in an array.

In the example below, I have an array of 10 elements, I want to check that the “type” value is not equal to “SERVICE”.

I have tried this

let response = pm.response.json();
pm.test('Type is not equal to SERVICE', () => {
    _.each(jsonData.data, (item) => {
        pm.expect(item.type).to.not.include('SERVICE')
    })
})

But I got this error: ReferenceError: jsonData is not defined

Please help.

“status”: “SUCCESS”,
“data”: [
{
“id”: “3029_qEmxmMIf”,
“name”: “Alayna”,
“type”: “SELLING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “619_hNUwxa8V”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671553987000,
“updatedAt”: 1671553987000,
“imagesUrl”: null
},
{
“id”: “3028_PbLmNx6”,
“name”: “Tiara”,
“type”: “PRODUCING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “618_3uEB2q”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671553987000,
“updatedAt”: 1671553987000,
“imagesUrl”: null
},
{
“id”: “3027_POuYVZa”,
“name”: “Ramon”,
“type”: “PRODUCING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “619_hNUwxa8V”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671553986000,
“updatedAt”: 1671553986000,
“imagesUrl”: null
},
{
“id”: “3024_EZ2jID”,
“name”: “Efe New Product dacw”,
“type”: “PRODUCING”,
“costPrice”: 2000.00,
“sellingPrice”: 2000.00,
“categoryId”: “640_4FqUgIL5”,
“businessCurrencyId”: “277_NTe4Z2HV4”,
“createdAt”: 1671553984000,
“updatedAt”: 1671553984000,
“imagesUrl”: null
},
{
“id”: “3023_ppovsAj”,
“name”: “Sheridan”,
“type”: “SELLING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “619_hNUwxa8V”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671553601000,
“updatedAt”: 1671553601000,
“imagesUrl”: null
},
{
“id”: “3020_ndGs9c72”,
“name”: “Edgar”,
“type”: “SELLING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “619_hNUwxa8V”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671553600000,
“updatedAt”: 1671553600000,
“imagesUrl”: null
},
{
“id”: “3019_2HrDq7IVZ”,
“name”: “Elissa”,
“type”: “PRODUCING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “618_3uEB2q”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671553599000,
“updatedAt”: 1671553599000,
“imagesUrl”: null
},
{
“id”: “3018_Q4O77QF”,
“name”: “Gabrielle”,
“type”: “PRODUCING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “619_hNUwxa8V”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671553599000,
“updatedAt”: 1671553599000,
“imagesUrl”: null
},
{
“id”: “3015_eav8zfQz”,
“name”: “Efe New Product lose”,
“type”: “PRODUCING”,
“costPrice”: 2000.00,
“sellingPrice”: 2000.00,
“categoryId”: “640_4FqUgIL5”,
“businessCurrencyId”: “277_NTe4Z2HV4”,
“createdAt”: 1671553596000,
“updatedAt”: 1671553596000,
“imagesUrl”: null
},
{
“id”: “3014_nlex24WLd”,
“name”: “Toby”,
“type”: “SELLING”,
“costPrice”: 80.00,
“sellingPrice”: 20.00,
“categoryId”: “619_hNUwxa8V”,
“businessCurrencyId”: “225_fidjsm6”,
“createdAt”: 1671552560000,
“updatedAt”: 1671552560000,
“imagesUrl”: null
}
]

The error is correct.

let response = pm.response.json();

So it should be (response.data), not (jsonData.data).

If you just want to check that “SERVICE” does not exist. As data is an array, you could just do a search (JavaScript find).

Something like.

response = pm.response.json()

pm.test('Type is not equal to SERVICE', () => {
    let search = (response.data.find(obj => {return obj.type === 'SERVICE'}));
    pm.expect(search).to.eql(undefined);
})

Awesome!
Works fine.
Thanks a lot for the clarity @mdjones