Skip to content

Commit

Permalink
v1.2.0: $sw etc, $size comparisons, stop-on-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
vasan-agrostar committed May 12, 2024
1 parent 99137c7 commit 46d50df
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [1.2.0]
- Support `$sw`, `$ew`, `$co` for startsWith, endsWith and contains
- Support for `$size` comparisons with `$lt`, `$gt` etc
- Run status test first and option for stopping on failure

## [1.1.1]
- Fixed unnecessary ? after parameter-less URLs

Expand Down
16 changes: 4 additions & 12 deletions docs/zzapi-bundle-description.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ These are options that can be switches on/off, both at the common level as well
* `verifySSL`: whether to enfoce SSL certificate validation (default is false)
* `showHeaders`: whether to show the response headers for each request (default is false)
* `keepRawJSON`: whether to keep the original response JSON without formatting it. (default is false)
* `stopOnFailure`: whether to skip other tests when any of the status tests fail.

### headers

Expand Down Expand Up @@ -166,7 +167,7 @@ Operators supported in the RHS are:
* `$eq`, `$ne`, `$lt`, `$gt`, `$lte`, `$gte`: against the value
* `$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
* `$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

Expand All @@ -184,18 +185,9 @@ Object | Path | Result

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)`.

### capture
### 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.

### capture.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.

Similar to tests, the key is a JSONPATH specification of the path of the field. The value is a string, the name of the variable to which the value will be set to. Eg:

* `address.city: citiyVar`

### capture.headers

Similar to tests, each header is a key-value pair where the key is the name of the header and the value is the variable to capture the value into.

* `Content-type: contentTypeVar`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zzapi",
"version": "1.1.1",
"version": "1.2.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",
Expand Down
25 changes: 24 additions & 1 deletion schemas/zzapi-bundle.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
"verifySSL": {
"description": "If set, will verify the SSL certificate (default: false)",
"type": "boolean"
},
"stopOnFailure": {
"description": "If set, will stop testing on the first failure",
"type": "boolean"
}
}
},
Expand All @@ -100,14 +104,33 @@
"$gt": { "$ref": "#/$defs/scalar" },
"$lte": { "$ref": "#/$defs/scalar" },
"$gte": { "$ref": "#/$defs/scalar" },
"$sw": { "$ref": "#/$defs/scalar" },
"$ew": { "$ref": "#/$defs/scalar" },
"$co": { "$ref": "#/$defs/scalar" },
"$type": {
"type": "string",
"enum": ["number", "string", "boolean", "object", "array", "null", "undefined"]
},
"$regex": { "type": "string" },
"$options": { "type": "string" },
"$exists": { "type": "boolean" },
"$size": { "type": "integer" }
"$size": {
"anyOf": [
{ "type": "integer" },
{
"type": "object",
"additionalProperties": false,
"properties": {
"$eq": { "description": "Equals" },
"$ne": { "$ref": "#/$defs/scalar" },
"$lt": { "$ref": "#/$defs/scalar" },
"$gt": { "$ref": "#/$defs/scalar" },
"$lte": { "$ref": "#/$defs/scalar" },
"$gte": { "$ref": "#/$defs/scalar" }
}
}
]
}
}
}
]
Expand Down

0 comments on commit 46d50df

Please sign in to comment.