import { describe, expect, it } from 'vitest';
import { isExternalIdentity, pickManagementLoginError } from '../../src/lib/admin-auth';

describe('admin-auth helpers (vitest)', () => {
  it('returns wrong portal message with highest priority', () => {
    expect(pickManagementLoginError({ error_code: 'WRONG_PORTAL', message: 'Ignore me' })).toBe(
      'This login is only for internal management users. External users must use the public login page.',
    );
  });

  it('detects external identities from multiple payload shapes', () => {
    expect(isExternalIdentity({ audience: 'public' })).toBe(true);
    expect(isExternalIdentity({ user: { user_type: 'external_user' } })).toBe(true);
    expect(isExternalIdentity({ user: { accountType: 'external' } })).toBe(true);
    expect(isExternalIdentity({ audience: 'admin', user: { userType: 'employee' } })).toBe(false);
  });
});
