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 audit follow-ups to the test, lint, theme and size ratchets

Maurice4bc764eb6afb
diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json
index b572afd98..7527cfd3a 100644
--- a/client/scripts/eslint-baseline.json
+++ b/client/scripts/eslint-baseline.json
@@ -8,7 +8,7 @@
"trek/no-swallowed-catch": 128,
"max-params": 32,
"trek/store-without-selector": 67,
- "react-hooks/refs": 554,
+ "react-hooks/refs": 553,
"react-hooks/set-state-in-effect": 193,
"@typescript-eslint/no-floating-promises": 164,
"react-hooks/exhaustive-deps": 116,
diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.json
index f6c481626..f2b36069a 100644
--- a/client/scripts/size-baseline.json
+++ b/client/scripts/size-baseline.json
@@ -5,7 +5,7 @@
"src/components/Admin/AdminPluginsPanel.tsx": 1266,
"src/components/Budget/CostsPanel.test.tsx": 2730,
"src/components/Budget/CostsPanel.tsx": 1798,
- "src/components/Map/MapView.tsx": 1337,
+ "src/components/Map/MapView.tsx": 1255,
"src/components/Map/MapViewGL.test.tsx": 2919,
"src/components/Map/MapViewGL.tsx": 2198,
"src/components/Planner/DayDetailPanel.test.tsx": 2333,
diff --git a/client/scripts/theme-disable-baseline.json b/client/scripts/theme-disable-baseline.json
index 2a56b0a8b..87f672eb0 100644
--- a/client/scripts/theme-disable-baseline.json
+++ b/client/scripts/theme-disable-baseline.json
@@ -20,7 +20,7 @@
"components/Map/DawarichTrailLayer.tsx": 1,
"components/Map/dawarichTrail.ts": 10,
"components/Map/useDawarichTrailGL.ts": 1,
- "components/Packing/PackingListPanelItemRow.tsx": 1,
+ "components/Packing/PackingBringersCard.tsx": 1,
"components/Planner/DayReorderPopup.tsx": 1,
"components/Planner/bookings/bookingsModel.ts": 1,
"components/Planner/bookings/transitParts.tsx": 1,
diff --git a/client/src/components/Map/PoiMarkers.tsx b/client/src/components/Map/PoiMarkers.tsx
index f94f7211e..2eb16ea5d 100644
--- a/client/src/components/Map/PoiMarkers.tsx
+++ b/client/src/components/Map/PoiMarkers.tsx
@@ -77,14 +77,17 @@ export default function PoiMarkers({
}) {
const map = useMap();
const [frame, setFrame] = useState<LngFrame | null>(null);
+ // Followed only while there are POIs to draw, so a map without them keeps no listeners.
+ const tracking = pois.length > 0;
useEffect(() => {
+ if (!tracking) return undefined;
const follow = () => setFrame((current) => viewLngFrame(current, map.getCenter().lng));
map.whenReady(follow);
map.on('moveend', follow);
return () => {
map.off('moveend', follow);
};
- }, [map]);
+ }, [map, tracking]);
// Native clicks keep the newest handler without rebuilding every marker.
const clickRef = useRef(onPoiClick);
useEffect(() => {
diff --git a/client/src/components/Packing/PackingBringersCard.test.tsx b/client/src/components/Packing/PackingBringersCard.test.tsx
index c7357d877..5829d5ffd 100644
--- a/client/src/components/Packing/PackingBringersCard.test.tsx
+++ b/client/src/components/Packing/PackingBringersCard.test.tsx
@@ -48,7 +48,7 @@ describe('BringersCard', () => {
expect(rows).toHaveLength(2);
expect(rows[0]).toHaveTextContent('anna');
expect(rows[1]).toHaveTextContent('carla');
- expect(screen.getByText('packing.bringersTitle')).toBeInTheDocument();
+ expect(screen.getByText('Brought by')).toBeInTheDocument();
});
it('FE-PACK-BRINGERCARD-004: the "+N" circle counts the others', () => {
diff --git a/client/src/components/Packing/PackingBringersCard.tsx b/client/src/components/Packing/PackingBringersCard.tsx
index 021644063..975e797ed 100644
--- a/client/src/components/Packing/PackingBringersCard.tsx
+++ b/client/src/components/Packing/PackingBringersCard.tsx
@@ -24,7 +24,7 @@ export function BringerAvatar({ bringer }: { bringer: Bringer }) {
style={{
...CIRCLE,
background: `hsl(${((bringer.name.codePointAt(0) ?? 0) * 37) % 360}, 55%, 55%)`, // theme-lint-disable: the colour comes from the bringer's name
- color: 'white', // theme-lint-disable: the letter sits on the name's own colour
+ color: 'white',
textTransform: 'uppercase',
}}
>
diff --git a/client/src/components/Packing/PackingListPanelItemRow.test.tsx b/client/src/components/Packing/PackingListPanelItemRow.test.tsx
index 1603443ee..a7f938ee1 100644
--- a/client/src/components/Packing/PackingListPanelItemRow.test.tsx
+++ b/client/src/components/Packing/PackingListPanelItemRow.test.tsx
@@ -379,13 +379,16 @@ describe('ArtikelZeile — category picker', () => {
})
describe('ArtikelZeile — sharing badges', () => {
- it('FE-W5ROW-018: an item somebody else brings shows their name', () => {
+ it('FE-W5ROW-018: an item somebody else brings shows their name in the TREK tooltip', async () => {
setup({
item: buildPackingItem({ id: 1, name: 'Stove', is_private: 1, owner_id: 2, owner_username: 'Bob' } as Partial<PackingItem>),
currentUserId: 1,
})
- expect(screen.getByLabelText('by Bob')).toHaveAttribute('title', 'by Bob')
+ const badge = screen.getByLabelText('by Bob')
+ expect(badge).not.toHaveAttribute('title')
+ fireEvent.mouseEnter(badge)
+ expect(await screen.findByRole('tooltip')).toHaveTextContent('by Bob')
})
it('FE-W5ROW-019: a nameless bringer degrades to an empty name', () => {
@@ -394,10 +397,10 @@ describe('ArtikelZeile — sharing badges', () => {
currentUserId: 1,
})
- expect(screen.getByTitle('by')).toBeInTheDocument()
+ expect(screen.getByLabelText('by')).toBeInTheDocument()
})
- it('FE-W5ROW-020: an item shared by me counts its recipients', () => {
+ it('FE-W5ROW-020: an item shared by me counts its recipients', async () => {
setup({
item: buildPackingItem({
id: 1, name: 'Stove', is_private: 1, owner_id: 1,
@@ -407,10 +410,11 @@ describe('ArtikelZeile — sharing badges', () => {
})
expect(screen.getByLabelText('shared with 2')).toHaveTextContent('2')
- expect(screen.getByTitle('shared with 2: alice, bob')).toBeInTheDocument()
+ fireEvent.mouseEnter(screen.getByLabelText('shared with 2'))
+ expect(await screen.findByRole('tooltip')).toHaveTextContent('shared with 2: alice, bob')
})
- it('FE-W5ROW-021: a common item names its bringer and counts co-bringers', () => {
+ it('FE-W5ROW-021: a common item names its bringer and counts co-bringers', async () => {
setup({
item: buildPackingItem({
id: 1, name: 'Stove', is_private: 0, owner_username: 'Bob',
@@ -419,8 +423,15 @@ describe('ArtikelZeile — sharing badges', () => {
currentUserId: 1,
})
- // The bringer's initial on an avatar, the co-bringers as a count; the title names everyone (#2782).
- expect(screen.getByTitle('brought by Bob, cleo')).toHaveTextContent('B+1')
+ // The bringer's initial on an avatar, the co-bringers as a "+N" circle; the tooltip
+ // names everyone, each on a line of their own (#2782).
+ const badge = screen.getByLabelText('brought by Bob, cleo')
+ expect(badge).toHaveTextContent('B+1')
+ fireEvent.mouseEnter(badge)
+ const rows = within(await screen.findByRole('tooltip')).getAllByRole('listitem')
+ expect(rows).toHaveLength(2)
+ expect(rows[0]).toHaveTextContent('Bob')
+ expect(rows[1]).toHaveTextContent('cleo')
})
it('FE-W5ROW-022: a bringer without co-bringers shows no counter', () => {
@@ -429,7 +440,7 @@ describe('ArtikelZeile — sharing badges', () => {
currentUserId: 1,
})
- expect(screen.getByTitle('brought by Bob')).toHaveTextContent(/^B$/)
+ expect(screen.getByLabelText('brought by Bob')).toHaveTextContent(/^B$/)
})
it('FE-W5ROW-023: the placeholder row carries no badges and no share control', () => {
diff --git a/server/scripts/size-baseline.json b/server/scripts/size-baseline.json
index 2cde2f810..1e5d04336 100644
--- a/server/scripts/size-baseline.json
+++ b/server/scripts/size-baseline.json
@@ -7,7 +7,7 @@
"src/db/repositories/Users.repository.ts": 1445,
"src/nest/atlas/atlas.service.ts": 1177,
"src/nest/auth/auth.service.ts": 1143,
- "src/nest/budget/budget.service.ts": 1612,
+ "src/nest/budget/budget.service.ts": 1607,
"src/nest/collections/collections.service.ts": 1426,
"src/nest/doc-sync/doc-sync.service.ts": 1060,
"src/nest/doc-sync/providers/synology-drive.client.ts": 1160,
diff --git a/server/scripts/test-new-service-baseline.json b/server/scripts/test-new-service-baseline.json
index b818f531b..88ce6909e 100644
--- a/server/scripts/test-new-service-baseline.json
+++ b/server/scripts/test-new-service-baseline.json
@@ -97,7 +97,7 @@
"tests/unit/nest/memories/trek-photo-cache.job.test.ts": 1,
"tests/unit/nest/notification-preferences.service.test.ts": 4,
"tests/unit/nest/notification-transports.test.ts": 3,
- "tests/unit/nest/notifications/storage-health-notifier.service.test.ts": 2,
+ "tests/unit/nest/notifications/storage-health-notifier.service.test.ts": 1,
"tests/unit/nest/notifications/vapid-keys.service.test.ts": 2,
"tests/unit/nest/notifications/web-push.service.test.ts": 1,
"tests/unit/nest/oauth.controller.test.ts": 1,
diff --git a/server/src/db/repositories/Collections.repository.ts b/server/src/db/repositories/Collections.repository.ts
index ff446bd69..1b22f49b1 100644
--- a/server/src/db/repositories/Collections.repository.ts
+++ b/server/src/db/repositories/Collections.repository.ts
@@ -261,7 +261,7 @@ export class CollectionsRepository extends TrekRepository<Collections> {
*/
async deleteWithImages(id: number): Promise<Array<string | null>> {
const cover = (await this.coverImage(id)) ?? null;
- const places = await this.readDb()
+ const places = await this.placesReadDb()
.selectFrom('collection_places')
.select('image_url')
.where('collection_id', '=', id)
diff --git a/server/tests/unit/nest/journey-domain.delete.test.ts b/server/tests/unit/nest/journey-domain.delete.test.ts
index 6d31dd807..8273707ff 100644
--- a/server/tests/unit/nest/journey-domain.delete.test.ts
+++ b/server/tests/unit/nest/journey-domain.delete.test.ts
@@ -1,76 +1,59 @@
/**
- * JOURNEY-SVC-022b/022c: what deleting a journey does with the photos of its gallery
- * (#2924). Split from journey-domain.service.test.ts, which is at its size baseline;
- * the service is built the same way.
+ * JourneyDomainService: what deleting a journey does with the photos of its gallery
+ * (#2924). A photo row only this journey linked goes with it and its files are handed
+ * to the storage release; one a trip or another journey still links keeps its row.
+ * The service comes from its module over a snapshot test db, the release is a spy.
*/
-import { db as testDb } from '../../../src/db/database';
import { JourneyPhotos } from '../../../src/db/entities/JourneyPhotos.entity';
import { TrekPhotos } from '../../../src/db/entities/TrekPhotos.entity';
import { TripPhotos } from '../../../src/db/entities/TripPhotos.entity';
+import { JourneyDomainModule } from '../../../src/nest/journey/journey-domain.module';
import { JourneyDomainService } from '../../../src/nest/journey/journey-domain.service';
-import { TrekPhotoRegistrationService } from '../../../src/nest/photos/trek-photo-registration.service';
-import { RealtimeService } from '../../../src/nest/realtime/realtime.service';
-import { createUser, createTrip } from '../../helpers/factories';
-import { findRows } from '../../helpers/factories/rows';
-import {
- createTestJourneysRepo,
- createTestJourneyContributorsRepo,
- createTestJourneyTripsRepo,
- createTestJourneyEntriesRepo,
- createTestJourneyPhotosRepo,
- createTestJourneyEntryPhotosRepo,
-} from '../../helpers/journey-repos';
+import { StorageReleaseService } from '../../../src/nest/storage/storage-release.service';
+import { createSnapshotTestDb } from '../../helpers/db-mock';
+import { findRows, insertRow } from '../../helpers/factories/rows';
+import { makeTrip } from '../../helpers/factories/trips';
+import { makeUser } from '../../helpers/factories/users';
import { releaseNothing } from '../../helpers/storage-release';
import { resetTestDb } from '../../helpers/test-db';
-import { createTestUnitOfWork, sharedTestOrm, createTestTripsRepo, createTestPlacesRepo } from '../../helpers/test-uow';
+import { createTestModule, type TestModule } from '../../helpers/test-module';
+import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
import type { EntityClass, EntityDTO, FilterQuery } from '@mikro-orm/core';
-import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
+import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
-vi.mock('../../../src/db/database', async () => {
- const { createSnapshotTestDb } = await import('../../helpers/db-mock');
- const db = createSnapshotTestDb();
- return { db, closeDb: () => {}, reinitialize: () => {} };
-});
-
-const orm = () => sharedTestOrm(testDb);
+const db = createSnapshotTestDb();
const release = releaseNothing();
+let t: TestModule;
+let orm: TestOrm;
let svc: JourneyDomainService;
async function one<T extends object>(entity: EntityClass<T>, where: FilterQuery<T>) {
- return (await findRows(await orm(), entity, where))[0] as EntityDTO<T> | undefined;
+ return (await findRows(orm, entity, where))[0] as EntityDTO<T> | undefined;
}
beforeAll(async () => {
- const t = await sharedTestOrm(testDb);
- const photosRepo = await createTestJourneyPhotosRepo(testDb);
- svc = new JourneyDomainService(
- new RealtimeService(),
- new TrekPhotoRegistrationService(t.repo(TrekPhotos), t.repo(TripPhotos), photosRepo),
- await createTestUnitOfWork(testDb),
- await createTestJourneysRepo(testDb),
- await createTestJourneyContributorsRepo(testDb),
- await createTestJourneyTripsRepo(testDb),
- await createTestJourneyEntriesRepo(testDb),
- await createTestTripsRepo(testDb),
- photosRepo,
- await createTestJourneyEntryPhotosRepo(testDb),
- await createTestPlacesRepo(testDb),
- release,
- );
+ t = await createTestModule({
+ db,
+ imports: [JourneyDomainModule],
+ overrides: [{ provide: StorageReleaseService, useValue: release }],
+ });
+ svc = t.get(JourneyDomainService);
+ orm = await createTestOrm(db);
});
-
beforeEach(() => {
- resetTestDb(testDb);
+ resetTestDb(db);
+ orm.clear();
});
-
-afterAll(() => {
- testDb.close();
+afterAll(async () => {
+ await orm.close();
+ await t.close();
+ db.close();
});
describe('deleteJourney and its gallery', () => {
it('JOURNEY-SVC-022b: deleting a journey drops the photo rows only it held and releases their files', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const journey = await svc.createJourney(user.id, { title: 'J' });
const [photo, video] = await svc.uploadGalleryPhotos(journey.id, user.id, [
{ path: 'journey/a.jpg' },
@@ -88,10 +71,10 @@ describe('deleteJourney and its gallery', () => {
});
it('JOURNEY-SVC-022c: a photo another journey or a trip still links keeps its row through the delete', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const journey = await svc.createJourney(user.id, { title: 'J' });
const other = await svc.createJourney(user.id, { title: 'Other' });
- const trip = createTrip(testDb, user.id);
+ const trip = await makeTrip(orm, user.id);
const [shared, inTrip, alone] = await svc.uploadGalleryPhotos(journey.id, user.id, [
{ path: 'journey/shared.jpg' },
{ path: 'journey/trip.jpg' },
@@ -100,9 +83,7 @@ describe('deleteJourney and its gallery', () => {
// The same file uploaded to a second journey reuses its photo row.
const [again] = await svc.uploadGalleryPhotos(other.id, user.id, [{ path: 'journey/shared.jpg' }]);
expect(again.photo_id).toBe(shared.photo_id);
- testDb
- .prepare('INSERT INTO trip_photos (trip_id, user_id, photo_id) VALUES (?, ?, ?)')
- .run(trip.id, user.id, inTrip.photo_id);
+ await insertRow(orm, TripPhotos, { trip: trip.id, user: user.id, photo: inTrip.photo_id, shared: 1 });
expect(await svc.deleteJourney(journey.id, user.id)).toBe(true);
diff --git a/server/tests/unit/nest/notifications/storage-health-notifier.service.test.ts b/server/tests/unit/nest/notifications/storage-health-notifier.service.test.ts
index 4a0806bb3..18d38a77d 100644
--- a/server/tests/unit/nest/notifications/storage-health-notifier.service.test.ts
+++ b/server/tests/unit/nest/notifications/storage-health-notifier.service.test.ts
@@ -27,12 +27,18 @@ afterEach(() => {
else process.env.TREK_MANAGED = savedManaged;
});
+/** The notifier over a fresh event bus and `send`, subscribed the way bootstrap does it. */
+function subscribed(send: ReturnType<typeof vi.fn>): StorageEventsService {
+ const events = new StorageEventsService();
+ const notifier = new StorageHealthNotifierService(events, { send } as unknown as NotificationsService, t.orm);
+ notifier.onApplicationBootstrap();
+ return events;
+}
+
describe('StorageHealthNotifierService', () => {
it('NOTIF-001 subscribes on bootstrap and sends an admin-scoped replica_failure with params', () => {
- const events = new StorageEventsService();
const send = vi.fn().mockResolvedValue(undefined);
- const notifier = new StorageHealthNotifierService(events, { send } as unknown as NotificationsService, t.orm);
- notifier.onApplicationBootstrap();
+ const events = subscribed(send);
events.emitReplicaFailure({ backend: 's3-bkp', key: 'backups/db.zip', op: 'put', error: 'timeout', at: 1 });
expect(send).toHaveBeenCalledWith({
event: 'replica_failure',
@@ -47,19 +53,15 @@ describe('StorageHealthNotifierService', () => {
});
it('NOTIF-002 a rejected send never throws into the emitter (write path stays safe)', () => {
- const events = new StorageEventsService();
const send = vi.fn().mockRejectedValue(new Error('smtp down'));
- const notifier = new StorageHealthNotifierService(events, { send } as unknown as NotificationsService, t.orm);
- notifier.onApplicationBootstrap();
+ const events = subscribed(send);
expect(() => events.emitReplicaFailure({ backend: 'b', key: 'k', op: 'delete', error: 'e', at: 3 })).not.toThrow();
});
it('NOTIF-003 a managed install sends nothing, since its admins have no row to mute the alert', () => {
process.env.TREK_MANAGED = '1';
- const events = new StorageEventsService();
const send = vi.fn().mockResolvedValue(undefined);
- const notifier = new StorageHealthNotifierService(events, { send } as unknown as NotificationsService, t.orm);
- notifier.onApplicationBootstrap();
+ const events = subscribed(send);
events.emitReplicaFailure({ backend: 's3-bkp', key: 'backups/db.zip', op: 'put', error: 'timeout', at: 4 });
expect(send).not.toHaveBeenCalled();
});