All checks were successful
CI / Unit & Component Tests (pull_request) Successful in 3m25s
CI / OCR Service Tests (pull_request) Successful in 21s
CI / Backend Unit Tests (pull_request) Successful in 3m23s
CI / fail2ban Regex (pull_request) Successful in 41s
CI / Semgrep Security Scan (pull_request) Successful in 20s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m2s
`@sentry/sveltekit` wraps load functions and reads `event.request.method` and `event.url.pathname`. Mock events that omitted `request` or `url` threw `TypeError: Cannot read properties of undefined` on every invocation, silently masking 86 test failures on main. Two root causes fixed: - Added `request: new Request(...)` (and `url: new URL(...)` where absent) to all mock event objects in 14 `*.server.spec.ts` files - Changed `;` to `&&` in the `test:coverage` npm script so a failing server run propagates its exit code instead of being swallowed by the client run All 576 server-project tests now pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 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 }));
|
|
|
|
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 });
|
|
});
|
|
});
|