import { resolveAuthenticationMode } from './resolve-authentication-mode';

describe('resolveAuthenticationMode', () => {
  it('defaults to "none" when the value is undefined', () => {
    expect(resolveAuthenticationMode(undefined)).toBe('none');
  });

  it('defaults to "none" when the value is an empty string', () => {
    expect(resolveAuthenticationMode('')).toBe('none');
  });

  it('defaults to "none" when the value is blank whitespace', () => {
    expect(resolveAuthenticationMode('   ')).toBe('none');
  });

  it('accepts "none" and returns "none"', () => {
    expect(resolveAuthenticationMode('none')).toBe('none');
  });

  it('accepts "aurora-hub" and returns "aurora-hub"', () => {
    expect(resolveAuthenticationMode('aurora-hub')).toBe('aurora-hub');
  });

  it('accepts "local-provider" and returns "local-provider"', () => {
    expect(resolveAuthenticationMode('local-provider')).toBe('local-provider');
  });

  it('throws an error for an invalid value listing the three valid values', () => {
    expect(() => resolveAuthenticationMode('does-not-exist')).toThrow(
      /none.*aurora-hub.*local-provider|aurora-hub.*none|local-provider.*none/i,
    );
  });

  it('throws a descriptive error that names the invalid value', () => {
    expect(() => resolveAuthenticationMode('invalid-mode')).toThrow('invalid-mode');
  });

  it('trims whitespace before resolving', () => {
    expect(resolveAuthenticationMode('  aurora-hub  ')).toBe('aurora-hub');
  });
});
