mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
This commit is contained in:
@@ -5,20 +5,22 @@
|
||||
* hardening: server-side normalization, a URL-scheme allowlist (no click-XSS), and
|
||||
* length/count caps.
|
||||
*/
|
||||
import type { TripsRepository } from '../../../src/db/repositories/Trips.repository';
|
||||
import { ViewContributionsController } from '../../../src/nest/plugins/contributions/view-contributions.controller';
|
||||
import type { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';
|
||||
import { TripAccessService } from '../../../src/nest/trip-membership/trip-access.service';
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { canAccessTrip, pluginsEnabled } = vi.hoisted(() => ({
|
||||
canAccessTrip: vi.fn(async (tripId: number, userId: number) => (tripId === 1 && userId === 5 ? { id: 1 } : undefined)),
|
||||
canAccessTrip: vi.fn(async (tripId: number, userId: number) =>
|
||||
tripId === 1 && userId === 5 ? { id: 1 } : undefined,
|
||||
),
|
||||
pluginsEnabled: vi.fn(() => true),
|
||||
}));
|
||||
vi.mock('../../../src/db/database', () => ({ db: { prepare: () => ({ get: () => undefined }) }, canAccessTrip }));
|
||||
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
|
||||
|
||||
import { ViewContributionsController } from '../../../src/nest/plugins/contributions/view-contributions.controller';
|
||||
import type { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';
|
||||
import type { TripsRepository } from '../../../src/db/repositories/Trips.repository';
|
||||
import { TripAccessService } from '../../../src/nest/trip-membership/trip-access.service';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const req = (id?: number) => ({ user: id === undefined ? undefined : { id } }) as any;
|
||||
function controller(invoke: (id: string) => unknown, providers = ['p1']) {
|
||||
@@ -26,13 +28,29 @@ function controller(invoke: (id: string) => unknown, providers = ['p1']) {
|
||||
providersOf: vi.fn(() => providers),
|
||||
tableContributions: vi.fn(async (id: string) => invoke(id)),
|
||||
} as unknown as PluginHooks;
|
||||
return { c: new ViewContributionsController(runtime, new TripAccessService({ findAccessible: canAccessTrip } as unknown as TripsRepository)), runtime };
|
||||
return {
|
||||
c: new ViewContributionsController(
|
||||
runtime,
|
||||
new TripAccessService({ findAccessible: canAccessTrip } as unknown as TripsRepository),
|
||||
),
|
||||
runtime,
|
||||
};
|
||||
}
|
||||
const col = (over: Record<string, unknown> = {}) => ({ kind: 'column', entityId: 1, id: 'c1', label: 'X', ...over });
|
||||
const act = (over: Record<string, unknown> = {}) => ({ kind: 'action', entityId: 1, id: 'a1', label: 'Go', target: { kind: 'frame', sub: '/ui' }, ...over });
|
||||
const act = (over: Record<string, unknown> = {}) => ({
|
||||
kind: 'action',
|
||||
entityId: 1,
|
||||
id: 'a1',
|
||||
label: 'Go',
|
||||
target: { kind: 'frame', sub: '/ui' },
|
||||
...over,
|
||||
});
|
||||
|
||||
describe('ViewContributionsController', () => {
|
||||
beforeEach(() => { pluginsEnabled.mockReturnValue(true); canAccessTrip.mockResolvedValue({ id: 1 } as never); });
|
||||
beforeEach(() => {
|
||||
pluginsEnabled.mockReturnValue(true);
|
||||
canAccessTrip.mockResolvedValue({ id: 1 } as never);
|
||||
});
|
||||
|
||||
it('gates: disabled / unknown view / no user / non-member all return [] (no plugin calls on the first two)', async () => {
|
||||
pluginsEnabled.mockReturnValue(false);
|
||||
@@ -66,7 +84,17 @@ describe('ViewContributionsController', () => {
|
||||
col({ id: 'long', label: 'L'.repeat(200), value: 'V'.repeat(500), tone: 'nope' }),
|
||||
]);
|
||||
const out = (await c.get('reservations', '1', req(5))).contributions;
|
||||
expect(out[0]).toEqual({ kind: 'column', pluginId: 'p1', entityId: 1, id: 'ok', label: 'Crowd', value: 'Quiet', url: 'https://x.test', icon: 'Users', tone: 'success' });
|
||||
expect(out[0]).toEqual({
|
||||
kind: 'column',
|
||||
pluginId: 'p1',
|
||||
entityId: 1,
|
||||
id: 'ok',
|
||||
label: 'Crowd',
|
||||
value: 'Quiet',
|
||||
url: 'https://x.test',
|
||||
icon: 'Users',
|
||||
tone: 'success',
|
||||
});
|
||||
expect((out[1] as { url?: string }).url).toBeUndefined(); // javascript: rejected
|
||||
expect((out[2] as { url?: string }).url).toBeUndefined(); // data: rejected
|
||||
expect((out[3] as { url?: string }).url).toBe('mailto:a@b.c');
|
||||
@@ -113,7 +141,13 @@ describe('ViewContributionsController', () => {
|
||||
});
|
||||
|
||||
it('merges providers, skips one that throws, and passes (view, tripId) + user to the hook', async () => {
|
||||
const { c, runtime } = controller((id) => { if (id === 'p2') throw new Error('slow'); return [col({ id: 'from-p1' })]; }, ['p1', 'p2']);
|
||||
const { c, runtime } = controller(
|
||||
(id) => {
|
||||
if (id === 'p2') throw new Error('slow');
|
||||
return [col({ id: 'from-p1' })];
|
||||
},
|
||||
['p1', 'p2'],
|
||||
);
|
||||
const out = (await c.get('reservations', '1', req(5))).contributions;
|
||||
expect(out.map((o) => o.id)).toEqual(['from-p1']);
|
||||
expect(runtime.tableContributions).toHaveBeenCalledWith('p1', 'reservations', 1, 5);
|
||||
|
||||
Reference in New Issue
Block a user