Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 3m1s
CI / OCR Service Tests (pull_request) Successful in 30s
CI / Backend Unit Tests (pull_request) Failing after 3m0s
CI / Unit & Component Tests (push) Failing after 2m59s
CI / OCR Service Tests (push) Successful in 37s
CI / Backend Unit Tests (push) Failing after 2m54s
- DocumentServiceTest.applyBulkEditToDocument_propagatesDomainException_whenSenderIdUnresolvable (Sara C1) - DocumentServiceTest.findIdsForFilter_passesTagOperatorOR_throughBuildSearchSpec (Sara C3) - bulkSelection.svelte.spec.ts: setAll([]) no-op + previous-IDs-absent + ids getter (Sara C4 + S4) - /documents/bulk-edit/+page.server.ts now defensively handles a UserGroup with NULL `permissions` (treats it as not-WRITE_ALL instead of throwing on .includes()) + matching test (Sara C7) 233 backend tests + frontend bulk-edit specs all green. Refs #225, PR #331 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { load } from './+page.server';
|
|
|
|
describe('/documents/bulk-edit +page.server.ts', () => {
|
|
it('redirects to /documents when user lacks WRITE_ALL', async () => {
|
|
const locals = { user: { groups: [{ permissions: ['READ_ALL'] }] } };
|
|
try {
|
|
// @ts-expect-error — partial event shape sufficient for this guard
|
|
await load({ locals });
|
|
throw new Error('expected redirect to be thrown');
|
|
} catch (e) {
|
|
const err = e as { status?: number; location?: string };
|
|
expect(err.status).toBe(303);
|
|
expect(err.location).toBe('/documents');
|
|
}
|
|
});
|
|
|
|
it('redirects when user has no groups', async () => {
|
|
const locals = { user: { groups: [] } };
|
|
try {
|
|
// @ts-expect-error — partial event shape sufficient for this guard
|
|
await load({ locals });
|
|
throw new Error('expected redirect');
|
|
} catch (e) {
|
|
expect((e as { status?: number }).status).toBe(303);
|
|
}
|
|
});
|
|
|
|
it('redirects when no user is logged in', async () => {
|
|
const locals = {};
|
|
try {
|
|
// @ts-expect-error — partial event shape sufficient for this guard
|
|
await load({ locals });
|
|
throw new Error('expected redirect');
|
|
} catch (e) {
|
|
expect((e as { status?: number }).status).toBe(303);
|
|
}
|
|
});
|
|
|
|
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 });
|
|
expect(result).toEqual({ canWrite: true });
|
|
});
|
|
|
|
it('redirects when a group has no permissions array (defensive)', async () => {
|
|
// Sara C7 — a UserGroup row with NULL permissions used to throw on
|
|
// .includes(); the guard now treats that case as "not WRITE_ALL".
|
|
const locals = {
|
|
user: { groups: [{ permissions: undefined as unknown as string[] }] }
|
|
};
|
|
try {
|
|
// @ts-expect-error — partial event shape sufficient for this guard
|
|
await load({ locals });
|
|
throw new Error('expected redirect');
|
|
} catch (e) {
|
|
expect((e as { status?: number }).status).toBe(303);
|
|
}
|
|
});
|
|
});
|