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
@@ -1,12 +1,12 @@
import { PluginSearchController } from '../../../src/nest/plugins/contributions/plugin-search.controller';
import type { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';
import { pluginSearchHitSchema, pluginSuggestResultSchema } from '@trek/shared';
import { describe, it, expect, vi, beforeEach } from 'vitest';
const { pluginsEnabled } = vi.hoisted(() => ({ pluginsEnabled: vi.fn(() => true) }));
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
import { pluginSearchHitSchema, pluginSuggestResultSchema } from '@trek/shared';
import { PluginSearchController } from '../../../src/nest/plugins/contributions/plugin-search.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;
@@ -23,7 +23,9 @@ function controller(over: Partial<PluginHooks> = {}) {
}
describe('PluginSearchController', () => {
beforeEach(() => { pluginsEnabled.mockReturnValue(true); });
beforeEach(() => {
pluginsEnabled.mockReturnValue(true);
});
it('returns [] when the runtime is disabled (no plugin calls)', async () => {
pluginsEnabled.mockReturnValue(false);
@@ -87,13 +89,20 @@ describe('PluginSearchController', () => {
) as unknown as PluginHooks['searchPlaces'],
});
const { places } = await c.search('milan', undefined, undefined, undefined, undefined, req(5));
expect(places.map(p => p.name)).toEqual(['A1', 'B1', 'A2', 'A3']);
expect(places.map((p) => p.name)).toEqual(['A1', 'B1', 'A2', 'A3']);
});
it('normalizes a hit into the shape the core search returns, and namespaces the id', async () => {
const { c } = controller({
searchPlaces: vi.fn(async () => [
hit({ address: 'Via Roma 1', rating: 4.5, website: 'https://ok.example', phone: '+39 02', category: 'restaurant', description: 'Good' }),
hit({
address: 'Via Roma 1',
rating: 4.5,
website: 'https://ok.example',
phone: '+39 02',
category: 'restaurant',
description: 'Good',
}),
]) as unknown as PluginHooks['searchPlaces'],
});
const { places } = await c.search('milan', undefined, undefined, undefined, undefined, req(5));
@@ -115,7 +124,9 @@ describe('PluginSearchController', () => {
it('falls back to the coordinate when a hit carries no id of its own', async () => {
const { c } = controller({
searchPlaces: vi.fn(async () => [{ name: 'Nameless index', lat: 45.4, lng: 9.2 }]) as unknown as PluginHooks['searchPlaces'],
searchPlaces: vi.fn(async () => [
{ name: 'Nameless index', lat: 45.4, lng: 9.2 },
]) as unknown as PluginHooks['searchPlaces'],
});
const { places } = await c.search('milan', undefined, undefined, undefined, undefined, req(5));
expect(places[0].osm_id).toBe('plugin:p1:45.4,9.2');
@@ -133,7 +144,7 @@ describe('PluginSearchController', () => {
]) as unknown as PluginHooks['searchPlaces'],
});
const { places } = await c.search('milan', undefined, undefined, undefined, undefined, req(5));
expect(places.map(p => p.name)).toEqual(['Keeper']);
expect(places.map((p) => p.name)).toEqual(['Keeper']);
});
it('strips a javascript: website, clamps the rating and caps every string', async () => {
@@ -164,7 +175,7 @@ describe('PluginSearchController', () => {
]) as unknown as PluginHooks['searchPlaces'],
});
const { places } = await c.search('milan', undefined, undefined, undefined, undefined, req(5));
expect(places.map(p => p.rating)).toEqual([null, null, null, 4.3]);
expect(places.map((p) => p.rating)).toEqual([null, null, null, 4.3]);
});
// #2483: a plugin index is one more source of websites typed without a scheme.
@@ -177,7 +188,11 @@ describe('PluginSearchController', () => {
]) as unknown as PluginHooks['searchPlaces'],
});
const { places } = await c.search('milan', undefined, undefined, undefined, undefined, req(5));
expect(places.map((p) => p.website)).toEqual(['https://www.ristorante.example/menu', 'https://ristorante.example', null]);
expect(places.map((p) => p.website)).toEqual([
'https://www.ristorante.example/menu',
'https://ristorante.example',
null,
]);
});
// A plugin on the same network may answer with an intranet address. The old
@@ -185,7 +200,9 @@ describe('PluginSearchController', () => {
it('PLUGIN-SEARCH-2483-02: an http(s) website keeps its host whatever it looks like', async () => {
const urls = ['http://localhost:8080/poi/1', 'http://intranet/poi/2', 'https://[2001:db8::1]/poi/3'];
const { c } = controller({
searchPlaces: vi.fn(async () => urls.map((website, i) => hit({ id: `h${i}`, website }))) as unknown as PluginHooks['searchPlaces'],
searchPlaces: vi.fn(async () =>
urls.map((website, i) => hit({ id: `h${i}`, website })),
) as unknown as PluginHooks['searchPlaces'],
});
const { places } = await c.search('poi', undefined, undefined, undefined, undefined, req(5));
expect(places.map((p) => p.website)).toEqual(urls);
@@ -206,7 +223,14 @@ describe('PluginSearchController', () => {
// is what fails when one of them moves without the other.
const { c } = controller({
searchPlaces: vi.fn(async () => [
hit({ address: 'Via Roma 1', rating: 4.5, website: 'ok.example', phone: '+39 02', category: 'restaurant', description: 'Good' }),
hit({
address: 'Via Roma 1',
rating: 4.5,
website: 'ok.example',
phone: '+39 02',
category: 'restaurant',
description: 'Good',
}),
hit({ id: 'bare', name: 'Bare' }),
]) as unknown as PluginHooks['searchPlaces'],
});
@@ -216,7 +240,9 @@ describe('PluginSearchController', () => {
});
describe('PluginSearchController.suggest (#2221)', () => {
beforeEach(() => { pluginsEnabled.mockReturnValue(true); });
beforeEach(() => {
pluginsEnabled.mockReturnValue(true);
});
it('asks only the providers that implement suggest, never their search', async () => {
const { c, hooks } = controller();
@@ -256,7 +282,7 @@ describe('PluginSearchController.suggest (#2221)', () => {
) as unknown as PluginHooks['suggestPlaces'],
});
const result = await c.suggest('ichiran', undefined, undefined, undefined, req(5));
expect(result.places.map(p => p.name)).toEqual(['A0', 'B0', 'A1']);
expect(result.places.map((p) => p.name)).toEqual(['A0', 'B0', 'A1']);
expect(pluginSuggestResultSchema.safeParse(result).success).toBe(true);
});