import { describe, it, expect, vi, beforeEach } from 'vitest';
import { getScanStatus, triggerScan } from './admin';

vi.mock('./client', () => ({
  api: { get: vi.fn(), post: vi.fn() }
}));

import { api } from './client';

describe('admin scan API', () => {
  beforeEach(() => vi.clearAllMocks());

  it('getScanStatus GETs the correct path', async () => {
    (api.get as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
      id: 's1', started_at: '2026-05-04T00:00:00Z', finished_at: null, in_flight: true
    });
    const got = await getScanStatus();
    expect(api.get).toHaveBeenCalledWith('/api/admin/scan/status');
    expect(got.in_flight).toBe(true);
  });

  it('triggerScan POSTs an empty body to /run', async () => {
    (api.post as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ id: 's2' });
    const got = await triggerScan();
    expect(api.post).toHaveBeenCalledWith('/api/admin/scan/run', {});
    expect(got.id).toBe('s2');
  });
});
