@case-contract-testing/case
Version:
Next-generation contract testing suite
32 lines (31 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.uriEncodedString = exports.httpStatus = void 0;
const entities_1 = require("../../../entities");
const matcher_1 = require("../../../entities/nodes/matchers/http/matcher");
/**
* Matches http status codes. Matches may be provided as a string, eg '4XX' or '401', or a number.
* If an array is provided, any status codes in the array will be matched.
*
* @param match - the status code to match
* @param example - optionally, an example to use during the test. If you do not provide one, case uses a code that passes the matcher.
* @returns
*/
const httpStatus = (match, example) => {
if (Array.isArray(match)) {
return (0, entities_1.httpStatusCodeMatcher)(match.map((r) => `${r}`), example);
}
return (0, entities_1.httpStatusCodeMatcher)(`${match}`, example);
};
exports.httpStatus = httpStatus;
/**
* Convenience matcher to treat the string as a uri encoded string. Useful in `path` segments.
*
* During matching, the actual value is decoded with `decodeUriComponent()` and passed to the child matcher.
*
* @param child - Any string matcher or literal string
*/
const uriEncodedString = (child) =>
// TODO: Check here that the child matcher will accept a string
(0, matcher_1.coreUrlEncodedString)(child);
exports.uriEncodedString = uriEncodedString;