request-mocking-protocol
Version:
A protocol for declarative mocking of HTTP requests
23 lines • 859 B
JavaScript
;
/**
* Schema to generate the response.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildMockResponseSchema = buildMockResponseSchema;
exports.toMockResponseSchemaObject = toMockResponseSchemaObject;
function buildMockResponseSchema(init) {
const initObj = toMockResponseSchemaObject(init);
assertSchema(initObj);
return Object.assign({}, initObj);
}
function toMockResponseSchemaObject(init) {
return typeof init === 'number' ? { status: init } : init;
}
function assertSchema(schema) {
const isStaticResponse = schema.status || schema.body;
const isPatchedResponse = schema.request || schema.bodyPatch;
if (isStaticResponse && isPatchedResponse) {
throw new Error('Ambiguous schema: is it static mock or patched response?');
}
}
//# sourceMappingURL=response-schema.js.map