import { NotificationsGateway } from './notifications.gateway';

describe('NotificationsGateway realtime events', () => {
  it('emits backward-compatible and new notification events to the recipient room', () => {
    const gateway = new NotificationsGateway({} as any, {} as any, {} as any);
    const roomEmitter = { emit: jest.fn() };
    (gateway as any).server = {
      to: jest.fn().mockReturnValue(roomEmitter),
    };
    const notification = { _id: 'notification-1', type: 'message' };
    const unreadCounts = {
      total: 3,
      interactions: 1,
      messages: 2,
      follows: 0,
      followRequests: 0,
      collaboration: 0,
      system: 0,
    };

    gateway.emitCreated('user-1', notification, 3, unreadCounts);

    expect((gateway as any).server.to).toHaveBeenCalledWith('user:user-1');
    expect(roomEmitter.emit).toHaveBeenCalledWith('notification_created', notification);
    expect(roomEmitter.emit).toHaveBeenCalledWith('notifications_unread_count', { unreadCount: 3 });
    expect(roomEmitter.emit).toHaveBeenCalledWith('notification:new', notification);
    expect(roomEmitter.emit).toHaveBeenCalledWith('notification:unread_counts', unreadCounts);
  });
});
