Files
familienarchiv/frontend/src/routes/admin/ocr/global/page.server.spec.ts
Marcel 567f9267e8 fix(tests): add missing Sentry mock event fields across 14 spec files; fix test:coverage semicolon
`@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>
2026-05-19 13:33:07 +02:00

38 lines
1.0 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/global — load', () => {
it('returns history from API', async () => {
mockApi.GET.mockResolvedValue({
response: { ok: true },
data: { runs: [{ id: 'run1' }], personNames: {} }
});
const result = (await load({
fetch,
request: new Request('http://localhost/admin/ocr/global'),
url: new URL('http://localhost/admin/ocr/global')
} as never))!;
expect(result.history.runs).toHaveLength(1);
});
it('throws error when API call fails', async () => {
mockApi.GET.mockResolvedValue({ response: { ok: false, status: 500 }, error: {} });
await expect(
load({
fetch,
request: new Request('http://localhost/admin/ocr/global'),
url: new URL('http://localhost/admin/ocr/global')
} as never)
).rejects.toMatchObject({ status: 500 });
});
});