1.0.3 • Published 2 years ago

wdio-enverus-core-api v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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

MethodsMethods typeParameters
async getDatapublichost: string, endpoint: string, query: string, headers: Map
async postDatapublichost: string, endpoint: string, body: Object, headers: Map
async putDatapublichost: string, endpoint: string, body: Object, headers: Map
async attachDatapublichost: string, endpoint: string, path: string, headers: Map
async deleteDatapublichost: string, endpoint: string, headers: Map
async deleteDataBodypublichost: string, endpoint: string, headers: Map

Params:

NameTypeDescription
hoststringServer URL
endpointstringAPI request url
querystringAPI request query
bodyObjectAPI request body
headersMapAPI request header Object

How to use:

  1. 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;
    }
}
  1. 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();
1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago