Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lSelectral/40acd602a92dbcf1853434d693cb4776 to your computer and use it in GitHub Desktop.
Save lSelectral/40acd602a92dbcf1853434d693cb4776 to your computer and use it in GitHub Desktop.
Advanced Schema validation for Postman Test
const expectedResponseSchema = {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"rows": {
"type": "array",
"items": [{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"context": {
"type": "string"
},
"creator_id": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "number"
},
"answer": {
"type": "string"
},
"isPrivate": {
"type": "boolean"
},
"isDeleted": {
"type": "boolean"
},
"createdAt": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
}]
}
},
"required": [
"count",
"rows"
]
}
pm.test('Should get 200 status code on Sucess', () => {
pm.response.to.have.status(200);
pm.response.to.be.ok;
pm.response.to.be.json;
})
pm.test('Should have valid response json schema', () => {
pm.response.to.have.jsonSchema(expectedResponseSchema)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment