"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("./AppDispatcher");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const dispatcherAO = appObjects.getOrCreate("appDispatcher");
    const mockHandler = jest.fn();
    const dispatcher = (0, AppDispatcher_1.makeAppDispatcher)(dispatcherAO, mockHandler);
    return { dispatcher, appObjects, mockHandler };
}
describe("App Dispatcher Entity", () => {
    it("Gets the App Dispatcher", () => {
        const { dispatcher, appObjects } = makeTestRig();
        expect(AppDispatcher_1.AppDispatcher.get(appObjects)).toEqual(dispatcher);
    });
    it("Dispatches to the host", () => {
        const { dispatcher, mockHandler } = makeTestRig();
        const request = {
            type: "a type",
            version: 1,
            payload: { foo: "bar" },
        };
        dispatcher.dispatch(request);
        expect(mockHandler).toHaveBeenCalledWith(request);
    });
    it("Forms and dispatches a request", () => {
        const { dispatcher, mockHandler } = makeTestRig();
        const request = {
            type: "a type",
            version: 1,
            payload: { foo: "bar" },
        };
        dispatcher.formRequestAndDispatch("a type", 1, { foo: "bar" });
        expect(mockHandler).toHaveBeenCalledWith(request);
    });
});
//# sourceMappingURL=AppDispatcher.test.js.map