UNPKG

@n1k1t/mock-server

Version:

Powerful util to setup mocks over HTTP APIs

35 lines 1.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = __importDefault(require("lodash")); const utils_1 = require("../utils"); const operator_1 = require("../models/operator"); class RemoveExpectationOperator extends operator_1.ExpectationOperator { get tags() { return []; } match() { return true; } manipulate(context) { const payload = (0, utils_1.extractContextByLocation)(this.command.$location, context); if (payload?.type !== 'object') { return context; } if (this.command.$path) { lodash_1.default.unset(payload.value, this.command.$path); return context; } if (this.command.$jsonPath && lodash_1.default.isObject(payload.value)) { (0, utils_1.extractWithJsonPathSafe)({ path: this.command.$jsonPath, json: payload.value }) .results?.forEach((segment) => lodash_1.default.unset(segment.parent, segment.parentProperty)); return context; } lodash_1.default.unset(payload.parent, payload.key); return context; } } exports.default = RemoveExpectationOperator; //# sourceMappingURL=remove.operator.js.map