import { makeAppObjectRepo } from "@vived/core";
import { makeBaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { MockAppHandlerEntity } from "../Mocks/MockAppHandlerEntity";
import { makeSetIsAuthoringUC } from "./SetIsAuthoringUC";
function makeTestRig() {
    const appObjectRepo = makeAppObjectRepo();
    const handlerAO = appObjectRepo.getOrCreate("Handler");
    const mockAppHandler = new MockAppHandlerEntity(handlerAO);
    const setIsAuthoring = makeSetIsAuthoringUC(handlerAO);
    const baseApp = makeBaseAppState(handlerAO);
    return { mockAppHandler, setIsAuthoring, baseApp };
}
describe("Set is authoring Base Handler", () => {
    it("Registers as a handler when constructed", () => {
        const { setIsAuthoring, mockAppHandler } = makeTestRig();
        expect(mockAppHandler.registerRequestHandler).toHaveBeenCalledWith(setIsAuthoring);
    });
    it("Triggers the action for v1 if the payload is true", () => {
        const { setIsAuthoring } = makeTestRig();
        setIsAuthoring.action = jest.fn();
        setIsAuthoring.handleRequest(1, { isAuthoring: true });
        expect(setIsAuthoring.action).toHaveBeenCalledWith(true);
    });
    it("Triggers the action for v1 if the payload is false", () => {
        const { setIsAuthoring } = makeTestRig();
        setIsAuthoring.action = jest.fn();
        setIsAuthoring.handleRequest(1, { isAuthoring: false });
        expect(setIsAuthoring.action).toHaveBeenCalledWith(false);
    });
    it("Throws for an bungled payload", () => {
        const { setIsAuthoring } = makeTestRig();
        expect(() => setIsAuthoring.handleRequest(1, { foo: "bar" })).toThrowError();
    });
    it("Throws for an unsupported version", () => {
        const { setIsAuthoring } = makeTestRig();
        expect(() => setIsAuthoring.handleRequest(-1, { isAuthoring: false })).toThrowError();
    });
    it("Sets base app to is authoring", () => {
        const { baseApp, setIsAuthoring } = makeTestRig();
        expect(baseApp.isAuthoring).toEqual(false);
        setIsAuthoring.action(true);
        expect(baseApp.isAuthoring).toEqual(true);
        setIsAuthoring.action(false);
        expect(baseApp.isAuthoring).toEqual(false);
    });
});
//# sourceMappingURL=SetIsAuthoringUC.test.js.map