import { describe, expect, it, vi } from 'vitest';
import { fetchEvent, FetchEventError } from '../eventApi';

describe('fetchEvent', () => {
  it('maps guest_limit_exceeded error codes', async () => {
    const originalFetch = global.fetch;
    global.fetch = vi.fn().mockResolvedValue({
      ok: false,
      status: 402,
      json: async () => ({
        error: { code: 'guest_limit_exceeded', message: 'Limit reached' },
      }),
    } as Response);

    await expect(fetchEvent('token')).rejects.toEqual(
      expect.objectContaining<Pick<FetchEventError, 'code'>>({
        code: 'guest_limit_exceeded',
      })
    );

    global.fetch = originalFetch;
  });
});
