Here is a sample of the tested response:
[
{
"label": "Summer '14",
"url": "/services/data/v31.0",
"version": "31.0"
},
{
"label": "Winter '15",
"url": "/services/data/v32.0",
"version": "32.0"
},
{
"label": "Spring '15",
"url": "/services/data/v33.0",
"version": "33.0"
}
]
I am testing to ensure that each URL in the response matches the expected format: "/services/data/v"
followed by the version number specified in the corresponding version key.
The script I have written checks this condition for each item in the response:
pm.test("URL formatted correctly and version matches version key", function () {
const response = pm.response.json();
response.forEach(item => {
// Extract version from the URL
const urlPattern = /^\/services\/data\/v(\d{2}\.\d)$/;
const match = item.url.match(urlPattern);
// Verify the URL follows the expected format
pm.expect(match).to.not.be.null; // Ensure the URL matches the pattern
// Extract the version from the URL if the pattern matched
const urlVersion = match ? match[1] : null;
// Verify the extracted version matches the version key
pm.expect(urlVersion).to.eql(item.version);
});
});
I would appreciate feedback from experienced individuals in Postman testing or JavaScript to confirm if this script functions as intended based on the described requirements.