import { describe, it, expect, vi, beforeEach } from 'vitest';
import { api } from '@/api/client';

describe('api client', () => {
  beforeEach(() => {
    vi.restoreAllMocks();
  });

  it('health fetches from /api/health', async () => {
    const mock = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
      new Response(JSON.stringify({ status: 'ok', db: true }), {
        status: 200,
        headers: { 'Content-Type': 'application/json' },
      }),
    );
    const result = await api.health();
    expect(mock).toHaveBeenCalledWith('/api/health', expect.any(Object));
    expect(result).toEqual({ status: 'ok', db: true });
  });
});
