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
@@ -6,17 +6,20 @@
* alpha-2 code validation (uppercase-coerced), tone enum default, length caps,
* layer/country count caps.
*/
import { AtlasLayersController } from '../../../src/nest/plugins/contributions/atlas-layers.controller';
import type { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';
import { describe, it, expect, vi, beforeEach } from 'vitest';
const { pluginsEnabled } = vi.hoisted(() => ({
pluginsEnabled: vi.fn(() => true),
}));
vi.mock('../../../src/db/database', () => ({ db: { prepare: () => ({ get: () => undefined }) }, canAccessTrip: vi.fn() }));
vi.mock('../../../src/db/database', () => ({
db: { prepare: () => ({ get: () => undefined }) },
canAccessTrip: vi.fn(),
}));
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
import { AtlasLayersController } from '../../../src/nest/plugins/contributions/atlas-layers.controller';
import type { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.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']) {
@@ -29,7 +32,9 @@ function controller(invoke: (id: string) => unknown, providers = ['p1']) {
const layer = (over: Record<string, unknown> = {}) => ({ id: 'l1', countries: [{ code: 'FR' }], ...over });
describe('AtlasLayersController', () => {
beforeEach(() => { pluginsEnabled.mockReturnValue(true); });
beforeEach(() => {
pluginsEnabled.mockReturnValue(true);
});
it('gates: disabled / no user return [] (no plugin calls on the first)', async () => {
pluginsEnabled.mockReturnValue(false);
@@ -46,12 +51,14 @@ describe('AtlasLayersController', () => {
layer({ name: 'Wishlist', countries: [{ code: 'FR', tone: 'success', label: 'Paris trip' }] }),
]);
const out = (await c.get(req(5))).layers;
expect(out).toEqual([{
pluginId: 'p1',
id: 'l1',
name: 'Wishlist',
countries: [{ code: 'FR', tone: 'success', label: 'Paris trip' }],
}]);
expect(out).toEqual([
{
pluginId: 'p1',
id: 'l1',
name: 'Wishlist',
countries: [{ code: 'FR', tone: 'success', label: 'Paris trip' }],
},
]);
// user-scoped: empty args, the acting user is bound host-side
expect(runtime.atlasLayers).toHaveBeenCalledWith('p1', 5);
});
@@ -60,11 +67,11 @@ describe('AtlasLayersController', () => {
const { c } = controller(() => [
layer({
countries: [
{ code: 'de' }, // lowercased -> DE
{ code: 'DEU' }, // alpha-3 -> dropped
{ code: '1x' }, // digits -> dropped
{ code: '' }, // empty -> dropped
null, // non-object -> dropped
{ code: 'de' }, // lowercased -> DE
{ code: 'DEU' }, // alpha-3 -> dropped
{ code: '1x' }, // digits -> dropped
{ code: '' }, // empty -> dropped
null, // non-object -> dropped
{ code: 'JP', tone: 'evil', label: 'L'.repeat(200) },
],
}),
@@ -73,14 +80,14 @@ describe('AtlasLayersController', () => {
expect(out.map((x) => x.code)).toEqual(['DE', 'JP']);
expect(out[0].tone).toBe('default');
expect(out[0].label).toBeUndefined();
expect(out[1].tone).toBe('default'); // unknown tone -> default
expect(out[1].label!.length).toBe(80); // capped
expect(out[1].tone).toBe('default'); // unknown tone -> default
expect(out[1].label!.length).toBe(80); // capped
});
it('drops id-less layers and non-objects, caps the name, tolerates non-array results', async () => {
const { c } = controller(() => [
layer({ id: '' }), // no id -> can't key it
null, // non-object
layer({ id: '' }), // no id -> can't key it
null, // non-object
layer({ id: 'ok', name: 'N'.repeat(200), countries: 'not an array' }),
]);
const out = (await c.get(req(5))).layers;
@@ -93,13 +100,23 @@ describe('AtlasLayersController', () => {
});
it('caps at 3 layers per plugin and 300 countries per layer, and skips a failing provider', async () => {
const many = Array.from({ length: 5 }, (_, i) => layer({
id: `l${i}`,
countries: Array.from({ length: 350 }, () => ({ code: 'US' })),
}));
const { c } = controller((id) => (id === 'bad' ? (() => { throw new Error('boom'); })() : many), ['good', 'bad']);
const many = Array.from({ length: 5 }, (_, i) =>
layer({
id: `l${i}`,
countries: Array.from({ length: 350 }, () => ({ code: 'US' })),
}),
);
const { c } = controller(
(id) =>
id === 'bad'
? (() => {
throw new Error('boom');
})()
: many,
['good', 'bad'],
);
const out = (await c.get(req(5))).layers;
expect(out).toHaveLength(3); // good capped to 3; bad contributes nothing
expect(out).toHaveLength(3); // good capped to 3; bad contributes nothing
expect(out[0].countries).toHaveLength(300);
});
});