Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc value as dot for entire result #671

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ While the Portman `tests` verify the "contract" of the API, the `contentTests` w

- **responseBodyTests (Array)** : Array of key/value pairs of properties & values in the Postman response body.

- **key (String)** : The key that will be targeted in the response body to check if it exists. To look up a key within in array of objects, you can use an array index (example `data.websites[0].url`) or a * wildcard (example: `data.websites[*].url`) which uses the `value` to match an object in an array.
- **key (String)** : The key that will be targeted in the response body to check if it exists.
- To look up a key within in array of objects, you can use an array index (example `data.websites[0].url`) or a * wildcard (example: `data.websites[*].url`) which uses the `value` to match an object in an array.
- To test a response body that is a single value instead of a JSON object, set this to '.'
- **value (String)** : The value that will be used to check if the value in the response body property matches.
- **contains (String)** : The value that will be used to check if the value is present in the value of the response body property.
- **oneOf (String[],Number[],Boolean[])** : The value that will be used to check one of the values is matching the response body property.
Expand Down
31 changes: 31 additions & 0 deletions examples/testsuite-content-tests/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,37 @@ if (jsonData?.service) {
})};
```

> **REMARK**:
> If you have an API that returns a single value, such as a number or a boolean, instead of a JSON object you can set `value` to `.` to apply the test against the entire result
thim81 marked this conversation as resolved.
Show resolved Hide resolved

`non JSON object response` configuration example:

```json
"responseBodyTests": [
{
"key": ".",
"value": true
}
]
```

`non JSON object response` generated test example:
```js
// Set property value as variable
const _res = jsonData;

// Response body should have "ROOT"
pm.test("[GET]::/return_boolean - Content check if 'ROOT' exists", function() {
pm.expect(_res !== undefined).to.be.true;
});

// Response body should have value "true" for "ROOT"
if (_res !== undefined) {
pm.test("[GET]::/return_boolean - Content check if value for 'ROOT' matches 'true'", function() {
pm.expect(_res).to.eql(true);
})};

```
---

### responseHeaderTests
Expand Down
Loading