All checks were successful
CI / Unit & Component Tests (pull_request) Successful in 3m24s
CI / OCR Service Tests (pull_request) Successful in 22s
CI / Backend Unit Tests (pull_request) Successful in 3m19s
CI / fail2ban Regex (pull_request) Successful in 41s
CI / Semgrep Security Scan (pull_request) Successful in 21s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m2s
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>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 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/[personId] — load', () => {
|
|
it('returns sender history from API', async () => {
|
|
const personId = '123e4567-e89b-12d3-a456-426614174000';
|
|
mockApi.GET.mockResolvedValue({
|
|
response: { ok: true },
|
|
data: { runs: [], personNames: { [personId]: 'Anna Müller' } }
|
|
});
|
|
|
|
const result = (await load({
|
|
params: { personId },
|
|
fetch,
|
|
request: new Request('http://localhost/admin/ocr/123'),
|
|
url: new URL('http://localhost/admin/ocr/123')
|
|
} as never))!;
|
|
|
|
expect(result.history.personNames?.[personId]).toBe('Anna Müller');
|
|
});
|
|
|
|
it('throws 404 when person not found', async () => {
|
|
mockApi.GET.mockResolvedValue({
|
|
response: { ok: false, status: 404 },
|
|
error: { code: 'PERSON_NOT_FOUND' }
|
|
});
|
|
|
|
await expect(
|
|
load({
|
|
params: { personId: 'unknown-id' },
|
|
fetch,
|
|
request: new Request('http://localhost/admin/ocr/unknown-id'),
|
|
url: new URL('http://localhost/admin/ocr/unknown-id')
|
|
} as never)
|
|
).rejects.toMatchObject({ status: 404 });
|
|
});
|
|
});
|