Last active
December 28, 2017 23:27
-
-
Save MelTheTester/fb875b0d461e2a6e3b00501ae490c5ff to your computer and use it in GitHub Desktop.
Postman Bits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a Gist to keep track of little postman/newman code bits for reuse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moment = require('moment') | |
var date = moment(new Date()).day(4,"DD").format("YYYY-MM-DD") | |
postman.setEnvironmentVariable("date", date) | |
pm.variables.get("date"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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