"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockDispatcher_1 = require("../Mocks/MockDispatcher");
const IsAssetFetchedUC_1 = require("./IsAssetFetchedUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObject = appObjects.getOrCreate("Dispatcher");
    const mockDispatcher = new MockDispatcher_1.MockDispatcher(appObject);
    const uc = (0, IsAssetFetchedUC_1.makeIsAssetFetchedUC)(appObject);
    return { uc, dispatcher: appObject, appObjects, mockDispatcher };
}
describe("Get App Asset URL UC", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(IsAssetFetchedUC_1.IsAssetFetchedUC.get(appObjects)).toEqual(uc);
    });
    it("Finds and dispatches to the UC", async () => {
        const { appObjects, uc } = makeTestRig();
        uc.doDispatch = jest.fn();
        await (0, IsAssetFetchedUC_1.isAssetFetched)("asset1", appObjects);
        expect(uc.doDispatch).toHaveBeenCalledWith("asset1");
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch("asset1");
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][0]).toEqual("IS_ASSET_FILE_FETCHED");
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch("asset1");
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][1]).toEqual(1);
    });
    it("Dispatches a payload", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch("asset1");
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).not.toBeUndefined();
    });
    it("Dispatches resolves with some meta", async () => {
        const { uc, mockDispatcher } = makeTestRig();
        const dispatcher = mockDispatcher;
        const mockURL = "some.url";
        dispatcher.formRequestAndDispatch = (type, version, payload) => {
            if (!payload)
                return;
            const cb = payload.callback;
            if (!cb)
                return;
            cb(true);
        };
        const url = await uc.doDispatch("asset1");
        expect(url).toEqual(true);
    });
});
//# sourceMappingURL=IsAssetFetchedUC.test.js.map