1.0.3 • Published 2 years ago
wdio-enverus-core-api v1.0.3
WDIO Enverus Core API methods
About
The motivation with this module is to provide a high-level abstraction for testing HTTP, while still allowing you to drop down to the lower-level API provided by superagent.
Getting Started
Install WDIO Enverus Core Api
as an npm module and save it to your package.json file as a development dependency:
npm install wdio-enverus-core-api --save-dev
Once installed it can now be referenced by simply calling import EnverusCoreApi from 'wdio-enverus-core-api'
;
Available methods:
- getData - Generic GET method
- postData - Generic POST method
- attachData - Generic POST(attach) method
- putData - Generic PUT method
- deleteData - Generic DELETE method
- deleteDataBody - Generic DELETE method with body
Method Summary
Methods | Methods type | Parameters |
---|---|---|
async getData | public | host: string , endpoint: string , query: string , headers: Map |
async postData | public | host: string , endpoint: string , body: Object , headers: Map |
async putData | public | host: string , endpoint: string , body: Object , headers: Map |
async attachData | public | host: string , endpoint: string , path: string , headers: Map |
async deleteData | public | host: string , endpoint: string , headers: Map |
async deleteDataBody | public | host: string , endpoint: string , headers: Map |
Params:
Name | Type | Description |
---|---|---|
host | string | Server URL |
endpoint | string | API request url |
query | string | API request query |
body | Object | API request body |
headers | Map | API request header Object |
How to use:
- Create CoreApi class
import EnverusCoreApi from 'wdio-enverus-core-api';
import { logger } from 'wdio-enverus-logger';
export default class CoreApi extends EnverusCoreApi {
get log () {
return logger;
}
/**
* Set basic headers for API requests
* @param {string} cookie
* @param {string} contentType
*/
async setBasicHeaders (contentType = 'application/json;charset=UTF-8') {
const headers = new Map();
headers.set('Content-Type', contentType);
headers.set('Cookie', await this.getUserCookies());
return headers;
}
}
- Create UserApi class
import CoreApi from './coreApi';
class UserApi extends CoreApi {
/**
* Get user information
* @param {string} userID
* @returns {Promise<Object>}
*/
async getUser (userID) {
this.log.infoMsg(`Get "${userID}" user information`);
return this.getData(
APP_URL.ADMIN_DEV_URL,
ENDPOINTS.USER_INFO(userID),
await this.setBasicHeaders()
);
}
}
export default new UserApi();