import { isUnlimitedSeats, normalizeTabPermissions, SEAT_UNLIMITED_THRESHOLD } from './permissions';

describe('normalizeTabPermissions', () => {
  it('adds READ when EDIT is present', () => {
    expect(normalizeTabPermissions(['TAB_PATIENTS_EDIT'])).toEqual([
      'TAB_PATIENTS_READ',
      'TAB_PATIENTS_EDIT',
    ]);
  });

  it('dedupes and sorts', () => {
    expect(
      normalizeTabPermissions([
        'TAB_TODAY_READ',
        'TAB_TODAY_EDIT',
        'TAB_TODAY_READ',
        'bogus',
      ]),
    ).toEqual(['TAB_TODAY_READ', 'TAB_TODAY_EDIT']);
  });

  it('accepts empty array', () => {
    expect(normalizeTabPermissions([])).toEqual([]);
  });
});

describe('isUnlimitedSeats', () => {
  it('treats sentinel as unlimited', () => {
    expect(isUnlimitedSeats(SEAT_UNLIMITED_THRESHOLD)).toBe(true);
    expect(isUnlimitedSeats(SEAT_UNLIMITED_THRESHOLD + 1)).toBe(true);
  });

  it('treats normal caps as limited', () => {
    expect(isUnlimitedSeats(5)).toBe(false);
    expect(isUnlimitedSeats(15)).toBe(false);
  });
});
