05bc2628a3
Adds getScanStatus/triggerScan helpers, createScanStatusQuery factory (3s poll), qk.scanStatus(), and a Library Scan section on the admin overview page with per-stage tallies and inline Run scan button. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
984 B
TypeScript
29 lines
984 B
TypeScript
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');
|
|
});
|
|
});
|