UNPKG

unmock-core

Version:

[![npm](https://img.shields.io/npm/v/unmock-core.svg)][npmjs] [![CircleCI](https://circleci.com/gh/unmock/unmock-js.svg?style=svg)](https://circleci.com/gh/unmock/unmock-js) [![codecov](https://codecov.io/gh/unmock/unmock-js/branch/dev/graph/badge.svg)](h

394 lines 19.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon_1 = require("sinon"); const decorate_1 = require("../decorate"); exports.decorators = { with(matcher) { return decorate_1.decorateSpy(this.withArgs(matcher)); }, withMethod(method) { return this.with(sinon_1.match({ method })); }, postRequestHost(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestHost" }); return spyWithMatcher.firstCall.args[0].host; }, postRequestBody(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestBody" }); return spyWithMatcher.firstCall.args[0].body; }, postRequestBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestBodyAsJson", }); return spyWithMatcher.firstCall.args[0].bodyAsJson; }, postRequestPath(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestPath" }); return spyWithMatcher.firstCall.args[0].path; }, postRequestPathname(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestPathname", }); return spyWithMatcher.firstCall.args[0].pathname; }, postRequestHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestHeaders" }); return spyWithMatcher.firstCall.args[0].headers; }, postRequestQuery(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestQuery" }); return spyWithMatcher.firstCall.args[0].query; }, postRequestProtocol(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestProtocol", }); return spyWithMatcher.firstCall.args[0].protocol; }, postResponseBody(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postResponseBody" }); return spyWithMatcher.firstCall.returnValue.body; }, postResponseBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postResponseBodyAsJson", }); return spyWithMatcher.firstCall.returnValue.bodyAsJson; }, postResponseCode(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postResponseCode" }); return spyWithMatcher.firstCall.returnValue.statusCode; }, postResponseHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "post" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postResponseHeaders", }); return spyWithMatcher.firstCall.returnValue.headers; }, getRequestHost(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestHost" }); return spyWithMatcher.firstCall.args[0].host; }, getRequestBody(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestBody" }); return spyWithMatcher.firstCall.args[0].body; }, getRequestBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestBodyAsJson", }); return spyWithMatcher.firstCall.args[0].bodyAsJson; }, getRequestPath(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestPath" }); return spyWithMatcher.firstCall.args[0].path; }, getRequestPathname(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestPathname" }); return spyWithMatcher.firstCall.args[0].pathname; }, getRequestHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestHeaders" }); return spyWithMatcher.firstCall.args[0].headers; }, getRequestQuery(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestQuery" }); return spyWithMatcher.firstCall.args[0].query; }, getRequestProtocol(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestProtocol" }); return spyWithMatcher.firstCall.args[0].protocol; }, getResponseBody(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getResponseBody" }); return spyWithMatcher.firstCall.returnValue.body; }, getResponseBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getResponseBodyAsJson", }); return spyWithMatcher.firstCall.returnValue.bodyAsJson; }, getResponseCode(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getResponseCode" }); return spyWithMatcher.firstCall.returnValue.statusCode; }, getResponseHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "get" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getResponseHeaders" }); return spyWithMatcher.firstCall.returnValue.headers; }, putRequestHost(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestHost" }); return spyWithMatcher.firstCall.args[0].host; }, putRequestBody(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestBody" }); return spyWithMatcher.firstCall.args[0].body; }, putRequestBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestBodyAsJson", }); return spyWithMatcher.firstCall.args[0].bodyAsJson; }, putRequestPath(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestPath" }); return spyWithMatcher.firstCall.args[0].path; }, putRequestPathname(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestPathname" }); return spyWithMatcher.firstCall.args[0].pathname; }, putRequestHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestHeaders" }); return spyWithMatcher.firstCall.args[0].headers; }, putRequestQuery(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestQuery" }); return spyWithMatcher.firstCall.args[0].query; }, putRequestProtocol(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestProtocol" }); return spyWithMatcher.firstCall.args[0].protocol; }, putResponseBody(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putResponseBody" }); return spyWithMatcher.firstCall.returnValue.body; }, putResponseBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putResponseBodyAsJson", }); return spyWithMatcher.firstCall.returnValue.bodyAsJson; }, putResponseCode(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putResponseCode" }); return spyWithMatcher.firstCall.returnValue.statusCode; }, putResponseHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "put" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putResponseHeaders" }); return spyWithMatcher.firstCall.returnValue.headers; }, deleteRequestHost(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestHost" }); return spyWithMatcher.firstCall.args[0].host; }, deleteRequestBody(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestBody" }); return spyWithMatcher.firstCall.args[0].body; }, deleteRequestBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestBodyAsJson", }); return spyWithMatcher.firstCall.args[0].bodyAsJson; }, deleteRequestPath(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestPath" }); return spyWithMatcher.firstCall.args[0].path; }, deleteRequestPathname(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestPathname", }); return spyWithMatcher.firstCall.args[0].pathname; }, deleteRequestHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestHeaders", }); return spyWithMatcher.firstCall.args[0].headers; }, deleteRequestQuery(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestQuery" }); return spyWithMatcher.firstCall.args[0].query; }, deleteRequestProtocol(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestProtocol", }); return spyWithMatcher.firstCall.args[0].protocol; }, deleteResponseBody(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteResponseBody" }); return spyWithMatcher.firstCall.returnValue.body; }, deleteResponseBodyAsJson(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteResponseBodyAsJson", }); return spyWithMatcher.firstCall.returnValue.bodyAsJson; }, deleteResponseCode(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteResponseCode" }); return spyWithMatcher.firstCall.returnValue.statusCode; }, deleteResponseHeaders(matcher) { const methodMatcher = sinon_1.match({ method: "delete" }); const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher; const spyWithMatcher = this.with(fullMatcher); decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteResponseHeaders", }); return spyWithMatcher.firstCall.returnValue.headers; }, }; //# sourceMappingURL=index.js.map