Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

957 B
Raw Blame
import axios from 'axios';
import { getTokenHeader, setTokenHeader } from '../src/headers-helpers';

describe('setTokenHeader', () => {
  afterEach(() => {
    delete axios.defaults.headers.common['Authorization'];
  });

  it('sets the Authorization header with a Bearer token', () => {
    setTokenHeader('my-token');
    expect(axios.defaults.headers.common['Authorization']).toBe('Bearer my-token');
    expect(getTokenHeader()).toBe('Bearer my-token');
  });

  it('deletes the Authorization header when called with undefined', () => {
    axios.defaults.headers.common['Authorization'] = 'Bearer old-token';
    setTokenHeader(undefined);
    expect(axios.defaults.headers.common['Authorization']).toBeUndefined();
    expect(getTokenHeader()).toBeUndefined();
  });

  it('is a no-op when clearing an already absent header', () => {
    setTokenHeader(undefined);
    expect(axios.defaults.headers.common['Authorization']).toBeUndefined();
  });
});