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.

read: project incoming_leg_transport_mode via rowShape + getAssignmentWithPlace

Ida Rogalskaedb21b681f3e
diff --git a/server/src/nest/assignments/assignments.service.ts b/server/src/nest/assignments/assignments.service.ts
index 85523dffa..8e901a666 100644
--- a/server/src/nest/assignments/assignments.service.ts
+++ b/server/src/nest/assignments/assignments.service.ts
@@ -90,6 +90,7 @@ export class AssignmentsService {
assignment_time: a.assignment_time ?? null,
assignment_end_time: a.assignment_end_time ?? null,
leg_transport_mode: a.leg_transport_mode ?? null,
+ incoming_leg_transport_mode: a.incoming_leg_transport_mode ?? null,
participants,
created_at: a.created_at,
place: {
diff --git a/server/src/nest/common/rowShape.ts b/server/src/nest/common/rowShape.ts
index 3b7f2c2a8..4e69b5379 100644
--- a/server/src/nest/common/rowShape.ts
+++ b/server/src/nest/common/rowShape.ts
@@ -19,6 +19,7 @@ export function formatAssignmentWithPlace(a: AssignmentRow, tags: Partial<Tag>[]
assignment_time: a.assignment_time ?? null,
assignment_end_time: a.assignment_end_time ?? null,
leg_transport_mode: a.leg_transport_mode ?? null,
+ incoming_leg_transport_mode: a.incoming_leg_transport_mode ?? null,
participants: participants || [],
created_at: a.created_at,
place: {
diff --git a/server/tests/integration/leg-mode-incoming.test.ts b/server/tests/integration/leg-mode-incoming.test.ts
index de5daf021..2f3a34e4b 100644
--- a/server/tests/integration/leg-mode-incoming.test.ts
+++ b/server/tests/integration/leg-mode-incoming.test.ts
@@ -1,7 +1,12 @@
/**
- * Migration test for incoming_leg_transport_mode on day_assignments.
+ * Migration test for incoming_leg_transport_mode on day_assignments, plus
+ * read-path parity: the field must survive both the single-assignment
+ * projection and the day-LIST projection.
*/
-import { describe, it, expect, beforeAll, afterAll } from 'vitest';
+import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
+import request from 'supertest';
+import type { Application } from 'express';
+import type { INestApplication } from '@nestjs/common';
const Database = require('better-sqlite3');
@@ -28,3 +33,95 @@ describe('incoming_leg_transport_mode migration', () => {
expect(cols.map(c => c.name)).toContain('incoming_leg_transport_mode');
});
});
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Read-path parity (day-LIST endpoint) — mirrors the harness in
+// tests/integration/assignments.test.ts verbatim.
+// ─────────────────────────────────────────────────────────────────────────────
+
+const { testDb2, dbMock } = vi.hoisted(() => {
+ const Database2 = require('better-sqlite3');
+ const db = new Database2(':memory:');
+ db.exec('PRAGMA journal_mode = WAL');
+ db.exec('PRAGMA foreign_keys = ON');
+ db.exec('PRAGMA busy_timeout = 5000');
+ const mock = {
+ db,
+ closeDb: () => {},
+ reinitialize: () => {},
+ getPlaceWithTags: (placeId: number) => {
+ const place: any = db.prepare(`SELECT p.*, c.name as category_name, c.color as category_color, c.icon as category_icon FROM places p LEFT JOIN categories c ON p.category_id = c.id WHERE p.id = ?`).get(placeId);
+ if (!place) return null;
+ const tags = db.prepare(`SELECT t.* FROM tags t JOIN place_tags pt ON t.id = pt.tag_id WHERE pt.place_id = ?`).all(placeId);
+ return { ...place, category: place.category_id ? { id: place.category_id, name: place.category_name, color: place.category_color, icon: place.category_icon } : null, tags };
+ },
+ canAccessTrip: (tripId: any, userId: number) =>
+ db.prepare(`SELECT t.id, t.user_id FROM trips t LEFT JOIN trip_members m ON m.trip_id = t.id AND m.user_id = ? WHERE t.id = ? AND (t.user_id = ? OR m.user_id IS NOT NULL)`).get(userId, tripId, userId),
+ isOwner: (tripId: any, userId: number) =>
+ !!db.prepare('SELECT id FROM trips WHERE id = ? AND user_id = ?').get(tripId, userId),
+ };
+ return { testDb2: db, dbMock: mock };
+});
+
+vi.mock('../../src/db/database', () => dbMock);
+vi.mock('../../src/config', () => ({
+ JWT_SECRET: 'test-jwt-secret-for-trek-testing-only',
+ ENCRYPTION_KEY: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2',
+ updateJwtSecret: () => {},
+ SESSION_DURATION: '24h',
+ SESSION_DURATION_MS: 86400000,
+ SESSION_DURATION_SECONDS: 86400,
+ DEFAULT_LANGUAGE: 'en',
+}));
+vi.mock('../../src/websocket', () => ({ broadcast: vi.fn(), broadcastToUser: vi.fn() }));
+
+import { buildApp } from '../../src/bootstrap';
+import { resetTestDb, resetRateLimits } from '../helpers/test-db';
+import { createUser, createTrip, createDay, createPlace } from '../helpers/factories';
+import { authCookie } from '../helpers/auth';
+
+describe('incoming_leg_transport_mode read-path parity', () => {
+ let nestApp: INestApplication;
+ let app: Application;
+
+ beforeAll(async () => {
+ createTables(testDb2);
+ runMigrations(testDb2);
+ nestApp = await buildApp();
+ app = nestApp.getHttpAdapter().getInstance();
+ });
+
+ beforeEach(() => {
+ resetTestDb(testDb2);
+ resetRateLimits(nestApp);
+ });
+
+ afterAll(async () => {
+ await nestApp.close();
+ testDb2.close();
+ });
+
+ it('round-trips incoming_leg_transport_mode through the day-LIST endpoint', async () => {
+ const { user } = createUser(testDb2);
+ const trip = createTrip(testDb2, user.id);
+ const day = createDay(testDb2, trip.id, { date: '2025-06-01' });
+ const place = createPlace(testDb2, trip.id, { name: 'Test Place' });
+
+ const create = await request(app)
+ .post(`/api/trips/${trip.id}/days/${day.id}/assignments`)
+ .set('Cookie', authCookie(user.id))
+ .send({ place_id: place.id });
+ expect(create.status).toBe(201);
+ const assignmentId = create.body.assignment.id;
+
+ testDb2.prepare('UPDATE day_assignments SET incoming_leg_transport_mode = ? WHERE id = ?').run('transit', assignmentId);
+
+ const res = await request(app)
+ .get(`/api/trips/${trip.id}/days`)
+ .set('Cookie', authCookie(user.id));
+ expect(res.status).toBe(200);
+ const foundDay = res.body.days.find((d: any) => d.id === day.id);
+ const a = foundDay.assignments.find((x: any) => x.id === assignmentId);
+ expect(a.incoming_leg_transport_mode).toBe('transit');
+ });
+});