UNPKG

@ply-ct/ply

Version:

REST API Automated Testing

90 lines 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlyExecBase = exports.LegacyExec = void 0; const result_1 = require("../result"); const replace_1 = require("../replace"); const util_1 = require("../util"); const exec_1 = require("./exec"); /** * Wraps a legacy PlyExecBase implementation */ class LegacyExec extends exec_1.StepExec { constructor(plyExecBase) { super(); this.plyExecBase = plyExecBase; } async run(context) { return this.plyExecBase.run(context.runtime, context.values, context.runOptions); } } exports.LegacyExec = LegacyExec; /** * @deprecated Extend StepExec or implement PlyExec directly */ class PlyExecBase { constructor(step, instance, logger) { this.step = step; this.instance = instance; this.logger = logger; } evaluateToString(expr, values, trusted = false) { return (0, replace_1.replaceLine)(expr, values, { trusted, logger: this.logger }); } /** * Returns a substituted attribute value */ getAttribute(name, values, options) { if (this.step.attributes) { const val = this.step.attributes[name]; if (val) { return (0, replace_1.replace)(val, values, { logger: this.logger, trusted: options === null || options === void 0 ? void 0 : options.trusted }); } } if (options === null || options === void 0 ? void 0 : options.required) throw new Error(`Missing required attribute: ${name}`); } isTrustRequired() { return true; } isExpression(input) { return input.startsWith('${') && input.endsWith('}'); } async verifyData(runtime, data, values, runOptions) { if (runOptions === null || runOptions === void 0 ? void 0 : runOptions.submit) return { status: 'Submitted', data }; if (runOptions === null || runOptions === void 0 ? void 0 : runOptions.createExpected) return { status: 'Passed', data }; const indent = runtime.options.prettyIndent; const actualYaml = 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 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 }, values, runOptions); outcome.data = data; return outcome; } /** * Tagged log at info level */ logInfo(message, obj) { this.logger.info(`${this.step.id} => ${message}`, obj); } /** * Tagged log at error level */ logError(message, obj) { this.logger.error(`${this.step.id} => ${message}`, obj); } /** * Tagged log at debug level */ logDebug(message, obj) { this.logger.debug(`${this.step.id} => ${message}`, obj); } } exports.PlyExecBase = PlyExecBase; PlyExecBase.legacy = true; //# sourceMappingURL=legacy.js.map