Skip to content

Commit

Permalink
back to $skip, $options, $multi
Browse files Browse the repository at this point in the history
  • Loading branch information
vasan-agrostar committed Jun 30, 2024
1 parent 8a14862 commit 0fa5d50
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions docs/zzapi-bundle-description.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +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.
* `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.
* `$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

Expand Down
10 changes: 5 additions & 5 deletions examples/tests-bundle.zzb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ requests:
params:
foo1: bar1
foo2: bar2
tests: # old way of specifying json tests
tests:
json:
$.args.foo1: bar1
$.args.foo2: bar2
Expand All @@ -44,7 +44,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:
Expand All @@ -68,7 +68,7 @@ requests:
- multi-2
tests:
$.args.foo1: bar
$.args.foo2: { $eq: ["multi-1", "multi-2"], skip: true }
$.args.foo2: { $eq: ["multi-1", "multi-2"], $skip: true }

post-header-merge:
url: /post
Expand Down Expand Up @@ -144,7 +144,7 @@ requests:
method: GET
url: /encoding/utf8
tests:
body: { $regex: unicode demo, options: i }
body: { $regex: unicode demo, $options: i }
headers:
content-type: text/html; charset=utf-8

Expand Down Expand Up @@ -246,7 +246,7 @@ requests:
$.data.phoneNumbers.0.available: { $eq: [7, 22], $type: array }
$.data.phoneNumbers.1.available: { $eq: "[18,22]", $type: array }
$.data.phoneNumbers.0:
skip: true
$skip: true
$tests:
$.type: mobile
$.number: { $ne: 0123-4567-8910 }
Expand Down
6 changes: 3 additions & 3 deletions schemas/zzapi-bundle.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@
]
},
"$tests": { "$ref": "#/$defs/tests" },
"options": { "type": "string" },
"skip": { "type": "boolean" },
"multi": { "type": "boolean" }
"$options": { "type": "string" },
"$skip": { "type": "boolean" },
"$multi": { "type": "boolean" }
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions src/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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",
MULTI_CLAUSE = "multi";
const SKIP_CLAUSE = "$skip",
OPTIONS_CLAUSE = "$options",
MULTI_CLAUSE = "$multi";

function hasFailure(res: SpecResult): boolean {
return res.results.some((r) => !r.pass) || res.subResults.some(hasFailure);
Expand Down
10 changes: 5 additions & 5 deletions tests/bundles/auto-tests.zzb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ requests:
foo1: bar1
foo2: bar2
tests:
status: { $eq: 0, skip: true }
$h.Content-type: { $eq: random-test, skip: true }
status: { $eq: 0, $skip: true }
$h.Content-type: { $eq: random-test, $skip: true }
json:
$.args:
skip: true
$skip: true
$tests:
$.foo1: bar2
$.foo2: bar1
Expand Down Expand Up @@ -158,7 +158,7 @@ requests:
method: GET
url: /encoding/utf8
tests:
body: { $regex: unicode demo, options: i }
body: { $regex: unicode demo, $options: i }
headers:
content-type: text/html; charset=utf-8

Expand Down Expand Up @@ -257,7 +257,7 @@ requests:
$.data.phoneNumbers[?(@.type=="home")].number: 0123-4567-8910
$.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[*].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:
Expand Down

0 comments on commit 0fa5d50

Please sign in to comment.