@ply-ct/ply
Version:
REST API Automated Testing
47 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlyCase = void 0;
class PlyCase {
constructor(name, method, start, end, logger) {
this.name = name;
this.method = method;
this.start = start;
this.end = end;
this.logger = logger;
this.type = 'case';
}
/**
* Only to be called in the context of a Suite (hence 'runtime').
* To execute a test programmatically, call one of the Suite.run() overloads.
* Or to send a request without testing, call submit().
* @returns result with request outcomes and status of 'Pending'
*/
async run(runtime, values, runOptions) {
if (!(runOptions === null || runOptions === void 0 ? void 0 : runOptions.trusted)) {
throw new Error(`Trusted context required for case execution: '${runtime.suitePath}'`);
}
const decoratedSuite = runtime.decoratedSuite;
if (!decoratedSuite) {
throw new Error(`Missing decorators for suite '${runtime.suitePath}'`);
}
this.logger.info(`Running '${this.name}'`);
if (!(runOptions === null || runOptions === void 0 ? void 0 : runOptions.submit)) {
await decoratedSuite.runBefores(this.name, values);
}
const method = decoratedSuite.instance[this.method];
if (!method) {
throw new Error(`Case method ${this.method} not found in suite class ${runtime.retrieval.location}`);
}
await method.call(decoratedSuite.instance, values);
if (!(runOptions === null || runOptions === void 0 ? void 0 : runOptions.submit)) {
await decoratedSuite.runAfters(this.name, values);
}
return {
name: this.name,
status: 'Pending',
message: ''
};
}
}
exports.PlyCase = PlyCase;
//# sourceMappingURL=case.js.map