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.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
test(tours): type the tours tests against the current contracts
Maurice5ae8ac8e70c0
diff --git a/server/tests/e2e/tours-activity-stats.e2e.test.ts b/server/tests/e2e/tours-activity-stats.e2e.test.tsindex f7f24ebe0..39b92efda 100644--- a/server/tests/e2e/tours-activity-stats.e2e.test.ts+++ b/server/tests/e2e/tours-activity-stats.e2e.test.ts@@ -111,7 +111,7 @@ describe('Tour activity stats e2e (STA-02)', () => {return { placeId, assignmentId };};- const exclude = (body: unknown, userId = OWNER) =>+ const exclude = (body: object, userId = OWNER) =>request(server).put(`${STATS}/exclusions`).set(as(userId)).send(body);beforeAll(async () => {diff --git a/server/tests/e2e/tours-activity.e2e.test.ts b/server/tests/e2e/tours-activity.e2e.test.tsindex 54f1e9c2e..9767b661a 100644--- a/server/tests/e2e/tours-activity.e2e.test.ts+++ b/server/tests/e2e/tours-activity.e2e.test.ts@@ -132,7 +132,7 @@ describe('Tour activities e2e (ACT-01)', () => {return res.body.tours[0] as { place_id: number; track_started_at: string | null };};- const assign = (placeId: number, body: unknown, userId = OWNER) =>+ const assign = (placeId: number, body: object, userId = OWNER) =>request(server).put(`/api/trips/${TRIP}/tours/${placeId}/activities`).set(as(userId)).send(body);const unassign = (placeId: number, activityId: number, userId = OWNER) =>request(server).delete(`/api/trips/${TRIP}/tours/${placeId}/activities/${activityId}`).set(as(userId));diff --git a/server/tests/unit/db/repositories/CollectionTours.repository.test.ts b/server/tests/unit/db/repositories/CollectionTours.repository.test.tsindex d39b54e85..d3374ef2a 100644--- a/server/tests/unit/db/repositories/CollectionTours.repository.test.ts+++ b/server/tests/unit/db/repositories/CollectionTours.repository.test.ts@@ -66,6 +66,11 @@ function snapshot(collectionId: number, savedBy: number | null, overrides: Partimatch_confidence: 1,max_hiking_difficulty: 3,bike_profile: null,+ winter_activity: null,+ run_profile: null,+ run_pace_seconds_per_km: null,+ ski_discipline: null,+ ski_technique: null,boat_type: null,water_context: null,paddle_speed_kmh: null,@@ -75,6 +80,8 @@ function snapshot(collectionId: number, savedBy: number | null, overrides: Partihiking_preferences: null,origin: 'trek',origin_file_name: null,+ track_started_at: null,+ track_ended_at: null,source_trip_title: 'Alps',source_tour_name: 'Ridge',...overrides,diff --git a/server/tests/unit/nest/tour-change-save.mcp.test.ts b/server/tests/unit/nest/tour-change-save.mcp.test.tsindex 144cb34bc..5142d4b17 100644--- a/server/tests/unit/nest/tour-change-save.mcp.test.ts+++ b/server/tests/unit/nest/tour-change-save.mcp.test.ts@@ -40,6 +40,7 @@ import { MikroORM } from '@mikro-orm/core';import { stationKeySchema, TOUR_REVISION_CONFLICT, type TourChange, type TourChangeSaveRequest } from '@trek/shared';import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';+import { z, type ZodRawShape } from 'zod';const db = createSnapshotTestDb();const route = vi.fn();@@ -381,7 +382,13 @@ describe('TourChangeMcp.saveTourChange (MCP-T03)', () => {it('TCHG-SAVE-008: the write of a tour needs a point to start at when it comes without a line', async () => {const err = await refusal(- t.get(ToursService).routeWrite({ name: 'Old town', tour_type: 'walk', route_geometry: null, waypoints: [] }),+ t.get(ToursService).routeWrite({+ name: 'Old town',+ tour_type: 'walk',+ max_hiking_difficulty: null,+ route_geometry: null,+ waypoints: [],+ }),);expect([err.getStatus(), err.publicMessage]).toEqual([400, 'A tour needs at least two points']);});@@ -406,10 +413,12 @@ describe('TourChangeMcp.saveTourChange (MCP-T03)', () => {];for (const term of terms) expect(options.description).toContain(term);// The fields are zod schemas from @trek/shared, read here by what they answer.- const shape = options.inputSchema as Record<string, { safeParse(value: unknown): { success: boolean } }>;+ const shape = options.inputSchema as ZodRawShape;const fields = ['tripId', 'placeId', 'changes', 'expected_revision', 'proposal_id', 'confirmed'];expect(Object.keys(shape)).toEqual(fields);- const yes = [true, false, undefined].map((value) => shape.confirmed?.safeParse(value).success);+ const confirmed = shape.confirmed;+ if (!confirmed) throw new Error('the tool takes no confirmed field');+ const yes = [true, false, undefined].map((value) => z.safeParse(confirmed, value).success);expect(yes).toEqual([true, false, false]);const isAddonEnabled = vi.fn(async (id: string) => id === 'tours');expect(await options.when?.(ctx(1), { addons: { isAddonEnabled } })).toBe(true);diff --git a/server/tests/unit/nest/tour-change-undo.mcp.test.ts b/server/tests/unit/nest/tour-change-undo.mcp.test.tsindex 3bbed1ffb..319ac8d01 100644--- a/server/tests/unit/nest/tour-change-undo.mcp.test.ts+++ b/server/tests/unit/nest/tour-change-undo.mcp.test.ts@@ -45,6 +45,7 @@ import { MikroORM } from '@mikro-orm/core';import { TOUR_REVISION_CONFLICT, type TourChange, type TourChangeUndoRequest } from '@trek/shared';import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';+import { z, type ZodRawShape } from 'zod';const db = createSnapshotTestDb();const route = vi.fn();@@ -507,8 +508,10 @@ describe('TourChangeUndoMcp (MCP-T04)', () => {const entry = getEntry(TourChangeUndoMcp as unknown as ClassRef, 'undoTourChange');if (!entry || entry.kind !== 'tool') throw new Error('undoTourChange is no MCP tool');// The fields are zod schemas from @trek/shared, read here by what they answer.- const shape = entry.options.inputSchema as Record<string, { safeParse(value: unknown): { success: boolean } }>;- const yes = [true, false, undefined].map((value) => shape.confirmed?.safeParse(value).success);+ const shape = entry.options.inputSchema as ZodRawShape;+ const confirmed = shape.confirmed;+ if (!confirmed) throw new Error('the tool takes no confirmed field');+ const yes = [true, false, undefined].map((value) => z.safeParse(confirmed, value).success);expect(yes).toEqual([true, false, false]);for (const term of ['prepare_tour_undo', 'expected_revision', 'conflict', 'get_tour_plan']) {expect(entry.options.description).toContain(term);diff --git a/server/tests/unit/nest/tours.service.test.ts b/server/tests/unit/nest/tours.service.test.tsindex cb7662697..cbc9ce720 100644--- a/server/tests/unit/nest/tours.service.test.ts+++ b/server/tests/unit/nest/tours.service.test.ts@@ -785,6 +785,10 @@ describe('ToursService stages on days (MDT-02)', () => {return { created, placeId, keys, days, held };}+ /** An edit of the hut-to-hut tour as the API takes it: the points a read gave back go through the request contract. */+ const editOf = (changes: Record<string, unknown>): TourCreateRequest =>+ tourCreateRequestSchema.parse({ ...hutToHut, ...changes });+const heldStages = async (placeId: number) =>(await findRows(await sharedTestOrm(testDb), DayAssignments, { place: placeId }, { id: 'asc' })).map((row) => row.tour_stage_key,@@ -810,7 +814,7 @@ describe('ToursService stages on days (MDT-02)', () => {const joined = created.waypoints.map(({ stage_end: _end, ...point }, index) =>index === 1 ? { ...point, stage_end: true } : point,);- await service.updateTour(tripId, String(placeId), { ...hutToHut, waypoints: joined }, 'socket');+ await service.updateTour(tripId, String(placeId), editOf({ waypoints: joined }), 'socket');expect(await heldStages(placeId)).toEqual([keys[0], keys[1]]);expect(broadcast).toHaveBeenCalledWith(tripId,@@ -825,7 +829,7 @@ describe('ToursService stages on days (MDT-02)', () => {it('MDT-SVC-006: a change that keeps every stage leaves every day as it was and says nothing', async () => {const { created, placeId, keys } = await onThreeDays();- await service.updateTour(tripId, String(placeId), { ...hutToHut, name: 'Renamed', waypoints: created.waypoints });+ await service.updateTour(tripId, String(placeId), editOf({ name: 'Renamed', waypoints: created.waypoints }));expect(await heldStages(placeId)).toEqual(keys.slice(0, 3));expect(broadcast.mock.calls.filter(([, event]) => event === 'assignment:deleted')).toEqual([]);});@@ -852,7 +856,7 @@ describe('ToursService stages on days (MDT-02)', () => {const warn = vi.spyOn(Logger.prototype, 'warn').mockImplementation(() => undefined);const dayTour = created.waypoints.map(({ stage_end: _end, ...point }) => point);await expect(- service.updateTour(tripId, String(placeId), { ...hutToHut, duration_seconds: 3600, waypoints: dayTour }),+ service.updateTour(tripId, String(placeId), editOf({ duration_seconds: 3600, waypoints: dayTour })),).resolves.toMatchObject({ tour: { stage_count: null } });expect(await heldStages(placeId)).toEqual([]);expect(warn).toHaveBeenCalled();