import { makeAppObjectRepo } from "@vived/core";
import { MockDispatcher } from "../Mocks/MockDispatcher";
import { getLinkedAssets, GetLinkedAssetsUC, makeGetLinkedAssetsUC, } from "./GetLinkedAssetsUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObject = appObjects.getOrCreate("Dispatcher");
    const mockDispatcher = new MockDispatcher(appObject);
    const uc = makeGetLinkedAssetsUC(appObject);
    return { uc, dispatcher: appObject, appObjects, mockDispatcher };
}
describe("Get Linked Assets UC", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(GetLinkedAssetsUC.get(appObjects)).toEqual(uc);
    });
    it("Finds and dispatches to the UC", async () => {
        const { appObjects, uc } = makeTestRig();
        uc.doDispatch = jest.fn();
        await getLinkedAssets("asset1", "assetType", appObjects);
        expect(uc.doDispatch).toHaveBeenCalledWith("asset1", "assetType");
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch("asset1", "assetType");
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][0]).toEqual("GET_LINKED_ASSETS");
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch("asset1", "assetType");
        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", "assetType");
        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 mockMeta = {
            id: "anID",
            name: "a name",
            description: "a desc",
        };
        dispatcher.formRequestAndDispatch = (type, version, payload) => {
            if (!payload)
                return;
            const cb = payload.callback;
            if (!cb)
                return;
            cb([mockMeta]);
        };
        const meta = await uc.doDispatch("asset1", "assetType");
        expect(meta).toEqual([mockMeta]);
    });
});
//# sourceMappingURL=GetLinkedAssetsUC.test.js.map