import { makeAppObjectRepo } from "@vived/core";
import { MockDispatcher } from "../Mocks/MockDispatcher";
import { makeSubmitResultUC, submitHitResult, submitMultiHitResult, submitProgressResult, submitQualityResult, SubmitResultResultUC, submitScoreResult, } from "./SubmitResultResultUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const dispatcherAO = appObjects.getOrCreate("dispatcher");
    const mockDispatcher = new MockDispatcher(dispatcherAO);
    const uc = makeSubmitResultUC(dispatcherAO);
    return {
        uc,
        mockDispatcher,
        appObjects,
    };
}
describe("Registers external stylesheets", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(SubmitResultResultUC.get(appObjects)).toEqual(uc);
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const data = {
            description: "Hello World",
            success: true,
        };
        uc.submitHitResult(data);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][0]).toEqual("SUBMIT_RESULTS");
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const data = {
            description: "Hello World",
            success: true,
        };
        uc.submitHitResult(data);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][1]).toEqual(3);
    });
    it("Dispatches the expected payload for a hit", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const data = {
            description: "Hello World",
            success: true,
        };
        uc.submitHitResult(data);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).toEqual({
            resultType: "HIT_V1",
            description: "Hello World",
            result: {
                success: true,
            },
        });
    });
    it("Finds and dispatches a Hit to the UC", () => {
        const { appObjects, uc } = makeTestRig();
        uc.submitHitResult = jest.fn();
        const data = {
            description: "Hello World",
            success: true,
        };
        submitHitResult(data, appObjects);
        expect(uc.submitHitResult).toHaveBeenCalledWith(data);
    });
    it("Dispatches the expected payload for a progress", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const data = {
            description: "Hello World",
            progress: 0.5,
        };
        uc.submitProgressResult(data);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).toEqual({
            resultType: "PROGRESS_V1",
            description: "Hello World",
            result: {
                progress: 0.5,
            },
        });
    });
    it("Finds and dispatches a progress to the UC", () => {
        const { appObjects, uc } = makeTestRig();
        uc.submitProgressResult = jest.fn();
        const data = {
            description: "Hello World",
            progress: 0.5,
        };
        submitProgressResult(data, appObjects);
        expect(uc.submitProgressResult).toHaveBeenCalledWith(data);
    });
    it("Dispatches the expected payload for a multi hit", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const data = {
            description: "Hello World",
            hits: 1,
            misses: 2,
            unanswered: 3,
        };
        uc.submitMultiHitResult(data);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).toEqual({
            resultType: "MULTIHIT_V1",
            description: "Hello World",
            result: {
                hits: 1,
                misses: 2,
                unanswered: 3,
            },
        });
    });
    it("Finds and dispatches a multi hit to the UC", () => {
        const { appObjects, uc } = makeTestRig();
        uc.submitMultiHitResult = jest.fn();
        const data = {
            description: "Hello World",
            hits: 1,
            misses: 2,
            unanswered: 3,
        };
        submitMultiHitResult(data, appObjects);
        expect(uc.submitMultiHitResult).toHaveBeenCalledWith(data);
    });
    it("Dispatches the expected payload for quality", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const data = {
            description: "Hello World",
            maxStars: 10,
            stars: 5,
        };
        uc.submitQualityResult(data);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).toEqual({
            resultType: "QUALITY_V1",
            description: "Hello World",
            result: {
                maxStars: 10,
                stars: 5,
            },
        });
    });
    it("Finds and dispatches a quality to the UC", () => {
        const { appObjects, uc } = makeTestRig();
        uc.submitQualityResult = jest.fn();
        const data = {
            description: "Hello World",
            maxStars: 10,
            stars: 5,
        };
        submitQualityResult(data, appObjects);
        expect(uc.submitQualityResult).toHaveBeenCalledWith(data);
    });
    it("Dispatches the expected payload for score", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const data = {
            description: "Hello World",
            maxScore: 10,
            score: 5,
        };
        uc.submitScoreResult(data);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).toEqual({
            resultType: "SCORE_V1",
            description: "Hello World",
            result: {
                maxScore: 10,
                score: 5,
            },
        });
    });
    it("Finds and dispatches a score to the UC", () => {
        const { appObjects, uc } = makeTestRig();
        uc.submitScoreResult = jest.fn();
        const data = {
            description: "Hello World",
            maxScore: 10,
            score: 5,
        };
        submitScoreResult(data, appObjects);
        expect(uc.submitScoreResult).toHaveBeenCalledWith(data);
    });
});
//# sourceMappingURL=SubmitResultResultUC.test.js.map