Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

test: hold the branch's tests to the type and lint gates

Maurice2a51a1a84240
diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json
index e482eb1fa..b9388f89d 100644
--- a/client/scripts/eslint-baseline.json
+++ b/client/scripts/eslint-baseline.json
@@ -1,7 +1,7 @@
{
"src": {
"@typescript-eslint/no-non-null-assertion": 382,
- "@typescript-eslint/no-misused-promises": 848,
+ "@typescript-eslint/no-misused-promises": 847,
"no-console": 88,
"complexity": 219,
"@typescript-eslint/no-explicit-any": 146,
@@ -35,11 +35,11 @@
},
"tests": {
"@typescript-eslint/no-explicit-any": 490,
- "@typescript-eslint/no-non-null-assertion": 1917,
+ "@typescript-eslint/no-non-null-assertion": 1914,
"@typescript-eslint/no-misused-promises": 22,
"@typescript-eslint/no-unused-vars": 51,
"@typescript-eslint/no-floating-promises": 33,
- "trek/no-window-globals": 331,
+ "trek/no-window-globals": 325,
"trek/no-swallowed-catch": 14,
"react-hooks/globals": 5,
"react-hooks/refs": 22,
diff --git a/client/src/components/Planner/TripExportModal.test.tsx b/client/src/components/Planner/TripExportModal.test.tsx
index 3c698273c..d03186c3b 100644
--- a/client/src/components/Planner/TripExportModal.test.tsx
+++ b/client/src/components/Planner/TripExportModal.test.tsx
@@ -111,14 +111,14 @@ describe('TripExportModal', () => {
it('FE-PLANNER-EXPORTMODAL-016: while one export works, every row waits', async () => {
const user = userEvent.setup()
- let finish: (() => void) | null = null
- vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
+ let finish = () => {}
+ vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
render(<TripExportModal {...makeProps()} />)
await user.click(screen.getByText('dayplan.pdf'))
await waitFor(() => expect(screen.getByRole('button', { name: /dayplan\.gpxAll/ })).toBeDisabled())
expect(screen.getByRole('button', { name: /mobileTrip\.icsDownload/ })).toBeDisabled()
expect(screen.getByRole('button', { name: /dayplan\.pdf/ })).toBeDisabled()
- finish!()
+ finish()
await waitFor(() => expect(screen.getByRole('button', { name: /dayplan\.gpxAll/ })).toBeEnabled())
})
@@ -203,7 +203,7 @@ describe('TripExportModal', () => {
const onClose = vi.fn()
render(<TripExportModal {...makeProps({ onClose })} />)
await user.click(screen.getByText('mobileTrip.icsSubscribe'))
- const exportBackdrop = screen.getByRole('dialog', { name: 'dayplan.export' }).parentElement!
+ const exportBackdrop = screen.getByRole('dialog', { name: 'dayplan.export' }).parentElement as HTMLElement
const subscribe = screen.getByTestId('ics-subscribe-modal')
// Both hang off the body; the later one paints above the earlier.
expect(exportBackdrop.compareDocumentPosition(subscribe) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
@@ -294,8 +294,8 @@ describe('TripExportModal', () => {
it('FE-PLANNER-EXPORTMODAL-019: while the PDF routes the row counts the legs, and the rest can be left out (#2876)', async () => {
const user = userEvent.setup()
- let finish: (() => void) | null = null
- vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
+ let finish = () => {}
+ vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
const roadtripViasByDay = { 10: [] }
const tourStageStops = new Map()
render(<TripExportModal {...makeProps({ roadtripViasByDay, tourStageStops })} />)
@@ -309,13 +309,13 @@ describe('TripExportModal', () => {
await user.click(screen.getByRole('button', { name: 'dayplan.pdfSkipRouting' }))
expect(route?.signal?.aborted).toBe(true)
expect(screen.queryByRole('button', { name: 'dayplan.pdfSkipRouting' })).toBeNull()
- await act(async () => finish!())
+ await act(async () => finish())
})
it('FE-PLANNER-EXPORTMODAL-020: closing the dialog while the PDF routes gives the export up', async () => {
const user = userEvent.setup()
- let finish: (() => void) | null = null
- vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
+ let finish = () => {}
+ vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
const props = makeProps()
const { rerender } = render(<TripExportModal {...props} />)
await user.click(screen.getByText('dayplan.pdf'))
@@ -325,7 +325,7 @@ describe('TripExportModal', () => {
rerender(<TripExportModal {...props} isOpen={false} />)
expect(route?.signal?.aborted).toBe(true)
expect(signal?.aborted).toBe(true)
- await act(async () => finish!())
+ await act(async () => finish())
expect(props.onClose).not.toHaveBeenCalled()
})
})
diff --git a/client/tests/helpers/bookingSave.ts b/client/tests/helpers/bookingSave.ts
index 25e25146b..f02dccfc3 100644
--- a/client/tests/helpers/bookingSave.ts
+++ b/client/tests/helpers/bookingSave.ts
@@ -12,14 +12,20 @@ import type { Reservation } from '../../src/types';
*/
export function plannerSave(record: { id: number }) {
const failures: Error[] = [];
- const save = vi.fn(async (_data: unknown, steps?: BookingSaveSteps) => {
- try {
- await steps?.afterSave?.(record as Reservation);
- return record;
- } catch (err) {
- failures.push(err as Error);
- return undefined;
+ const stored = record as Reservation;
+ const save = vi.fn(
+ async (
+ _data: Record<string, unknown> & { title: string },
+ steps?: BookingSaveSteps
+ ): Promise<Reservation | undefined> => {
+ try {
+ await steps?.afterSave?.(stored);
+ return stored;
+ } catch (err) {
+ failures.push(err as Error);
+ return undefined;
+ }
}
- });
+ );
return { save, failures };
}
diff --git a/client/tests/unit/mobile/trip/MExportSheet.test.tsx b/client/tests/unit/mobile/trip/MExportSheet.test.tsx
index 973b54b18..2f0ea4321 100644
--- a/client/tests/unit/mobile/trip/MExportSheet.test.tsx
+++ b/client/tests/unit/mobile/trip/MExportSheet.test.tsx
@@ -223,8 +223,8 @@ describe('MExportSheet', () => {
})
it('FE-MOB-EXPSH-014: while the PDF routes the row counts the legs, and the rest can be left out (#2876)', async () => {
- let finish: (() => void) | null = null
- vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
+ let finish = () => {}
+ vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
renderSheet()
fireEvent.click(screen.getByText('PDF'))
await waitFor(() => expect(downloadTripPDF).toHaveBeenCalledTimes(1))
@@ -234,7 +234,7 @@ describe('MExportSheet', () => {
expect(screen.getByText('Calculating routes: 3 of 10')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'Export without the remaining routes' }))
expect(route?.signal?.aborted).toBe(true)
- await act(async () => finish!())
+ await act(async () => finish())
})
it('FE-MOB-EXPSH-015: hiding the sheet while the PDF routes gives the export up', async () => {
diff --git a/server/src/nest/maps/providers/photon.mapping.ts b/server/src/nest/maps/providers/photon.mapping.ts
index 411b86489..a6cea4ba6 100644
--- a/server/src/nest/maps/providers/photon.mapping.ts
+++ b/server/src/nest/maps/providers/photon.mapping.ts
@@ -148,7 +148,7 @@ export function asSuggestion(feature: PhotonFeature): Suggestion | null {
// place is. Cut by the name rather than at its first comma, which a name can
// hold; a house without a name is titled by its number, as Nominatim does.
const name = feature.properties.name?.trim();
- const line = hit.display_name;
+ const line = hit.display_name ?? '';
const [head = '', ...rest] = line.split(', ');
const mainText = name || head;
if (!mainText) return null;
diff --git a/server/tests/unit/nest/maps.autocomplete.test.ts b/server/tests/unit/nest/maps.autocomplete.test.ts
index 5733f2ea0..9626aeb7f 100644
--- a/server/tests/unit/nest/maps.autocomplete.test.ts
+++ b/server/tests/unit/nest/maps.autocomplete.test.ts
@@ -498,11 +498,12 @@ describe('MapsService.autocompletePlaces', () => {
it('MAPS-AUTO-023: an index failure keeps what Photon found instead of throwing it away', async () => {
mockSearch.mockRejectedValue(new Error('places api down'));
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
const { svc } = withPhoton([photonRow()]);
const result = await svc.autocompletePlaces(1, INPUT);
- expect(console.warn).toHaveBeenCalledWith('TREK Places autocomplete failed, falling back:', 'places api down');
+ expect(warn).toHaveBeenCalledWith('TREK Places autocomplete failed, falling back:', 'places api down');
expect(result.suggestions).toEqual([photonRow()]);
});
diff --git a/server/tests/unit/nest/photon.client.test.ts b/server/tests/unit/nest/photon.client.test.ts
index a12f171a3..ac3210046 100644
--- a/server/tests/unit/nest/photon.client.test.ts
+++ b/server/tests/unit/nest/photon.client.test.ts
@@ -247,12 +247,13 @@ describe('the suggestions asked per keystroke', () => {
init.signal?.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')));
}),
);
- for (let i = 0; i < 5; i += 1) {
- const dropped = new AbortController();
- const asked = photon.suggest('Rost', { signal: dropped.signal });
- dropped.abort();
- expect(await asked).toBeNull();
- }
+ const dropped = Array.from({ length: 5 }, () => {
+ const controller = new AbortController();
+ const asked = photon.suggest('Rost', { signal: controller.signal });
+ controller.abort();
+ return asked;
+ });
+ expect(await Promise.all(dropped)).toEqual([null, null, null, null, null]);
fetchMock.mockImplementation(async () => photonAnswer([gateFeature()]));
expect(await photon.suggest('Rostock')).toHaveLength(1);
});
diff --git a/server/tests/unit/nest/place-regions-repair.test.ts b/server/tests/unit/nest/place-regions-repair.test.ts
index 1abf0ac38..ef6cf6ad1 100644
--- a/server/tests/unit/nest/place-regions-repair.test.ts
+++ b/server/tests/unit/nest/place-regions-repair.test.ts
@@ -177,8 +177,8 @@ describe('the one time repair of place_regions rows cached before #2527', () =>
expect(await atlas.repairStaleRegionCache()).toEqual({ replaced: 0, dropped: 2 });
expect(await cachedRow(beach)).toBeUndefined();
expect(await cachedRow(cleared)).toBeUndefined();
- // The dashboard, which reads only the cache, no longer counts France.
- expect((await atlas.getTravelStats(userId)).countries).toEqual([]);
+ // The dashboard no longer counts France; the borders place the beach in Germany.
+ expect((await atlas.getTravelStats(userId)).countries).toEqual(['DE']);
});
it('does not write over a place that is edited while the pass runs', async () => {