Test Overview
This test checks if the API correctly handles requests for different versions. It verifies that the response matches the requested API version and returns the expected data format.
This test checks if the API correctly handles requests for different versions. It verifies that the response matches the requested API version and returns the expected data format.
pm.test("API version 1 returns correct response", function () { pm.sendRequest({ url: pm.environment.get("baseUrl") + "/api/v1/resource", method: 'GET' }, function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('status', 200); pm.expect(res.json()).to.have.property('version', '1'); pm.expect(res.json()).to.have.property('data'); }); }); pm.test("API version 2 returns correct response", function () { pm.sendRequest({ url: pm.environment.get("baseUrl") + "/api/v2/resource", method: 'GET' }, function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('status', 200); pm.expect(res.json()).to.have.property('version', '2'); pm.expect(res.json()).to.have.property('data'); pm.expect(res.json().data).to.have.property('newField'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send GET request to /api/v1/resource | API server is running and accessible | Response status code is 200 and version field is '1' | PASS |
| 2 | Check response body for version '1' and presence of data field | Response JSON contains version and data fields | version == '1' and data field exists | PASS |
| 3 | Send GET request to /api/v2/resource | API server is running and accessible | Response status code is 200 and version field is '2' | PASS |
| 4 | Check response body for version '2', data field, and newField inside data | Response JSON contains version, data, and newField fields | version == '2' and data.newField exists | PASS |