@case-contract-testing/case
Version:
Next-generation contract testing suite
21 lines (20 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UrlEncodedStringMatcher = void 0;
const entities_1 = require("../../entities");
const context_1 = require("../../entities/context");
const results_1 = require("../../entities/results");
const check = (matcher, matchContext, actual) => typeof actual === 'string'
? matchContext.descendAndCheck(matcher['case:matcher:child'], (0, context_1.addLocation)(':urlEncoded', matchContext), decodeURIComponent(actual))
: (0, results_1.makeResults)((0, results_1.matchingError)(matcher, `${(0, results_1.actualToString)(actual)} is not a string; so can't treat it as an encoded URL component`, actual, matchContext));
const strip = (matcher, matchContext) => {
const result = matchContext.descendAndStrip(matcher['case:matcher:child'], (0, context_1.addLocation)(':urlEncoded', matchContext));
if (typeof result === 'string')
return encodeURIComponent(result);
throw new entities_1.CaseConfigurationError(`Unable to URL encode '${result}' during stripMatchers, as it's not a string and therefore can't be URL encoded`);
};
exports.UrlEncodedStringMatcher = {
describe: (matcher, matchContext) => `uriEncoded string '${matchContext.descendAndDescribe(matcher['case:matcher:child'], (0, context_1.addLocation)(':urlEncoded', matchContext))}'`,
check,
strip,
};