diff --git a/CHANGELOG.md b/CHANGELOG.md index 461a247..2af8787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Change Log -## [1.2.0] -- Bug fix: stopOnFailue not working +## 1.3.0 +- Support for `$tests` to recursively run tests on a sub-object + +## [1.2.1] +- Bug fix: stopOnFailure not working ## [1.2.0] - Support `$sw`, `$ew`, `$co` for startsWith, endsWith and contains diff --git a/docs/zzapi-bundle-description.md b/docs/zzapi-bundle-description.md index 9a356f6..7b98808 100644 --- a/docs/zzapi-bundle-description.md +++ b/docs/zzapi-bundle-description.md @@ -170,6 +170,7 @@ Operators supported in the RHS are: * `$size`: for length of arrays and objects, or the length of the string if it is not an array. The value can be an object for `$ne`, `$lt` etc. comparisons. * `$exists`: true|false, to check existance of a field * `$type`: string|number|object|array|null: to check the type of the field +* `$tests`: perform assertions (recursively) on the value, as if it were the `$.` root ### jsonpath tests @@ -183,11 +184,10 @@ Object | Path | Result `{ field: [ { value: 10 }, { value: 20 } ]}` | `$.field.1.value` | 20 `{ field: [ { name: x, value: 10 }, { name: y, value: 20 } ]}` | `$.field[?(@.name=="x")].value` | 10 -If the result is a non-scalar (eg, the entire array) it will be used as is when matching against the operators `$size`, `$exists` and `$type`, otherwise will be converted to a string using `JSON.stringify(value)`. +If the result is a non-scalar (eg, the entire array) it will be used as is when matching against the operators `$tests`, `$size`, `$exists` and `$type`, otherwise will be converted to a string using `JSON.stringify(value)`. ### setvars Values from the response (headers and JSON body) can be captured and set as variables. We allow variables which are not scalars also (eg, objects and arrays), when capturing values from the response JSON. `setvars` is an object with many ke-value pairs, where the key is the name of the variable to set and the value is similar to tests: one of status, entire body, a JSONPATH spec or a header spec. - diff --git a/examples/tests-bundle.zzb b/examples/tests-bundle.zzb index 46e5129..c8a1b21 100644 --- a/examples/tests-bundle.zzb +++ b/examples/tests-bundle.zzb @@ -1,7 +1,8 @@ # yaml-language-server: $schema=../schemas/zzapi-bundle.schema.json + # This bundle contains a series of test requests against various endpoints, # most of them being the postman echo service. We use this to both serve as -# an example of how to create test bundles as well as testing zzapi runner itself. +# an example of how to create test bundles as well as testing zzapi itself. common: baseUrl: https://postman-echo.com @@ -240,14 +241,19 @@ requests: $.data.phoneNumbers[0].type: mobile $.data.phoneNumbers.1.type: home $.data.phoneNumbers[?(@.type=="home")].number: 0123-4567-8910 - $.data.lastName: { $exists: true } - # $.data.middleName: { $exists: true, $type: "null" } - $.data.middleName: null - $.data.otherName: { $exists: false, $type: undefined } $.data.phoneNumbers[*].type: mobile $.data.phoneNumbers[*].available: { $eq: [7, 22] } $.data.phoneNumbers.0.available: { $eq: [7, 22], $type: array } $.data.phoneNumbers.1.available: { $eq: "[18,22]", $type: array } + $.data.phoneNumbers.0: + $tests: + $.type: mobiles + $.number: { $ne: 0123-4567-8910 } + $.available: { $eq: [7, 22] } + $.data.lastName: { $exists: true } + # $.data.middleName: { $exists: true, $type: "null" } + $.data.middleName: null + $.data.otherName: { $exists: false, $type: undefined } # stress: ensure corner cases don't crash $.data.otherName.value: { $exists: false } # don't recurse down undefined $.data.middleName.value: { $exists: false } # don't recurse down null diff --git a/package.json b/package.json index 15b3c08..820368a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zzapi", - "version": "1.2.1", + "version": "1.3.0", "description": "zzAPI is a REST API testing and documentation tool set. It is an open-source Postman alternative. ", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/schemas/zzapi-bundle.schema.json b/schemas/zzapi-bundle.schema.json index cfe8936..82fc8af 100644 --- a/schemas/zzapi-bundle.schema.json +++ b/schemas/zzapi-bundle.schema.json @@ -130,7 +130,8 @@ } } ] - } + }, + "$tests": { "$ref": "#/$defs/tests" } } } ]