Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
120 changes: 61 additions & 59 deletions docs/helpers/REST.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,21 @@ title: REST
REST helper allows to send additional requests to the REST API during acceptance tests.
[Axios][1] library is used to perform requests.



## Configuration

Type: [object][4]

### Properties

* `endpoint` **[string][3]?** API base URL
* `prettyPrintJson` **[boolean][6]?** pretty print json for response/request on console logs.
* `printCurl` **[boolean][6]?** print cURL request on console logs. False by default.
* `timeout` **[number][5]?** timeout for requests in milliseconds. 10000ms by default.
* `defaultHeaders` **[object][4]?** a list of default headers.
* `httpAgent` **[object][4]?** create an agent with SSL certificate
* `onRequest` **[function][7]?** an async function which can update request object.
* `onResponse` **[function][7]?** an async function which can update response object.
* `maxUploadFileSize` **[number][5]?** set the max content file size in MB when performing api calls.


- `endpoint` **[string][3]?** API base URL
- `prettyPrintJson` **[boolean][6]?** pretty print json for response/request on console logs.
- `printCurl` **[boolean][6]?** print cURL request on console logs. False by default.
- `timeout` **[number][5]?** timeout for requests in milliseconds. 10000ms by default.
- `defaultHeaders` **[object][4]?** a list of default headers.
- `httpAgent` **[object][4]?** create an agent with SSL certificate
- `onRequest` **[function][7]?** an async function which can update request object.
- `onResponse` **[function][7]?** an async function which can update response object.
- `maxUploadFileSize` **[number][5]?** set the max content file size in MB when performing api calls.

## Example

Expand Down Expand Up @@ -91,34 +87,34 @@ Send REST requests by accessing `_executeRequest` method:

```js
this.helpers['REST']._executeRequest({
url,
data,
});
url,
data,
})
```

## Methods

### Parameters

* `config`  
- `config`  

### _executeRequest
### \_executeRequest

Executes axios request

#### Parameters

* `request` **any** 
- `request` **any** 

Returns **[Promise][2]<any>** response

### _url
### \_url

Generates url based on format sent (takes endpoint + url if latter lacks 'http')

#### Parameters

* `url` **any**&#x20;
- `url` **any**&#x20;

### amBearerAuthenticated

Expand All @@ -131,28 +127,28 @@ I.amBearerAuthenticated(secret('heregoestoken'))

#### Parameters

* `accessToken` **([string][3] | CodeceptJS.Secret)** Bearer access token
- `accessToken` **([string][3] | CodeceptJS.Secret)** Bearer access token

### haveRequestHeaders

Sets request headers for all requests of this test

#### Parameters

* `headers` **[object][4]** headers list
- `headers` **[object][4]** headers list

### sendDeleteRequest

Sends DELETE request to API.

```js
I.sendDeleteRequest('/api/users/1');
I.sendDeleteRequest('/api/users/1')
```

#### Parameters

* `url` **any**&#x20;
* `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object
- `url` **any**&#x20;
- `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object

Returns **[Promise][2]<any>** response

Expand All @@ -161,14 +157,14 @@ Returns **[Promise][2]<any>** response
Sends DELETE request to API with payload.

```js
I.sendDeleteRequestWithPayload('/api/users/1', { author: 'john' });
I.sendDeleteRequestWithPayload('/api/users/1', { author: 'john' })
```

#### Parameters

* `url` **any**&#x20;
* `payload` **any** the payload to be sent. By default it is sent as an empty object
* `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object
- `url` **any**&#x20;
- `payload` **any** the payload to be sent. By default it is sent as an empty object
- `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object

Returns **[Promise][2]<any>** response

Expand All @@ -177,13 +173,28 @@ Returns **[Promise][2]<any>** response
Send GET request to REST API

```js
I.sendGetRequest('/api/users.json');
I.sendGetRequest('/api/users.json')
```

#### Parameters

* `url` **any**&#x20;
* `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object
- `url` **any**&#x20;
- `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object

Returns **[Promise][2]<any>** response

### sendHeadRequest

Send HEAD request to REST API

```js
I.sendHeadRequest('/api/users.json')
```

#### Parameters

- `url` **any**&#x20;
- `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object

Returns **[Promise][2]<any>** response

Expand All @@ -192,18 +203,17 @@ Returns **[Promise][2]<any>** response
Sends PATCH request to API.

```js
I.sendPatchRequest('/api/users.json', { "email": "user@user.com" });
I.sendPatchRequest('/api/users.json', { email: 'user@user.com' })

// To mask the payload in logs
I.sendPatchRequest('/api/users.json', secret({ "email": "user@user.com" }));

I.sendPatchRequest('/api/users.json', secret({ email: 'user@user.com' }))
```

#### Parameters

* `url` **[string][3]**&#x20;
* `payload` **any** the payload to be sent. By default it is sent as an empty object
* `headers` **[object][4]** the headers object to be sent. By default it is sent as an empty object
- `url` **[string][3]**&#x20;
- `payload` **any** the payload to be sent. By default it is sent as an empty object
- `headers` **[object][4]** the headers object to be sent. By default it is sent as an empty object

Returns **[Promise][2]<any>** response

Expand All @@ -212,18 +222,17 @@ Returns **[Promise][2]<any>** response
Sends POST request to API.

```js
I.sendPostRequest('/api/users.json', { "email": "user@user.com" });
I.sendPostRequest('/api/users.json', { email: 'user@user.com' })

// To mask the payload in logs
I.sendPostRequest('/api/users.json', secret({ "email": "user@user.com" }));

I.sendPostRequest('/api/users.json', secret({ email: 'user@user.com' }))
```

#### Parameters

* `url` **any**&#x20;
* `payload` **any** the payload to be sent. By default, it is sent as an empty object
* `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object
- `url` **any**&#x20;
- `payload` **any** the payload to be sent. By default, it is sent as an empty object
- `headers` **[object][4]** the headers object to be sent. By default, it is sent as an empty object

Returns **[Promise][2]<any>** response

Expand All @@ -232,18 +241,17 @@ Returns **[Promise][2]<any>** response
Sends PUT request to API.

```js
I.sendPutRequest('/api/users.json', { "email": "user@user.com" });
I.sendPutRequest('/api/users.json', { email: 'user@user.com' })

// To mask the payload in logs
I.sendPutRequest('/api/users.json', secret({ "email": "user@user.com" }));

I.sendPutRequest('/api/users.json', secret({ email: 'user@user.com' }))
```

#### Parameters

* `url` **[string][3]**&#x20;
* `payload` **any** the payload to be sent. By default it is sent as an empty object
* `headers` **[object][4]** the headers object to be sent. By default it is sent as an empty object
- `url` **[string][3]**&#x20;
- `payload` **any** the payload to be sent. By default it is sent as an empty object
- `headers` **[object][4]** the headers object to be sent. By default it is sent as an empty object

Returns **[Promise][2]<any>** response

Expand All @@ -252,23 +260,17 @@ Returns **[Promise][2]<any>** response
Set timeout for the request

```js
I.setRequestTimeout(10000); // In milliseconds
I.setRequestTimeout(10000) // In milliseconds
```

#### Parameters

* `newTimeout` **[number][5]** timeout in milliseconds
- `newTimeout` **[number][5]** timeout in milliseconds

[1]: https://github.com/axios/axios

[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise

[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
Loading