Skip to content

Instantly share code, notes, and snippets.

@MelTheTester MelTheTester/Postman Bits
Last active Dec 28, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.