import { describe, it, expect } from 'vitest';
import { buildAuthHeaders } from './client-factory.js';

describe('buildAuthHeaders', () => {
  it('uses Authorization: Bearer by default for api_key without custom header', () => {
    expect(buildAuthHeaders({ authKind: 'api_key', authHeaderName: null }, 'tok')).toEqual({
      Authorization: 'Bearer tok',
    });
  });

  it('sends the token verbatim under a custom header for api_key', () => {
    expect(
      buildAuthHeaders({ authKind: 'api_key', authHeaderName: 'xc-mcp-token' }, 'secret-123'),
    ).toEqual({ 'xc-mcp-token': 'secret-123' });
  });

  it('always uses Authorization: Bearer for oauth, ignoring any header name', () => {
    expect(
      buildAuthHeaders({ authKind: 'oauth', authHeaderName: 'xc-mcp-token' }, 'oauth-at'),
    ).toEqual({ Authorization: 'Bearer oauth-at' });
  });

  it('falls back to Bearer when custom header name is an empty string', () => {
    expect(buildAuthHeaders({ authKind: 'api_key', authHeaderName: '' }, 'tok')).toEqual({
      Authorization: 'Bearer tok',
    });
  });
});
