@contract-case/case-core-plugin-http
Version:
ContractCase core HTTP plugin, providing HTTP matchers and mocks
31 lines • 1.69 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, context) => {
if (!(field in data)) {
throw new case_plugin_base_1.CaseConfigurationError(`${name} must contain a '${String(field)}' key`, context, 'BAD_INTERACTION_DEFINITION');
}
if (typeof data[field] !== type) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must be a ${type}`, context, 'BAD_INTERACTION_DEFINITION');
}
if (notNull && data[field] === null) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must not be null`, context, 'BAD_INTERACTION_DEFINITION');
}
};
const ifPresentInternal = (data, { field, type, notNull }, name, context) => {
if (field in data) {
if (typeof data[field] !== type) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must be a ${type}`, context, 'BAD_INTERACTION_DEFINITION');
}
if (notNull && data[field] === null) {
throw new case_plugin_base_1.CaseConfigurationError(`${name}'s ${String(field)} must not be null`, context, 'BAD_INTERACTION_DEFINITION');
}
}
};
const makeAssertionsOn = (data, name, context) => ({
assertFieldPresent: (descriptor) => assertPresentInternal(data, descriptor, name, context),
assertIfFieldPresent: (descriptor) => ifPresentInternal(data, descriptor, name, context),
});
exports.makeAssertionsOn = makeAssertionsOn;
//# sourceMappingURL=assert.js.map