Created
June 3, 2025 12:51
-
-
Save solanoize/4895f7e832177d9fee2302782ef13959 to your computer and use it in GitHub Desktop.
Script pengujian postman
This file contains hidden or 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
pm.test("Response status code must be 200", function () { | |
pm.response.to.have.status(200); | |
}); | |
pm.test("Response time is less than 1.5 seconds", function () { | |
pm.expect(pm.response.responseTime).to.be.below(1500); | |
}); | |
pm.test("Response must be object", () => { | |
const responseData = pm.response.json(); | |
const { results, count, next, previous } = responseData; | |
pm.expect(responseData).to.be.an('object'); | |
pm.expect(results).to.be.an('array'); | |
pm.expect(count).to.be.a('number'); | |
if (count === 0) { | |
pm.expect(next).to.be.null; | |
pm.expect(previous).to.be.null; | |
} else if (count > 10 && count < 20) { | |
pm.expect(next).to.be.a('string'); | |
pm.expect(previous).to.be.null; | |
} else if (count > 20) { | |
pm.expect(previous).to.be.a('string'); | |
pm.expect(next).to.be.a('string'); | |
} | |
}); | |
pm.test("Response pagination test", () => { | |
const responseData = pm.response.json(); | |
const { results, count, next, previous } = responseData; | |
pm.expect(responseData).to.be.an('object'); | |
pm.expect(results).to.be.an('array'); | |
pm.expect(count).to.be.a('number'); | |
if (count === 0) { | |
pm.expect(next).to.be.null; | |
pm.expect(previous).to.be.null; | |
} else if (count > 10 && count < 20) { | |
pm.expect(next).to.be.a('string'); | |
pm.expect(previous).to.be.null; | |
} else if (count > 20) { | |
pm.expect(previous).to.be.a('string'); | |
pm.expect(next).to.be.a('string'); | |
} | |
}); | |
// pm.test("Response must be have token string", () => { | |
// const responseData = pm.response.json(); | |
// pm.expect(responseData).to.have.property('token').that.is.a('string'); | |
// }) | |
// pm.test("Response must be have header content-type is application/json", () => { | |
// pm.expect(pm.response.headers.get('Content-Type')).to.be.equal("application/json"); | |
// }); | |
// pm.test("Validate the response schema for 'products' endpoint", function () { | |
// const responseData = pm.response.json(); | |
// console.log(responseData.token.split(".").length); | |
// pm.expect(3, "Error bro").equal(responseData.token.split(".").length); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment