Skip to content

Instantly share code, notes, and snippets.

@MelTheTester
Last active December 28, 2017 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MelTheTester/fb875b0d461e2a6e3b00501ae490c5ff to your computer and use it in GitHub Desktop.
Save MelTheTester/fb875b0d461e2a6e3b00501ae490c5ff to your computer and use it in GitHub Desktop.
Postman Bits
This is a Gist to keep track of little postman/newman code bits for reuse
var moment = require('moment')
var date = moment(new Date()).day(4,"DD").format("YYYY-MM-DD")
postman.setEnvironmentVariable("date", date)
pm.variables.get("date");
var jsonData = JSON.parse(responseBody);
if(jsonData.length === 0 ) {
pm.environment.unset("timeSlot");
pm.test.skip('No Time Slots Are Available', () => {
pm.expect(jsonData[0].dateTime).to.be.a('string');
});
}
else {
pm.test('Check the time value', () => {
pm.expect(jsonData[0].dateTime).to.be.a('string');
pm.environment.set("timeSlot", jsonData[0].dateTime);
});
//Expected Response Time
pm.test("Response time is less than 400ms", function () {
pm.expect(pm.response.responseTime).to.be.below(400);
});
//Expect Status
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// No errors in JSON body
pm.test("No errors in JSON Body", function() {
pm.response.to.not.have.jsonBody("error");
});
pm.environment.unset("date");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment