Created
August 8, 2022 22:40
-
-
Save lSelectral/40acd602a92dbcf1853434d693cb4776 to your computer and use it in GitHub Desktop.
Advanced Schema validation for Postman Test
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
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