diff --git a/docs/zzapi-bundle-description.md b/docs/zzapi-bundle-description.md index 2592190..31c1bad 100644 --- a/docs/zzapi-bundle-description.md +++ b/docs/zzapi-bundle-description.md @@ -166,13 +166,14 @@ Note that an assertion value can be a non-scalar, especially when matching a non Operators supported in the RHS are: * `$eq`, `$ne`, `$lt`, `$gt`, `$lte`, `$gte`: against the value -* `$regex`: against the value, with `$options` like ignore-case +* `$regex`: against the value, with `options` like ignore-case * `$sw`, `$ew`, `$co`: to check if the target starts with, ends with or contains a string * `$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 -* `$skip`: skip the assertions under this test. Useful in case some tests are failing, but we want the output to keep reminding us of this fact. +* `skip`: skip the assertions under this test. Useful in case some tests are failing, but we want the output to keep reminding us of this fact. +* `multi`: use `jasonpath.query` (all matches) instead of `jasonpath.value` (first match) to evaluate the JSONPath expresson. This is useful if you need to evaluate multiple nested elements of an object array all at once. ### jsonpath tests diff --git a/schemas/zzapi-bundle.schema.json b/schemas/zzapi-bundle.schema.json index e3a562d..ea5e8ee 100644 --- a/schemas/zzapi-bundle.schema.json +++ b/schemas/zzapi-bundle.schema.json @@ -112,7 +112,6 @@ "enum": ["number", "string", "boolean", "object", "array", "null", "undefined"] }, "$regex": { "type": "string" }, - "$options": { "type": "string" }, "$exists": { "type": "boolean" }, "$size": { "anyOf": [ @@ -132,7 +131,9 @@ ] }, "$tests": { "$ref": "#/$defs/tests" }, - "$skip": { "type": "boolean" } + "options": { "type": "string" }, + "skip": { "type": "boolean" }, + "multi": { "type": "boolean" } } } ] diff --git a/src/runTests.ts b/src/runTests.ts index 4367bcf..59704c9 100644 --- a/src/runTests.ts +++ b/src/runTests.ts @@ -5,8 +5,8 @@ import { getStringIfNotScalar, isDict } from "./utils/typeUtils"; import { Tests, ResponseData, Assertion, SpecResult, TestResult } from "./models"; import { mergePrefixBasedTests } from "./mergeData"; -const SKIP_CLAUSE = "$skip", - OPTIONS_CLAUSE = "$options", +const SKIP_CLAUSE = "skip", + OPTIONS_CLAUSE = "options", MULTI_CLAUSE = "multi"; function hasFailure(res: SpecResult): boolean { diff --git a/tests/bundles/auto-tests.zzb b/tests/bundles/auto-tests.zzb index 8ed4365..dc7f2c0 100644 --- a/tests/bundles/auto-tests.zzb +++ b/tests/bundles/auto-tests.zzb @@ -42,12 +42,12 @@ requests: params: foo1: bar1 foo2: bar2 - tests: # old way of specifying json tests - status: { $eq: 0, $skip: true } - $h.Content-type: { $eq: random-test, $skip: true } + tests: + status: { $eq: 0, skip: true } + $h.Content-type: { $eq: random-test, skip: true } json: $.args: - $skip: true + skip: true $tests: $.foo1: bar2 $.foo2: bar1 @@ -58,7 +58,7 @@ requests: params: foo1: bar1 foo2: - tests: # new way of specifying json + tests: $.url: "https://postman-echo.com/get?foo1=bar1&foo2" get-with-params-as-array-positive: @@ -255,8 +255,9 @@ requests: $.data.phoneNumbers[0].type: mobile $.data.phoneNumbers.1.type: home $.data.phoneNumbers[?(@.type=="home")].number: 0123-4567-8910 - $.data.phoneNumbers[*].type: mobile - $.data.phoneNumbers[*].available: { $eq: [7, 22] } + $.data.phoneNumbers[*].number: 0123-4567-8888 # without multi option, it compares only the first + $.data.phoneNumbers[*].available: { $eq: [7, 22] } # without multi option, it compares only the first + $.data.phoneNumbers[*].type: { $eq: ["mobile", "home"], multi: true } $.data.phoneNumbers.0.available: { $eq: [7, 22], $type: array } $.data.phoneNumbers.1.available: { $eq: "[18,22]", $type: array } $.data.phoneNumbers.0: @@ -310,11 +311,10 @@ requests: status: { $ne: 200 } headers: content-type: { $exists: false } - # Uncomment the following to run tests. Schema validation makes these invalid. - # $.data.operator: { badop: any } # invalid operator badop. If you want to match an entire object/array, use it as the value of the $eq operator. - # $.data.numbers: [444, 222] - # $.data.address: { $type: invalid } - # $.data.object: { $exists: 4 } + $.data.operator: { badop: any } # invalid operator badop. If you want to match an entire object/array, use it as the value of the $eq operator. + $.data.numbers: [444, 222] + $.data.address: { $type: invalid } + $.data.object: { $exists: 4 } capture-response-positive: method: POST