Repository URL to install this package:
|
Version:
7.1.2 ▾
|
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const exotic_1 = require("exotic");
// from config?
const mockUrl = process.env.BASE_URL || 'http://localhost:4000';
function toUrl(url = '') {
// for now, autofix it to include the baseUrl
if (!url.includes('http')) {
return mockUrl + url;
}
else {
return url;
}
}
exports.toUrl = toUrl;
function adaptRequest(store) {
const _a = exotic_1.fromMapToObj(store), { params = '', method, tapParams, tapResponse } = _a, remaining = __rest(_a, ["params", "method", "tapParams", "tapResponse"]);
const url = toUrl(remaining.url);
const nock = require('nock');
const handleGet = (urlRequested) => {
// `api/${url}`
const doesRequestIncludeUrl = urlRequested.includes(url) || url.includes(urlRequested);
// console.log('[oneRequest] asMock - handleGet', { url, urlRequested, doesRequestIncludeUrl })
return doesRequestIncludeUrl;
};
const data = exotic_1.isFunction(tapResponse)
? tapResponse()
: { '@@EMPTY_RESPONSE': true };
if (method === 'POST') {
return nock(mockUrl)
.post(url)
.query(params)
.reply(201, data);
}
else {
return nock(mockUrl)
.get(handleGet)
.query(params)
.reply(200, data);
}
}
exports.adaptRequest = adaptRequest;
//# sourceMappingURL=mock.js.map