"use strict";
/**
 * Event logger test
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework.
 *
 *  liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var EventMediator_1 = require("../../src/system/EventMediator");
var ContextError_1 = require("../../src/error/ContextError");
var events_1 = require("events");
var chai_1 = require("chai");
describe('system.EventMediator captures and logs events', function () {
    [
        { event: 'document-processed', code: 'notice' },
        { event: 'delta-publish', code: 'notice' },
        { event: 'amqp-conn-warn', code: 'warning' },
        { event: 'amqp-reconnect', code: 'warning' },
        { event: 'request-received', code: 'notice' },
        { event: 'response-sent', code: 'notice' },
        { event: 'callback-sent', code: 'notice' },
    ].forEach(function (_a) {
        var event = _a.event, code = _a.code;
        it(event + " triggers log#" + code, function () {
            var method_called = false;
            var emitter = new events_1.EventEmitter();
            var log = createMockLogger();
            log[code] = function (_str) {
                method_called = true;
            };
            new EventMediator_1.EventMediator(log, emitter);
            emitter.emit(event);
            chai_1.expect(method_called).to.be.true;
        });
    });
    it('context and stack are retrieved from error', function () {
        var method_called = false;
        var event_id = 'error';
        var err_msg = 'Foo';
        var stub_err = new Error(err_msg);
        var emitter = new events_1.EventEmitter();
        var log = createMockLogger();
        var err_context = { bar: 'baz' };
        var expected_context = {
            bar: err_context.bar,
            stack: stub_err.stack,
        };
        log.error = function (str, context) {
            chai_1.expect(str).to.equal(err_msg);
            chai_1.expect(context).to.deep.equal(expected_context);
            method_called = true;
        };
        new EventMediator_1.EventMediator(log, emitter);
        emitter.emit(event_id, ContextError_1.context(stub_err, err_context));
        chai_1.expect(method_called).to.be.true;
    });
});
function createMockLogger() {
    return {
        debug: function (_msg, _context) { },
        info: function (_msg, _context) { },
        notice: function (_msg, _context) {
            console.log('asdasd msg: ', _msg);
        },
        warning: function (_msg, _context) { },
        error: function (_msg, _context) { },
        critical: function (_msg, _context) { },
        alert: function (_msg, _context) { },
        emergency: function (_msg, _context) { },
        log: function (_level, _msg, _context) { },
    };
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRNZWRpYXRvclRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJFdmVudE1lZGlhdG9yVGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FtQkc7O0FBRUgsZ0VBQW9FO0FBQ3BFLDZEQUFxRDtBQUNyRCxpQ0FBb0M7QUFDcEMsNkJBQTRCO0FBRzVCLFFBQVEsQ0FBQywrQ0FBK0MsRUFBRTtJQUN4RDtRQUNFLEVBQUMsS0FBSyxFQUFFLG9CQUFvQixFQUFFLElBQUksRUFBRSxRQUFRLEVBQUM7UUFDN0MsRUFBQyxLQUFLLEVBQUUsZUFBZSxFQUFFLElBQUksRUFBRSxRQUFRLEVBQUM7UUFDeEMsRUFBQyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsSUFBSSxFQUFFLFNBQVMsRUFBQztRQUMxQyxFQUFDLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxJQUFJLEVBQUUsU0FBUyxFQUFDO1FBQzFDLEVBQUMsS0FBSyxFQUFFLGtCQUFrQixFQUFFLElBQUksRUFBRSxRQUFRLEVBQUM7UUFDM0MsRUFBQyxLQUFLLEVBQUUsZUFBZSxFQUFFLElBQUksRUFBRSxRQUFRLEVBQUM7UUFDeEMsRUFBQyxLQUFLLEVBQUUsZUFBZSxFQUFFLElBQ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