pm.test('GET /items returns 200', function () {
pm.response.to.have.status(200);
});
pm.test('POST /items returns 201 and new item', function () {
pm.response.to.have.status(201);
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('name', 'NewItem');
});
pm.test('PUT /items/1 returns 200 and updated item', function () {
pm.response.to.have.status(200);
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('name', 'UpdatedItem');
});
pm.test('DELETE /items/1 returns 204', function () {
pm.response.to.have.status(204);
});This Postman test script verifies the API intent defined by HTTP methods.
Each pm.test block checks the status code matches the expected one for the HTTP method used.
For POST and PUT, it also checks the response body to confirm the item was created or updated correctly.
DELETE is verified by checking the 204 No Content status code.
Using these tests ensures the API behaves as intended for each HTTP method, reflecting their purpose.