Skip to content

Commit d19a2e2

Browse files
author
Andrey Pshenkin
committed
add readme
1 parent e649572 commit d19a2e2

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const request = require('then-request');
32
const urljoin = require('url-join');
43
const { cropLongData } = require('@kronoslive/codeceptjs-utils');
@@ -131,7 +130,8 @@ class HTTP extends Helper {
131130
/**
132131
* Validate that latest https response has specified JSON schema.
133132
* @param {string} schema - path to JSON schema file. is relative to schemas folder
134-
* @param {*} params
133+
* @param {*} params - (optional) if schema file is js file, that export function, then you can specify here params in array,
134+
* that will be applied to this function. Function should return JSON schema.
135135
* @param {*} data - (optional) - specify data that should be validated (by default first response message for latest
136136
* request)
137137
* @returns {*}
@@ -141,6 +141,9 @@ class HTTP extends Helper {
141141
* ```
142142
*/
143143
seeHttpResponseHasValidJsonSchema(schema, params, data) {
144+
if (utils === undefined) {
145+
throw new Error('To use JSON schema validation please add codeceptjs-utils-helper https://www.npmjs.com/package/@kronoslive/codeceptjs-utils-helper');
146+
}
144147
data = data || this.currentResponse.body;
145148
return utils.seeDataHasValidJsonSchema(schema, params, data);
146149
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeceptjs-http",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "CodeceptJS helper for HTTP request with Mochawesome logging",
55
"dependencies": {
66
"@kronoslive/codeceptjs-utils": "^0.0.1",
@@ -19,7 +19,7 @@
1919
},
2020
"repository": {
2121
"type": "git",
22-
"url": "git@github.com:APshenkin/codeceptjs-http.git"
22+
"url": "git@github.com:testphony/codeceptjs-http.git"
2323
},
2424
"author": "Andrey Pshenkin <andrey.pshenkin@gmail.com>",
2525
"license": "MIT"

readme.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# codeceptjs-http
2+
3+
codeceptjs-http is [CodeceptJS](https://codecept.io/) helper which wraps [then-request](https://www.npmjs.com/package/then-request) library to
4+
process HTTP requests. It's alternative helper that provides more flexible request management.
5+
6+
NPM package: https://www.npmjs.com/package/codeceptjs-http
7+
8+
### Configuration
9+
10+
This helper should be configured in codecept.json/codecept.conf.js
11+
12+
- `endpoint`: base HTTP url.
13+
14+
Example:
15+
16+
```json
17+
{
18+
"helpers": {
19+
"HTTP" : {
20+
"require": "codeceptjs-http",
21+
"endpoint": "http://localhost:8080"
22+
}
23+
}
24+
}
25+
```
26+
27+
## sendRequest
28+
29+
Send HTTP request, response will be availible as return value and in this.currentResponse.
30+
31+
```js
32+
I.sendRequest(('/callback', 'POST', {
33+
headers: {
34+
'Content-Type': 'application/json',
35+
},
36+
json: {
37+
myParam: 123
38+
},
39+
})); // will use base endpoint
40+
I.sendRequest('https://logalhost:8080/getOrders', 'GET'); // will use url from 1st argument
41+
```
42+
43+
**Parameters**
44+
45+
- `requestPath` - endpoint path. Can be relative or absolute
46+
- `method` - (optional) request method. Default 'GET'
47+
- `options` - (optional) headers, body, etc. see https://www.npmjs.com/package/then-request
48+
- `domain` - (optional) change domain for request
49+
50+
## seeHttpResponseHasValidJsonSchema
51+
52+
Validate that latest https response has specified JSON schema.
53+
54+
```js
55+
I.seeHttpResponseHasValidJsonSchema('api/getOrders.json');
56+
I.seeHttpResponseHasValidJsonSchema('filters/values.js', ['param1', 'param2']);
57+
```
58+
59+
**Parameters**
60+
61+
- `schema` - path to JSON schema file. is relative to schemas folder. schemas folder will be in codeceptJS root folder (path.join(global.codecept_dir, './schemas/'))
62+
- `params` - (optional) if schema file is js file, that export function, then you can specify here params in array, that will be applied to this function. Function should return JSON schema.
63+
- `data` - (optional) specify data that should be validated. By default first response message for latest request
64+

0 commit comments

Comments
 (0)