/**
 * @vitest-environment happy-dom
 */
import { beforeEach, describe, expect, it } from 'vitest';
import { authHeaders, clearStoredAuth, getStoredAuth, setStoredAuth } from '../api/auth';

describe('auth session helpers', () => {
  beforeEach(() => {
    sessionStorage.clear();
  });

  it('stores and retrieves basic token', () => {
    setStoredAuth('drjones', 'secret');
    expect(getStoredAuth()).toBe(btoa('drjones:secret'));
  });

  it('builds Authorization header when logged in', () => {
    setStoredAuth('user', 'pass');
    expect(authHeaders()).toEqual({ Authorization: `Basic ${btoa('user:pass')}` });
  });

  it('returns empty headers when logged out', () => {
    clearStoredAuth();
    expect(authHeaders()).toEqual({});
  });
});
