import { afterEach, beforeEach, describe, expect, test } from 'vitest';
import { getOrCreateClientId } from './clientId';

beforeEach(() => sessionStorage.clear());
afterEach(() => sessionStorage.clear());

describe('getOrCreateClientId', () => {
  test('generates a UUID on first call and persists it in sessionStorage', () => {
    const id = getOrCreateClientId();
    expect(id).toMatch(/^[0-9a-f-]{36}$/);
    expect(sessionStorage.getItem('minstrel.client_id')).toBe(id);
  });

  test('returns the same id on subsequent calls', () => {
    const a = getOrCreateClientId();
    const b = getOrCreateClientId();
    expect(a).toBe(b);
  });
});
