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:
Maurice
2026-10-10 21:23:37 +02:00
parent f4e518b2df
commit 724c88c201
1978 changed files with 78448 additions and 39347 deletions
@@ -5,24 +5,31 @@
* the declared-profile re-check against the DB row, and whole-result rejection
* of malformed routes (a wrong leg count must never mis-key sidebar connectors).
*/
import type { PluginsRepository } from '../../../src/db/repositories/Plugins.repository';
import type { TripsRepository } from '../../../src/db/repositories/Trips.repository';
import { PluginRoutesController } from '../../../src/nest/plugins/contributions/plugin-routes.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, capabilitiesRow } = 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),
capabilitiesRow: { value: JSON.stringify({ routeProfiles: [{ id: 'ev', label: 'EV' }] }) as string | undefined },
}));
vi.mock('../../../src/db/database', () => ({
db: { prepare: () => ({ get: () => (capabilitiesRow.value === undefined ? undefined : { capabilities: capabilitiesRow.value }) }) },
db: {
prepare: () => ({
get: () => (capabilitiesRow.value === undefined ? undefined : { capabilities: capabilitiesRow.value }),
}),
},
canAccessTrip,
}));
import type { TripsRepository } from '../../../src/db/repositories/Trips.repository';
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
import { PluginRoutesController } from '../../../src/nest/plugins/contributions/plugin-routes.controller';
import type { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';
import type { PluginsRepository } from '../../../src/db/repositories/Plugins.repository';
import { TripAccessService } from '../../../src/nest/trip-membership/trip-access.service';
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const req = (id?: number) => ({ user: id === undefined ? undefined : { id } }) as any;
@@ -37,11 +44,22 @@ function controller(invoke: () => unknown, providers = ['ev-plug']) {
const plugins = {
findCapabilities: vi.fn(async () => (capabilitiesRow.value === undefined ? null : capabilitiesRow.value)),
} as unknown as PluginsRepository;
return { c: new PluginRoutesController(runtime, new TripAccessService({ findAccessible: canAccessTrip } as unknown as TripsRepository), plugins), runtime };
return {
c: new PluginRoutesController(
runtime,
new TripAccessService({ findAccessible: canAccessTrip } as unknown as TripsRepository),
plugins,
),
runtime,
};
}
const wp = (n = 3) => Array.from({ length: n }, (_, i) => ({ lat: 48 + i * 0.1, lng: 2 + i * 0.1 }));
const goodRoute = (n = 3, over: Record<string, unknown> = {}) => ({
coordinates: [[48, 2], [48.1, 2.1], [48.2, 2.2]],
coordinates: [
[48, 2],
[48.1, 2.1],
[48.2, 2.2],
],
distance: 12000,
duration: 900,
legs: Array.from({ length: n - 1 }, () => ({ distance: 6000, duration: 450 })),
@@ -72,9 +90,14 @@ describe('PluginRoutesController', () => {
it('rejects invalid waypoint lists without invoking the plugin', async () => {
const cases = [
body({ waypoints: wp(1) }), // too few
body({ waypoints: wp(31) }), // too many
body({ waypoints: [{ lat: 200, lng: 2 }, { lat: 48, lng: 2 }] }), // out of range
body({ waypoints: wp(1) }), // too few
body({ waypoints: wp(31) }), // too many
body({
waypoints: [
{ lat: 200, lng: 2 },
{ lat: 48, lng: 2 },
],
}), // out of range
body({ waypoints: 'nope' }),
body({ tripId: 'NaN' }),
];
@@ -94,10 +117,15 @@ describe('PluginRoutesController', () => {
});
it('returns a normalized route and passes the request through to the hook', async () => {
const { c, runtime } = controller(() => goodRoute(3, {
legs: [{ distance: 6000, duration: 450, note: 'charge to 80%' }, { distance: 6000, duration: 450 }],
viaPoints: [{ lat: 48.05, lng: 2.05, label: 'Fastned', tone: 'success', dwellSeconds: 1500.7 }],
}));
const { c, runtime } = controller(() =>
goodRoute(3, {
legs: [
{ distance: 6000, duration: 450, note: 'charge to 80%' },
{ distance: 6000, duration: 450 },
],
viaPoints: [{ lat: 48.05, lng: 2.05, label: 'Fastned', tone: 'success', dwellSeconds: 1500.7 }],
}),
);
const { route } = await c.route('ev-plug', 'ev', body(), req(5));
expect(route).not.toBeNull();
expect(route!.pluginId).toBe('ev-plug');
@@ -109,11 +137,21 @@ describe('PluginRoutesController', () => {
it('rejects a malformed route whole: wrong leg count, bad vertex, negative numbers', async () => {
const bads = [
goodRoute(3, { legs: [{ distance: 1, duration: 1 }] }), // 1 leg for 3 waypoints
goodRoute(3, { coordinates: [[48, 2], [999, 2]] }), // out-of-range vertex
goodRoute(3, { legs: [{ distance: 1, duration: 1 }] }), // 1 leg for 3 waypoints
goodRoute(3, {
coordinates: [
[48, 2],
[999, 2],
],
}), // out-of-range vertex
goodRoute(3, { distance: -5 }),
goodRoute(3, { duration: 'soon' }),
goodRoute(3, { legs: [{ distance: 1, duration: -1 }, { distance: 1, duration: 1 }] }),
goodRoute(3, {
legs: [
{ distance: 1, duration: -1 },
{ distance: 1, duration: 1 },
],
}),
'nope',
];
for (const bad of bads) {
@@ -133,11 +171,13 @@ describe('PluginRoutesController', () => {
expect(route!.viaPoints.length).toBeLessThanOrEqual(40);
expect(route!.viaPoints[0].tone).toBe('default');
expect(route!.viaPoints[0].label!.length).toBe(80);
expect(route!.viaPoints.some(v => v.label === 'dropped')).toBe(false);
expect(route!.viaPoints.some((v) => v.label === 'dropped')).toBe(false);
});
it('answers null when the provider throws or times out', async () => {
const { c } = controller(() => { throw new Error('solver down'); });
const { c } = controller(() => {
throw new Error('solver down');
});
expect((await c.route('ev-plug', 'ev', body(), req(5))).route).toBeNull();
});
});