@n1k1t/mock-server
Version:
Powerful util to setup mocks over HTTP APIs
56 lines • 2.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const operator_1 = require("../models/operator");
class IfExpectationOperator extends operator_1.ExpectationOperator {
constructor() {
super(...arguments);
this.compiled = {
condition: (() => {
const extracted = this.extractNestedSchema(this.command.$condition);
if (!extracted) {
return null;
}
const Operator = this.operators[extracted.key];
return new Operator(this.operators, extracted.nested);
})(),
...(this.command.$then && {
then: (() => {
const extracted = this.extractNestedSchema(this.command.$then);
if (!extracted) {
return null;
}
const Operator = this.operators[extracted.key];
return new Operator(this.operators, extracted.nested);
})(),
}),
...(this.command.$else && {
else: (() => {
const extracted = this.extractNestedSchema(this.command.$else);
if (!extracted) {
return null;
}
const Operator = this.operators[extracted.key];
return new Operator(this.operators, extracted.nested);
})(),
}),
};
}
get tags() {
return [
...(this.compiled.condition?.tags ?? []),
...(this.compiled.then?.tags ?? []),
...(this.compiled.else?.tags ?? []),
];
}
match(context) {
const result = this.compiled.condition?.match(context) ?? false;
return (result ? this.compiled.then?.match(context) : this.compiled.else?.match(context)) ?? false;
}
manipulate(context) {
const result = this.compiled.condition?.match(context) ?? false;
result ? this.compiled.then?.manipulate(context) : this.compiled.else?.manipulate(context);
return context;
}
}
exports.default = IfExpectationOperator;
//# sourceMappingURL=if.operator.js.map