fix(tests): add missing Sentry mock event fields across 14 spec files; fix test:coverage semicolon
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>
This commit is contained in:
Marcel
2026-05-19 10:27:11 +02:00
parent 741b2231f2
commit 07415a5b2b
15 changed files with 282 additions and 46 deletions

View File

@@ -6,7 +6,11 @@ describe('/documents/bulk-edit +page.server.ts', () => {
const locals = { user: { groups: [{ permissions: ['READ_ALL'] }] } };
try {
// @ts-expect-error — partial event shape sufficient for this guard
await load({ locals });
await load({
locals,
request: new Request('http://localhost/documents/bulk-edit'),
url: new URL('http://localhost/documents/bulk-edit')
});
throw new Error('expected redirect to be thrown');
} catch (e) {
const err = e as { status?: number; location?: string };
@@ -19,7 +23,11 @@ describe('/documents/bulk-edit +page.server.ts', () => {
const locals = { user: { groups: [] } };
try {
// @ts-expect-error — partial event shape sufficient for this guard
await load({ locals });
await load({
locals,
request: new Request('http://localhost/documents/bulk-edit'),
url: new URL('http://localhost/documents/bulk-edit')
});
throw new Error('expected redirect');
} catch (e) {
expect((e as { status?: number }).status).toBe(303);
@@ -30,7 +38,11 @@ describe('/documents/bulk-edit +page.server.ts', () => {
const locals = {};
try {
// @ts-expect-error — partial event shape sufficient for this guard
await load({ locals });
await load({
locals,
request: new Request('http://localhost/documents/bulk-edit'),
url: new URL('http://localhost/documents/bulk-edit')
});
throw new Error('expected redirect');
} catch (e) {
expect((e as { status?: number }).status).toBe(303);
@@ -40,7 +52,11 @@ describe('/documents/bulk-edit +page.server.ts', () => {
it('returns canWrite=true for a WRITE_ALL user', async () => {
const locals = { user: { groups: [{ permissions: ['WRITE_ALL', 'READ_ALL'] }] } };
// @ts-expect-error — partial event shape sufficient for this guard
const result = await load({ locals });
const result = await load({
locals,
request: new Request('http://localhost/documents/bulk-edit'),
url: new URL('http://localhost/documents/bulk-edit')
});
expect(result).toEqual({ canWrite: true });
});
@@ -52,7 +68,11 @@ describe('/documents/bulk-edit +page.server.ts', () => {
};
try {
// @ts-expect-error — partial event shape sufficient for this guard
await load({ locals });
await load({
locals,
request: new Request('http://localhost/documents/bulk-edit'),
url: new URL('http://localhost/documents/bulk-edit')
});
throw new Error('expected redirect');
} catch (e) {
expect((e as { status?: number }).status).toBe(303);