Validating null or not null value #372
-
Hi Team, I have a scenario where I just need to check value should be present for the particular field I dont want to validate exact value so So, for this scenario do we have any predefine keyword in portman likewise we have for sucess, length or using extend test we need to add this kind of scenarios? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
The Schema validation would be checking if the required fields are present. {
"version": 1.0,
"tests": {
"contractTests": [
{
"openApiOperation": "*::/crm/*",
"schemaValidation": {
"enabled": true
}
}
]
}
} If you want to do specific checks for a field, Portman provides All the options are described here: https://github.com/apideck-libraries/portman#portman---contenttests-properties It seems that for your question, a Portman like this example is what you are looking for: {
"version": 1.0,
"tests": {
"contentTests": [
{
"openApiOperationId": "leadsAll",
"responseBodyTests": [
{
"key": "id"
}
]
}
]
} where the |
Beta Was this translation helpful? Give feedback.
-
@shubhambajad After discussing with another Portman fan, we came to the conclusion that mapping all available Postman assertion would make Portman a bit convoluted and probably more difficult to maintain. The currently supported assertions in Portman are based on the common use-cases for content test. On the other hand Portman focusses on flexibility and extensibility, so we came up with this proposal: The Postman/Newman application is using “Chai assertions” which means this kind of syntax: pm.expect(target)assertion(value) where example: pm.expect(jsonData.company_name).to.eql("Spacex");
pm.expect(jsonData.company_name).to.not.be.null; In Portman, we already have a value setting, which checks the value. {
"key": "name",
"assert": "to.be.null"
} which would result in: pm.expect(jsonData.company_name).to.be.null; where we taken the “raw” An additional positive effect is that we can chain them in 1 config: {
"key": "favourites",
"value": "Greeks love frappé"
"assert": "not.to.be.null"
} which would generate 2 postman checks: pm.expect(jsonData.favourites).to.eql("Greeks love frappé"); plus pm.expect(jsonData.favourites).not.to.be.null; Credits to Stella T. for this excellent proposal. |
Beta Was this translation helpful? Give feedback.
hi @shubhambajad
The Schema validation would be checking if the required fields are present.
If you want to do specific checks for a field, Portman provides
contentTests
.Via content tests, you can target specific endpoints, and do checks like: key
All the options are described here: https://github.com/apideck-libraries/portman#portman---contenttests-properties
Or in the provided example: https://github.com/apideck-libraries/portman/tree/main/examples/testsuite-content-tests
It seems that for your q…