"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.expectError = exports.expectBatchFailure = exports.expectNoListOutput = exports.expectNoSingleOutput = exports.expectSuccessfulBatchOutput = exports.expectSuccessfulListOutput = exports.expectSuccessfulSingleOutput = exports.expectSuccessful = void 0;
const chai_1 = require("chai");
// --------------------------------------------------
//
// THIS FILE IS A COPY LIFTED FROM codiac-api-base
//
// --------------------------------------------------
function expectSuccessful(eventAttempted, result) {
    if (result.error) {
        //console.log(result.error.stack);
        (0, chai_1.expect)(result.error).to.equal(undefined, `${eventAttempted} must execute without errors.  Error returned: ${result.error.stack}`);
    }
    (0, chai_1.expect)(result.success).to.equal(true, `${eventAttempted} must return success.`);
}
exports.expectSuccessful = expectSuccessful;
function expectSuccessfulSingleOutput(eventAttempted, result) {
    expectSuccessful(eventAttempted, result);
    (0, chai_1.expect)(result.output).to.not.equal(undefined, `${eventAttempted} must return the entity as output.`);
}
exports.expectSuccessfulSingleOutput = expectSuccessfulSingleOutput;
function expectSuccessfulListOutput(eventAttempted, result, expectedQty) {
    expectSuccessful(eventAttempted, result);
    (0, chai_1.expect)(result.output).to.not.equal(undefined, `${eventAttempted} must return output.`);
    if (expectedQty) {
        (0, chai_1.expect)(result.count).to.equal(expectedQty, `${eventAttempted} must return ${expectedQty} entities. \nActual output: ${JSON.stringify(result.output, undefined, 2)}`);
    }
}
exports.expectSuccessfulListOutput = expectSuccessfulListOutput;
function expectSuccessfulBatchOutput(eventAttempted, result) {
    expectSuccessful(eventAttempted, result);
    (0, chai_1.expect)(result.successes).to.not.equal(undefined, `${eventAttempted} must return successes.`);
    (0, chai_1.expect)(result.failures).to.not.equal(undefined, `${eventAttempted} must not return an undefined failures list.`);
    (0, chai_1.expect)(result.failures.length).to.equal(0, `${eventAttempted} must return an empty failures list.`);
}
exports.expectSuccessfulBatchOutput = expectSuccessfulBatchOutput;
/** NOTE:  This method ensures that there is no error either. */
function expectNoSingleOutput(eventAttempted, result) {
    (0, chai_1.expect)(result.success).to.equal(false, `${eventAttempted} must return unsuccessful.`);
    (0, chai_1.expect)(result.output).to.equal(undefined, `${eventAttempted} must not return output.`);
    (0, chai_1.expect)(result.error).to.equal(undefined, `${eventAttempted} must not return an error.`);
}
exports.expectNoSingleOutput = expectNoSingleOutput;
/** NOTE:  This method ensures that there is no error either. */
function expectNoListOutput(eventAttempted, result) {
    (0, chai_1.expect)(result.success).to.equal(false, `${eventAttempted} must return unsuccessful.`);
    if (result.output) {
        (0, chai_1.expect)(result.output.length).to.equal(0, `${eventAttempted} must return empty or undefined output.`);
    }
    (0, chai_1.expect)(result.error).to.equal(undefined, `${eventAttempted} must not return an error.`);
}
exports.expectNoListOutput = expectNoListOutput;
/** NOTE:  This method does NOT check for result.error. */
function expectBatchFailure(eventAttempted, result) {
    (0, chai_1.expect)(result.success).to.equal(false, `${eventAttempted} must return unsuccessful.`);
    if (result.successes) {
        (0, chai_1.expect)(result.successes.length).to.equal(0, `${eventAttempted} must return empty or undefined successes.`);
    }
    if (result.failures) {
        (0, chai_1.expect)(result.failures.length).to.gt(0, `${eventAttempted} must return failures.`);
    }
}
exports.expectBatchFailure = expectBatchFailure;
/** NOTE:  This method does NOT check for null output. */
function expectError(eventAttempted, result) {
    (0, chai_1.expect)(result.success).to.equal(false, `${eventAttempted} must return unsuccessful.`);
    (0, chai_1.expect)(result.error).to.not.equal(undefined, `${eventAttempted} must return error.`);
}
exports.expectError = expectError;
//# sourceMappingURL=test-extensions.js.map