Skip to content

Commit

Permalink
schema changes (skip and multi), tests for multi
Browse files Browse the repository at this point in the history
  • Loading branch information
vasan-agrostar committed Jun 29, 2024
1 parent 2142a3d commit 972ac76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
5 changes: 3 additions & 2 deletions docs/zzapi-bundle-description.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions schemas/zzapi-bundle.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"enum": ["number", "string", "boolean", "object", "array", "null", "undefined"]
},
"$regex": { "type": "string" },
"$options": { "type": "string" },
"$exists": { "type": "boolean" },
"$size": {
"anyOf": [
Expand All @@ -132,7 +131,9 @@
]
},
"$tests": { "$ref": "#/$defs/tests" },
"$skip": { "type": "boolean" }
"options": { "type": "string" },
"skip": { "type": "boolean" },
"multi": { "type": "boolean" }
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions src/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions tests/bundles/auto-tests.zzb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 972ac76

Please sign in to comment.