swagger-tests
Version:
A typescript framework for testing an api against a swagger 3.0 json file.
32 lines • 1.49 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const underscore_1 = require("underscore");
class ResponseSupport {
constructor(apiSupport) {
this.apiSupport = apiSupport;
}
async success(response) {
expect(response.status.toString()).toEqual(this.apiSupport.operation.statusCode);
if (this.apiSupport.operation.restAction === 'index') {
response.data = underscore_1.first(response.data);
}
if (underscore_1.contains(['index', 'show'], this.apiSupport.operation.restAction)) {
expect(this.apiSupport.attributes.required()).toEqual(underscore_1.intersection(this.apiSupport.attributes.required(), Object.keys(response.data)));
}
if (underscore_1.contains(['create', 'update'], this.apiSupport.operation.restAction) && response.status >= 300 && response.status < 400) {
expect(response.headers.location).toBeDefined('location missing from headers');
}
return true;
}
async notFound(response) {
expect(response.status.toString()).toEqual(this.apiSupport.operation.statusCode);
}
async bad(response) {
expect(response.status.toString()).toEqual(this.apiSupport.operation.statusCode);
}
async unauthorized(response) {
expect(response.status.toString()).toEqual(this.apiSupport.operation.statusCode);
}
}
exports.ResponseSupport = ResponseSupport;
//# sourceMappingURL=response.support.js.map
;