@contract-case/case-core-plugin-http
Version:
ContractCase core HTTP plugin, providing HTTP matchers and mocks
31 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeAssertionsOn = void 0;
const case_plugin_base_1 = require("@contract-case/case-plugin-base");
const assertPresentInternal = (data, { field, type, notNull }, name) => {
if (!(field in data)) {
throw new case_plugin_base_1.CaseConfigurationError(`${name} must contain a '${String(field)}' key`);
}
if (typeof data[field] !== type) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must be a ${type}`);
}
if (notNull && data[field] === null) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must not be null`);
}
};
const ifPresentInternal = (data, { field, type, notNull }, name) => {
if (field in data) {
if (typeof data[field] !== type) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must be a ${type}`);
}
if (notNull && data[field] === null) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must not be null`);
}
}
};
const makeAssertionsOn = (data, name) => ({
assertFieldPresent: ({ field, type }) => assertPresentInternal(data, { field, type }, name),
assertIfFieldPresent: ({ field, type }) => ifPresentInternal(data, { field, type }, name),
});
exports.makeAssertionsOn = makeAssertionsOn;
//# sourceMappingURL=assert.js.map