import { type Message } from '../../../../shared-kernel';
import { groupMessagesByRoom } from './notifications.effects';

function createMessage(overrides: Partial<Message> = {}): Message {
  return {
    id: 'message-1',
    roomId: 'room-1',
    senderId: 'user-1',
    senderName: 'User 1',
    content: 'hello',
    timestamp: 1,
    reactions: [],
    isDeleted: false,
    ...overrides
  };
}

describe('groupMessagesByRoom', () => {
  it('groups sync batches by room id', () => {
    const grouped = groupMessagesByRoom([
      createMessage({ id: 'a1', roomId: 'room-a' }),
      createMessage({ id: 'b1', roomId: 'room-b' }),
      createMessage({ id: 'a2', roomId: 'room-a' })
    ]);

    expect(Array.from(grouped.keys())).toEqual(['room-a', 'room-b']);
    expect(grouped.get('room-a')?.map((message) => message.id)).toEqual(['a1', 'a2']);
    expect(grouped.get('room-b')?.map((message) => message.id)).toEqual(['b1']);
  });

  it('returns empty map for empty sync batch', () => {
    expect(groupMessagesByRoom([]).size).toBe(0);
  });
});
