"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const EventService_1 = __importDefault(require("./EventService"));
const EventNotFound_1 = require("./error/EventNotFound");
const WalletEvent_1 = require("./WalletEvent");
const EventListenerNotFound_1 = require("./error/EventListenerNotFound");
describe("EventService", () => {
    let eventService;
    beforeEach(() => {
        jest.clearAllMocks();
        eventService = new EventService_1.default(WalletEvent_1.WalletEvents);
    });
    afterEach(() => {
        jest.clearAllMocks();
    });
    describe("constructor and registerEvents", () => {
        it("should initialize with registered events", () => {
            expect(eventService.eventNames()).toEqual(Object.keys(WalletEvent_1.WalletEvents));
        });
    });
    describe("getEventEmitter", () => {
        it("should throw EventNotFound for an unregistered event", () => {
            expect(() => eventService.getEventEmitter("invalidEvent")).toThrow(EventNotFound_1.EventNotFound);
            expect(() => eventService.getEventEmitter("invalidEvent")).toThrow("WalletEvent (invalidEvent) not registered yet");
        });
    });
    describe("on", () => {
        it("should throw EventListenerNotFound for an unregistered event", () => {
            const listener = jest.fn();
            const invalidEvent = "invalidEvent";
            expect(() => eventService.on(invalidEvent, listener)).toThrow(EventListenerNotFound_1.EventListenerNotFound);
            expect(() => eventService.on(invalidEvent, listener)).toThrow(invalidEvent);
        });
    });
    describe("emit", () => {
        it("should throw EventNotFound for an unregistered event", () => {
            const invalidEvent = "invalidEvent";
            const data = {};
            expect(() => eventService.emit(invalidEvent, data)).toThrow(EventNotFound_1.EventNotFound);
            expect(() => eventService.emit(invalidEvent, data)).toThrow(`WalletEvent (${invalidEvent}) not registered yet`);
        });
    });
    describe("eventNames", () => {
        it("should return all registered event names", () => {
            const result = eventService.eventNames();
            expect(result).toEqual(Object.keys(WalletEvent_1.WalletEvents));
            expect(result).toContain(WalletEvent_1.WalletEvents.walletInit);
            expect(result).toContain(WalletEvent_1.WalletEvents.walletPaired);
        });
    });
});
