"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins_1 = require("../../../src/plugins/plugins");
function makeContext() {
    return {
        Events: {
            on: jest.fn(),
            emit: jest.fn(),
            emitBlocking: jest.fn(),
            emitNonBlocking: jest.fn(),
            log: jest.fn(),
        },
    };
}
describe("PluginService.loadPlugin", () => {
    it("should register the plugin under its meta.key", async () => {
        const service = new plugins_1.PluginService(makeContext());
        const mockKey = "test-plugin";
        service.loadPlugin = jest.fn().mockImplementation(async (_spec) => {
            const instance = {
                meta: { key: mockKey, name: "Test Plugin" },
                isEnabled: () => true,
                enable: () => { },
                disable: () => { },
                call: () => Promise.resolve(""),
                callMany: () => Promise.resolve(""),
                embed: () => Promise.resolve([]),
            };
            service.pluginMap.set(instance.meta.key, instance);
            return instance.meta.key;
        });
        const key = await service.loadPlugin("some-package");
        expect(key).toBe(mockKey);
        expect(service.isPlugin(mockKey)).toBe(true);
    });
    it("should call getPlugin after loading", async () => {
        const service = new plugins_1.PluginService(makeContext());
        const mockKey = "my-plugin";
        service.loadPlugin = jest.fn().mockImplementation(async (_spec) => {
            const instance = {
                meta: { key: mockKey, name: "My Plugin" },
                isEnabled: () => true,
                enable: () => { },
                disable: () => { },
                call: () => Promise.resolve("result"),
                callMany: () => Promise.resolve("result"),
                embed: () => Promise.resolve([]),
            };
            service.pluginMap.set(instance.meta.key, instance);
            return instance.meta.key;
        });
        await service.loadPlugin("./some-path");
        const plugin = service.getPlugin(mockKey);
        expect(plugin).toBeDefined();
        expect(plugin.meta.key).toBe(mockKey);
    });
});
//# sourceMappingURL=pluginLoading.test.js.map