"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
const LogUC_1 = require("./LogUC");
class MockDispatcher extends AppDispatcher_1.AppDispatcher {
    constructor() {
        super(...arguments);
        this.dispatch = jest.fn();
        this.formRequestAndDispatch = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const dispatcher = appObjects.getOrCreate("Dispatcher");
    const mockDispatcher = new MockDispatcher(dispatcher, AppDispatcher_1.AppDispatcher.type);
    const uc = (0, LogUC_1.makeLogUC)(dispatcher);
    return { uc, dispatcher, appObjects, mockDispatcher };
}
describe("Dispatch a Log", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(LogUC_1.LogUC.get(appObjects)).toEqual(uc);
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchLog("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy.mock.calls[0][0]).toEqual(uc.requestType);
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchLog("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy.mock.calls[0][1]).toEqual(1);
    });
    it("Dispatches the correct sender", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchLog("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        const payload = spy.mock.calls[0][2];
        expect(payload.sender).toEqual("Sender");
    });
    it("Dispatches the correct message", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchLog("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        const payload = spy.mock.calls[0][2];
        expect(payload.message).toEqual("Message");
    });
    it("Dispatches the correct severity for a Log", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchLog("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        const payload = spy.mock.calls[0][2];
        expect(payload.severity).toEqual("LOG");
    });
    it("Dispatches the correct severity for a Warning", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchWarn("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        const payload = spy.mock.calls[0][2];
        expect(payload.severity).toEqual("WARNING");
    });
    it("Dispatches the correct severity for a Warning", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchError("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        const payload = spy.mock.calls[0][2];
        expect(payload.severity).toEqual("ERROR");
    });
    it("Dispatches the correct severity for a Fatal Error", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.dispatchFatal("Sender", "Message");
        expect(spy).toHaveBeenCalledTimes(1);
        const payload = spy.mock.calls[0][2];
        expect(payload.severity).toEqual("FATAL");
    });
});
//# sourceMappingURL=LogUC.test.js.map