UNPKG

swagger-tests

Version:

A typescript framework for testing an api against a swagger 3.0 json file.

45 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const attribute_support_1 = require("./attribute.support"); const operation_support_1 = require("./operation.support"); const request_support_1 = require("./request.support"); const response_support_1 = require("./response.support"); const before_support_1 = require("./before.support"); const after_support_1 = require("./after.support"); class ApiSupport { constructor(operationStr, debug = false) { this.debug = debug; this.modelName = this.constructor.name.toString().replace('Api', ''); this.attributes = new attribute_support_1.AttributeSupport(this); this.axiosConfig = {}; this.before = new before_support_1.BeforeSupport(this); this.after = new after_support_1.AfterSupport(this); this.request = new request_support_1.RequestSupport(this); this.response = new response_support_1.ResponseSupport(this); this.operation = new operation_support_1.OperationSupport(operationStr); } get route() { return this.operation.route.replace('{id}/', ''); } async test() { this.step('before'); const beforeHookResponse = await (this.before[this.operation.statusString]()); this.step(beforeHookResponse); this.step('request'); const requestHookResponse = await (this.request[this.operation.statusString](beforeHookResponse)); this.step(`after received: ${requestHookResponse.status.toString()}`); this.step(requestHookResponse); this.step('response'); await this.response[this.operation.statusString](requestHookResponse); this.step('after'); const afterResponse = await this.after[this.operation.statusString](beforeHookResponse); this.step(afterResponse); } step(name) { if (this.debug) { console.log(name, this.modelName, this.operation.restAction, this.operation.statusString); } } } exports.ApiSupport = ApiSupport; //# sourceMappingURL=api.support.js.map