UNPKG

@kronoslive/codeceptjs

Version:

Supercharged End 2 End Testing Framework for NodeJS

157 lines (101 loc) 3.15 kB
--- permalink: /helpers/REST editLink: false sidebar: auto title: REST --- <!-- Generated by documentation.js. Update this documentation by updating the source code. --> ## REST **Extends Helper** REST helper allows to send additional requests to the REST API during acceptance tests. [Axios][1] library is used to perform requests. ## Configuration - endpoint: API base URL - timeout: timeout for requests in milliseconds. 10000ms by default - defaultHeaders: a list of default headers - onRequest: a async function which can update request object. - maxUploadFileSize: set the max content file size in MB when performing api calls. ## Example ```js { helpers: { REST: { endpoint: 'http://site.com/api', onRequest: (request) => { request.headers.auth = '123'; } } } ``` ## Access From Helpers Send REST requests by accessing `_executeRequest` method: ```js this.helpers['REST']._executeRequest({ url, data, }); ``` ## Methods ### Parameters - `config` ### _executeRequest Executes axios request #### Parameters - `request` **any** ### _url Generates url based on format sent (takes endpoint + url if latter lacks 'http') #### Parameters - `url` **any** ### sendDeleteRequest Sends DELETE request to API. ```js I.sendDeleteRequest('/api/users/1'); ``` #### Parameters - `url` **any** - `headers` **[object][2]** the headers object to be sent. By default it is sent as an empty object ### sendGetRequest Send GET request to REST API ```js I.sendGetRequest('/api/users.json'); ``` #### Parameters - `url` **any** - `headers` **[object][2]** the headers object to be sent. By default it is sent as an empty object ### sendPatchRequest Sends PATCH request to API. ```js I.sendPatchRequest('/api/users.json', { "email": "user@user.com" }); ``` #### Parameters - `url` **[string][3]** - `payload` **any** the payload to be sent. By default it is sent as an empty object - `headers` **[object][2]** the headers object to be sent. By default it is sent as an empty object ### sendPostRequest Sends POST request to API. ```js I.sendPostRequest('/api/users.json', { "email": "user@user.com" }); ``` #### Parameters - `url` **any** - `payload` **any** the payload to be sent. By default it is sent as an empty object - `headers` **[object][2]** the headers object to be sent. By default it is sent as an empty object ### sendPutRequest Sends PUT request to API. ```js I.sendPutRequest('/api/users.json', { "email": "user@user.com" }); ``` #### Parameters - `url` **[string][3]** - `payload` **any** the payload to be sent. By default it is sent as an empty object - `headers` **[object][2]** the headers object to be sent. By default it is sent as an empty object ### setRequestTimeout Set timeout for the request ```js I.setRequestTimeout(10000); // In milliseconds ``` #### Parameters - `newTimeout` [1]: https://github.com/axios/axios [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String