import { buildSignalingUser } from './rooms.helpers';

describe('buildSignalingUser - status', () => {
  it('defaults to online when no status provided', () => {
    const user = buildSignalingUser({ oderId: 'u1', displayName: 'Alice' });

    expect(user.status).toBe('online');
  });

  it('uses away status when provided', () => {
    const user = buildSignalingUser({ oderId: 'u1', displayName: 'Alice', status: 'away' });

    expect(user.status).toBe('away');
  });

  it('uses busy status when provided', () => {
    const user = buildSignalingUser({ oderId: 'u1', displayName: 'Bob', status: 'busy' });

    expect(user.status).toBe('busy');
  });

  it('ignores invalid status and defaults to online', () => {
    const user = buildSignalingUser({ oderId: 'u1', displayName: 'Eve', status: 'invalid' });

    expect(user.status).toBe('online');
  });

  it('maps offline status to disconnected', () => {
    const user = buildSignalingUser({ oderId: 'u1', displayName: 'Ghost', status: 'offline' });

    expect(user.status).toBe('disconnected');
  });

  it('allows extras to override status', () => {
    const user = buildSignalingUser(
      { oderId: 'u1', displayName: 'Dave', status: 'away' },
      { status: 'busy' }
    );

    expect(user.status).toBe('busy');
  });

  it('preserves other fields', () => {
    const user = buildSignalingUser(
      { oderId: 'u1', displayName: 'Alice', status: 'away' },
      { presenceServerIds: ['server-1'] }
    );

    expect(user.oderId).toBe('u1');
    expect(user.id).toBe('u1');
    expect(user.displayName).toBe('Alice');
    expect(user.isOnline).toBe(true);
    expect(user.role).toBe('member');
  });
});
