// SPDX-License-Identifier: Apache-2.0
import { createMock } from "@golevelup/ts-jest";
import EventInPort from "./Event";
import { WalletEvents } from "../../../app/service/event/WalletEvent";
import LogService from "../../../app/service/log/LogService";
describe("Event", () => {
    let networkServiceMock;
    let eventServiceMock;
    beforeEach(() => {
        networkServiceMock = createMock();
        eventServiceMock = createMock({
            on: jest.fn().mockResolvedValue(undefined),
        });
        EventInPort.networkService = networkServiceMock;
        EventInPort.eventService = eventServiceMock;
        jest.spyOn(LogService, "logError").mockImplementation(() => { });
    });
    afterEach(() => {
        jest.resetAllMocks();
        jest.restoreAllMocks();
    });
    describe("register", () => {
        it("should register events with eventService", async () => {
            const mockCallback = jest.fn();
            const events = {
                [WalletEvents.walletInit]: mockCallback,
            };
            EventInPort.register(events);
            expect(eventServiceMock.on).toHaveBeenCalledWith(WalletEvents.walletInit, mockCallback);
            expect(eventServiceMock.on).toHaveBeenCalledTimes(1);
        });
        it("should ignore events not in WalletEvents", async () => {
            const mockCallback = jest.fn();
            const events = {
                invalidEvent: mockCallback,
            };
            EventInPort.register(events);
            expect(eventServiceMock.on).not.toHaveBeenCalled();
        });
    });
});
