@ply-ct/ply
Version:
REST API Automated Testing
100 lines • 3.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContextImpl = void 0;
const result_1 = require("../result");
const replace_1 = require("../replace");
const util_1 = require("../util");
class ContextImpl {
constructor(base) {
this.base = base;
}
get name() {
return this.base.name;
}
get runtime() {
return this.base.runtime;
}
get flow() {
return this.base.flow;
}
get flowInstance() {
return this.base.flowInstance;
}
get subflow() {
return this.base.subflow;
}
get step() {
return this.base.step;
}
get stepInstance() {
return this.base.stepInstance;
}
get logger() {
return this.base.logger;
}
get values() {
return this.base.values;
}
get runOptions() {
return this.base.runOptions;
}
get requestSuite() {
return this.base.requestSuite;
}
get runNum() {
return this.base.runNum;
}
get instNum() {
return this.base.instNum;
}
evaluateToString(expr) {
var _a;
return (0, replace_1.replaceLine)(expr, this.values, {
trusted: (_a = this.runOptions) === null || _a === void 0 ? void 0 : _a.trusted,
logger: this.logger
});
}
getAttribute(name, options) {
var _a;
if (this.step.attributes) {
const val = this.step.attributes[name];
if (val) {
return (0, replace_1.replace)(val, this.values, {
logger: this.logger,
trusted: (_a = this.runOptions) === null || _a === void 0 ? void 0 : _a.trusted
});
}
}
if (options === null || options === void 0 ? void 0 : options.required)
throw new Error(`Missing required attribute: ${name}`);
}
async verifyData(data) {
var _a, _b;
if ((_a = this.runOptions) === null || _a === void 0 ? void 0 : _a.submit)
return { status: 'Submitted', data };
if ((_b = this.runOptions) === null || _b === void 0 ? void 0 : _b.createExpected)
return { status: 'Passed', data };
const indent = this.runtime.options.prettyIndent;
const actualYaml = this.runtime.results.getActualYaml(this.step.id);
let actualYamlText = actualYaml.text + 'data: |\n'.padStart(8 + indent);
for (const line of (0, util_1.lines)(JSON.stringify(data, null, indent))) {
actualYamlText += line.padStart(line.length + 2 * indent) + '\n';
}
const expectedYaml = await this.runtime.results.getExpectedYaml(this.step.id);
const verifier = new result_1.Verifier(this.step.name.replace(/\r?\n/g, ' '), expectedYaml, this.logger);
const outcome = verifier.verify({ ...actualYaml, text: actualYamlText }, this.values, this.runOptions);
outcome.data = data;
return outcome;
}
logInfo(message, obj) {
this.logger.info(`${this.step.id} => ${message}`, obj);
}
logError(message, obj) {
this.logger.error(`${this.step.id} => ${message}`, obj);
}
logDebug(message, obj) {
this.logger.debug(`${this.step.id} => ${message}`, obj);
}
}
exports.ContextImpl = ContextImpl;
//# sourceMappingURL=impl.js.map