This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+16
View File
@@ -0,0 +1,16 @@
const schemaMatcher = require('./schema-matcher');
const statusCodeMatcher = require('./status-matcher');
const coverage = require('../../helpers/coverage');
const { messages } = require('../../helpers/common');
module.exports = function apiSchemaPlugin(should, options) {
const Assertion = should.Assertion || should;
if (!(options instanceof Object) || !options.apiDefinitionsPath) {
throw new Error(messages.REQUIRED_API_DEFINITIONS_PATH);
}
coverage.init(options);
schemaMatcher(Assertion, options);
statusCodeMatcher(Assertion);
};
@@ -0,0 +1,20 @@
const validators = require('../../validators');
module.exports = (Assertion, options) => {
Assertion.add('matchApiSchema', function addApiSchemaMethod(apiDefinitionsPath) {
const {
predicate, actual, expected, matchMsg,
} = validators.schemaValidator(
this.obj,
{ ...options, apiDefinitionsPath: apiDefinitionsPath || options.apiDefinitionsPath },
);
this.params = {
message: matchMsg,
expected,
actual,
};
predicate.should.be.true();
});
};
@@ -0,0 +1,31 @@
const validators = require('../../validators');
module.exports = (Assertion) => {
buildMatcher('successful', 200);
buildMatcher('created', 201);
buildMatcher('badRequest', 400);
buildMatcher('unauthorized', 401);
buildMatcher('forbidden', 403);
buildMatcher('notFound', 404);
buildMatcher('serverError', 500);
buildMatcher('serviceUnavailable', 503);
buildMatcher('gatewayTimeout', 504);
buildMatcher('status');
function buildMatcher(str, statusToTest) {
Assertion.add(str, function statusCodeMatcher(customStatus) {
const expectedStatus = statusToTest || customStatus;
const {
predicate, actual, expected, matchMsg,
} = validators.statusValidator(expectedStatus, this.obj);
this.params = {
message: matchMsg,
expected,
actual,
};
predicate.should.be.true();
});
}
};