swagger-tests
Version:
A typescript framework for testing an api against a swagger 3.0 json file.
70 lines • 3.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const services_1 = require("../services");
const underscore_1 = require("underscore");
class RequestSupport {
constructor(apiSupport) {
this.apiSupport = apiSupport;
}
async success(response) {
await this.addAuthorization();
if (this.apiSupport.operation.restAction == 'create') {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.valid()));
}
else if (this.apiSupport.operation.restAction == 'update') {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.valid()), response.data.id);
}
else if (underscore_1.contains(['show', 'delete'], this.apiSupport.operation.restAction)) {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, {}, response.data.id);
}
else {
return services_1.HttpService.query(this.apiSupport.axiosConfig, this.apiSupport.route, {});
}
}
async bad(response) {
await this.addAuthorization();
if (this.apiSupport.operation.restAction == 'create') {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.invalid()));
}
else if (this.apiSupport.operation.restAction == 'update') {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.invalid()), response.data.id);
}
else if (this.apiSupport.operation.restAction == 'index') {
return services_1.HttpService.query(this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.invalid()));
}
else {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.invalid()), response.data.id);
}
}
async notFound(_response) {
await this.addAuthorization();
if (this.apiSupport.operation.restAction == 'update') {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.valid()), -999);
}
else {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, {}, -999);
}
}
async unauthorized(_response) {
this.removeAuthorization();
if (this.apiSupport.operation.restAction == 'index') {
return services_1.HttpService.query(this.apiSupport.axiosConfig, this.apiSupport.route, {});
}
else if (this.apiSupport.operation.restAction == 'create') {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, await (this.apiSupport.attributes.valid()));
}
else {
return services_1.HttpService[this.apiSupport.operation.restMethod](this.apiSupport.axiosConfig, this.apiSupport.route, {}, -999);
}
}
removeAuthorization() {
if (this.apiSupport.axiosConfig.headers !== undefined && this.apiSupport.axiosConfig.headers.Authorization !== undefined) {
delete this.apiSupport.axiosConfig.headers.Authorization;
}
}
async addAuthorization() {
return true;
}
}
exports.RequestSupport = RequestSupport;
//# sourceMappingURL=request.support.js.map