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>
This commit is contained in:
Marcel
2026-05-19 10:27:11 +02:00
committed by marcel
parent 1dc5bf4377
commit 567f9267e8
15 changed files with 282 additions and 46 deletions

View File

@@ -23,7 +23,9 @@ describe('document detail load — happy path', () => {
const result = await load({
params: { id: '123' },
fetch: mockFetch as unknown as typeof fetch
fetch: mockFetch as unknown as typeof fetch,
request: new Request('http://localhost/documents/123'),
url: new URL('http://localhost/documents/123')
});
expect(result.document.title).toBe('Testbrief');
@@ -44,7 +46,12 @@ describe('document detail load — error paths', () => {
const mockFetch = vi.fn();
await expect(
load({ params: { id: 'missing' }, fetch: mockFetch as unknown as typeof fetch })
load({
params: { id: 'missing' },
fetch: mockFetch as unknown as typeof fetch,
request: new Request('http://localhost/documents/123'),
url: new URL('http://localhost/documents/123')
})
).rejects.toMatchObject({ status: 404 });
});
@@ -59,7 +66,12 @@ describe('document detail load — error paths', () => {
const mockFetch = vi.fn();
await expect(
load({ params: { id: 'secret' }, fetch: mockFetch as unknown as typeof fetch })
load({
params: { id: 'secret' },
fetch: mockFetch as unknown as typeof fetch,
request: new Request('http://localhost/documents/123'),
url: new URL('http://localhost/documents/123')
})
).rejects.toMatchObject({ status: 403 });
});
@@ -74,7 +86,12 @@ describe('document detail load — error paths', () => {
const mockFetch = vi.fn();
await expect(
load({ params: { id: 'any' }, fetch: mockFetch as unknown as typeof fetch })
load({
params: { id: 'any' },
fetch: mockFetch as unknown as typeof fetch,
request: new Request('http://localhost/documents/123'),
url: new URL('http://localhost/documents/123')
})
).rejects.toMatchObject({ location: '/login' });
});
});

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);

View File

@@ -33,6 +33,7 @@ describe('documents page load — search params', () => {
await load({
url: makeUrl({ q: 'Urlaub', from: '1920-01-01', to: '1950-12-31' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -57,6 +58,7 @@ describe('documents page load — search params', () => {
await load({
url: makeUrl({ senderId: 'p-1', receiverId: 'p-2' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -81,6 +83,7 @@ describe('documents page load — search params', () => {
await load({
url: makeUrl({ sort: 'TITLE', dir: 'asc', tagQ: 'fam' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -111,6 +114,7 @@ describe('documents page load — search params', () => {
const result = await load({
url: makeUrl({ q: 'test' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -129,6 +133,7 @@ describe('documents page load — search params', () => {
const result = await load({
url: makeUrl({ q: 'Urlaub', from: '1920-01-01', sort: 'TITLE', dir: 'asc' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -148,7 +153,11 @@ describe('documents page load — auth redirect', () => {
} as ReturnType<typeof createApiClient>);
await expect(
load({ url: makeUrl(), fetch: vi.fn() as unknown as typeof fetch })
load({
url: makeUrl(),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
})
).rejects.toMatchObject({ location: '/login' });
});
});
@@ -161,7 +170,11 @@ describe('documents page load — network error fallback', () => {
GET: vi.fn().mockRejectedValue(new Error('Network failure'))
} as ReturnType<typeof createApiClient>);
const result = await load({ url: makeUrl(), fetch: vi.fn() as unknown as typeof fetch });
const result = await load({
url: makeUrl(),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
expect(result.error).toBeTruthy();
expect(result.items).toEqual([]);
@@ -199,6 +212,7 @@ describe('documents page load — person name resolution', () => {
const result = await load({
url: makeUrl({ senderId: '11111111-1111-1111-1111-111111111111' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -210,6 +224,7 @@ describe('documents page load — person name resolution', () => {
const result = await load({
url: makeUrl({ receiverId: '22222222-2222-2222-2222-222222222222' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -221,6 +236,7 @@ describe('documents page load — person name resolution', () => {
const result = await load({
url: makeUrl({ senderId: 'not-a-uuid' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});
@@ -234,6 +250,7 @@ describe('documents page load — person name resolution', () => {
const result = await load({
url: makeUrl({ senderId: '11111111-1111-1111-1111-111111111111' }),
request: new Request('http://localhost/documents'),
fetch: vi.fn() as unknown as typeof fetch
});