UNPKG

swagger-tests

Version:

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

47 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const services_1 = require("../services"); const underscore_1 = require("underscore"); class BeforeSupport { constructor(apiSupport) { this.apiSupport = apiSupport; } async success() { await this.addAuthorization(); if (underscore_1.contains(['delete', 'update', 'show', 'index'], this.apiSupport.operation.restAction)) { const validAttributes = await (this.apiSupport.attributes.valid()); return services_1.HttpService.post(Object.assign({}, this.apiSupport.axiosConfig, { maxRedirects: 1 }), this.apiSupport.route, validAttributes); } else { return true; } } async bad() { await this.addAuthorization(); if (underscore_1.contains(['update'], this.apiSupport.operation.restAction)) { const validAttributes = await (this.apiSupport.attributes.valid()); return services_1.HttpService.post(Object.assign({}, this.apiSupport.axiosConfig, { maxRedirects: 1 }), this.apiSupport.route, validAttributes); } else { return true; } } async notFound() { await this.addAuthorization(); return true; } async unauthorized() { this.removeAuthorization(); return true; } removeAuthorization() { if (this.apiSupport.axiosConfig.headers !== undefined && this.apiSupport.axiosConfig.headers.Authorization !== undefined) { delete this.apiSupport.axiosConfig.headers.Authorization; } } async addAuthorization() { return true; } } exports.BeforeSupport = BeforeSupport; //# sourceMappingURL=before.support.js.map