Complete the code to assert the status code is 200.
pm.test('Status code is 200', function () { pm.response.to.have.status([1]); });
The status code 200 means the request was successful. We use pm.response.to.have.status(200) to check this.
Complete the code to assert the response JSON has a nested property 'user.name'.
pm.test('Response has user name', function () { pm.expect(pm.response.json()).to.have.nested.property([1]); });
To check nested properties in Postman, use dot notation as a string inside nested.property. Here, 'user.name' checks the 'name' inside 'user'.
Fix the error in the assertion to check that 'data.items[0].id' equals 123.
pm.test('First item id is 123', function () { pm.expect(pm.response.json()).to.have.nested.property('data.items[0].id', [1]); });
The expected value should be a number 123, not a string. So use 123 without quotes.
Fill both blanks to assert the nested property 'profile.address.city' equals 'New York'.
pm.test('City is New York', function () { pm.expect(pm.response.json()).to.have.nested.property([1], [2]); });
Use the full nested property path as a string for the first blank, and the expected string value 'New York' for the second blank.
Fill all three blanks to assert the nested property 'order.items[1].price' is greater than 20.
pm.test('Second item price check', function () { pm.expect(pm.response.json()).to.have.nested.property([1]); pm.expect(pm.response.json().order.items[1].price).to.be.[2]([3]); });
First blank is the nested property path as a string. Second blank is the assertion method above to check greater than. Third blank is the number 20.