import { isPersonSource, PERSON_SOURCES, type PersonSource } from './person-source';

describe('PERSON_SOURCES', () => {
  it('contains the three v1 sources from ADR-0026', () => {
    expect(PERSON_SOURCES).toEqual(['self-signin', 'admin-ui', 'seed']);
  });

  it('has no duplicate entries', () => {
    expect(new Set(PERSON_SOURCES).size).toBe(PERSON_SOURCES.length);
  });
});

describe('isPersonSource', () => {
  it('returns true for every catalogue value', () => {
    for (const source of PERSON_SOURCES) {
      expect(isPersonSource(source)).toBe(true);
    }
  });

  it('returns false for values outside the catalogue', () => {
    // future ADR-0029 values, not shipped in v1
    expect(isPersonSource('pleiades')).toBe(false);
    expect(isPersonSource('acteurs-plus')).toBe(false);
    // common typos / casing variations
    expect(isPersonSource('self_signin')).toBe(false);
    expect(isPersonSource('Self-Signin')).toBe(false);
    expect(isPersonSource('')).toBe(false);
  });

  it('narrows the type at the call site', () => {
    const candidate = String('self-signin');
    if (!isPersonSource(candidate)) {
      throw new Error('unreachable — candidate is a known source');
    }
    const narrowed: PersonSource = candidate;
    expect(narrowed).toBe('self-signin');
  });
});
