All checks were successful
CI / Unit & Component Tests (push) Successful in 3m31s
CI / OCR Service Tests (push) Successful in 19s
CI / Backend Unit Tests (push) Successful in 3m29s
CI / fail2ban Regex (push) Successful in 40s
CI / Semgrep Security Scan (push) Successful in 20s
CI / Compose Bucket Idempotency (push) Successful in 1m0s
All route spec files that mock $lib/shared/api.server were missing extractErrorCode from the mock factory, causing a vitest "No export defined" error after the refactor introduced the new export. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { load } from './+page.server';
|
|
|
|
const mockApi = { GET: vi.fn() };
|
|
|
|
vi.mock('$lib/shared/api.server', () => ({
|
|
createApiClient: () => mockApi,
|
|
extractErrorCode: (e: unknown) => (e as { code?: string } | undefined)?.code
|
|
}));
|
|
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
describe('admin/ocr — load', () => {
|
|
it('returns trainingInfo from API', async () => {
|
|
mockApi.GET.mockResolvedValue({
|
|
response: { ok: true },
|
|
data: { availableBlocks: 10, ocrServiceAvailable: true, senderModels: [] }
|
|
});
|
|
|
|
const result = (await load({
|
|
fetch,
|
|
request: new Request('http://localhost/admin/ocr'),
|
|
url: new URL('http://localhost/admin/ocr')
|
|
} as never))!;
|
|
|
|
expect(result.trainingInfo.availableBlocks).toBe(10);
|
|
expect(result.trainingInfo.ocrServiceAvailable).toBe(true);
|
|
});
|
|
|
|
it('throws 503 when OCR API call fails', async () => {
|
|
mockApi.GET.mockResolvedValue({ response: { ok: false, status: 503 }, error: {} });
|
|
|
|
await expect(
|
|
load({
|
|
fetch,
|
|
request: new Request('http://localhost/admin/ocr'),
|
|
url: new URL('http://localhost/admin/ocr')
|
|
} as never)
|
|
).rejects.toMatchObject({ status: 503 });
|
|
});
|
|
});
|