mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
Fold the journey domain into Nest and finish the MCP migration
journeyService (1324 LOC, 36 exports) and journeyShareService (203) become JourneyDomainService and JourneyShareService. Every SQL statement, error string and broadcast is the one that shipped. The two could never be split: the share service gates on isOwner, which lives in the domain service, so it injects it. JourneyDomainModule is a leaf carrying just the two services. Places, assignments and the plugin host each need a handful of journey functions; importing JourneyModule for that would drag MemoriesModule and both photo providers into their graphs. Same shape as TrekPhotosModule. The 23 tools in src/mcp/tools/journey.ts become JourneyMcp. src/mcp/tools/ is down to _shared.ts and registerTools() no longer fans out to anything. journey.bridge.ts keeps four exports, for the journey resources in src/mcp/resources.ts that register at import time. McpAccessMode is host-augmentable now. journey:share is neither read nor write, so the three share tools would have had to be opaque predicates - and predicates bypass the access policy entirely, invisible to the boot-time scope gate. A scope typo in one would ship as a silently ungated tool. McpAccessModeRegistry mirrors McpAccessGroupRegistry; unaugmented, mode stays 'read' | 'write'. Fixes a latent bug in tests/helpers/mcp-test-controllers.ts: it constructed PlacesService with five of eight arguments. tsconfig only includes src, so nothing typechecked it, and the missing dependencies were harmless until the journey skeleton hooks landed on the place write paths. journey.mcp.ts arrived from src/mcp/ at 14.5% branch coverage - the legacy registrar had no test file of its own. 40 tool tests take it to 93.4%, and 25 cases for the skeleton lifecycle, the photo gallery and the preference row take the domain service from 73.9% to 82.8%.
This commit is contained in:
@@ -48,7 +48,7 @@ vi.mock('../../src/db/database', () => ({
|
||||
vi.mock('../../src/websocket', () => ({ broadcast: vi.fn() }));
|
||||
|
||||
const { reconcileTripSkeletons } = vi.hoisted(() => ({ reconcileTripSkeletons: vi.fn() }));
|
||||
vi.mock('../../src/services/journeyService', () => ({ reconcileTripSkeletons }));
|
||||
import { JourneyDomainService } from '../../src/nest/journey/journey-domain.service';
|
||||
|
||||
import { PermissionsService } from '../../src/nest/permissions/permissions.service';
|
||||
|
||||
@@ -65,7 +65,10 @@ describe('Assignments e2e (real auth guard + temp SQLite)', () => {
|
||||
let app: Awaited<ReturnType<typeof build>>;
|
||||
|
||||
async function build() {
|
||||
const moduleRef = await Test.createTestingModule({ imports: [DatabaseModule, RealtimeModule, AssignmentsModule] }).compile();
|
||||
const moduleRef = await Test.createTestingModule({ imports: [DatabaseModule, RealtimeModule, AssignmentsModule] })
|
||||
.overrideProvider(JourneyDomainService)
|
||||
.useValue({ reconcileTripSkeletons })
|
||||
.compile();
|
||||
const nest = moduleRef.createNestApplication();
|
||||
nest.use(cookieParser());
|
||||
nest.useGlobalPipes(new ZodValidationPipe());
|
||||
|
||||
@@ -47,10 +47,10 @@ vi.mock('../../src/nest/memories/photo-resolver.service', async (importOriginal)
|
||||
const { jsvc } = vi.hoisted(() => ({
|
||||
jsvc: { listJourneys: vi.fn(), createJourney: vi.fn(), getJourneyFull: vi.fn() },
|
||||
}));
|
||||
vi.mock('../../src/services/journeyService', () => jsvc);
|
||||
import { JourneyDomainService } from '../../src/nest/journey/journey-domain.service';
|
||||
|
||||
const { sharesvc } = vi.hoisted(() => ({ sharesvc: { getPublicJourney: vi.fn() } }));
|
||||
vi.mock('../../src/services/journeyShareService', () => sharesvc);
|
||||
import { JourneyShareService } from '../../src/nest/journey/journey-share.service';
|
||||
|
||||
import { JourneyModule } from '../../src/nest/journey/journey.module';
|
||||
import { AddonsService } from '../../src/nest/addons/addons.service';
|
||||
@@ -62,6 +62,10 @@ describe('Journey e2e (real auth guard + temp SQLite)', () => {
|
||||
|
||||
async function build() {
|
||||
const moduleRef = await Test.createTestingModule({ imports: [DatabaseModule, JourneyModule] })
|
||||
.overrideProvider(JourneyDomainService)
|
||||
.useValue(jsvc)
|
||||
.overrideProvider(JourneyShareService)
|
||||
.useValue(sharesvc)
|
||||
.overrideProvider(AddonsService)
|
||||
.useValue({ isAddonEnabled })
|
||||
.compile();
|
||||
|
||||
@@ -59,7 +59,7 @@ vi.mock('../../src/db/database', () => ({
|
||||
db, canAccessTrip, isOwner: vi.fn(() => true), getPlaceWithTags, closeDb: () => {}, reinitialize: () => {},
|
||||
}));
|
||||
vi.mock('../../src/websocket', () => ({ broadcast: vi.fn() }));
|
||||
vi.mock('../../src/services/journeyService', () => ({ onPlaceCreated: vi.fn(), onPlaceUpdated: vi.fn(), onPlaceDeleted: vi.fn() }));
|
||||
import { JourneyDomainService } from '../../src/nest/journey/journey-domain.service';
|
||||
|
||||
import { PermissionsService } from '../../src/nest/permissions/permissions.service';
|
||||
|
||||
@@ -77,7 +77,10 @@ describe('Places e2e (real auth guard + temp SQLite)', () => {
|
||||
let app: Awaited<ReturnType<typeof build>>;
|
||||
|
||||
async function build() {
|
||||
const moduleRef = await Test.createTestingModule({ imports: [DatabaseModule, RealtimeModule, PlacesModule] }).compile();
|
||||
const moduleRef = await Test.createTestingModule({ imports: [DatabaseModule, RealtimeModule, PlacesModule] })
|
||||
.overrideProvider(JourneyDomainService)
|
||||
.useValue({ onPlaceCreated: vi.fn(), onPlaceUpdated: vi.fn(), onPlaceDeleted: vi.fn() })
|
||||
.compile();
|
||||
const nest = moduleRef.createNestApplication();
|
||||
nest.use(cookieParser());
|
||||
nest.useGlobalFilters(new TrekExceptionFilter());
|
||||
|
||||
@@ -51,6 +51,13 @@ import { VacayMcp } from '../../src/nest/vacay/vacay.mcp';
|
||||
import { VacayService } from '../../src/nest/vacay/vacay.service';
|
||||
import { RealtimeService } from '../../src/nest/realtime/realtime.service';
|
||||
import { QueryHelpersService } from '../../src/nest/query-helpers/query-helpers.service';
|
||||
import { JourneyMcp } from '../../src/nest/journey/journey.mcp';
|
||||
import { JourneyDomainService } from '../../src/nest/journey/journey-domain.service';
|
||||
import { JourneyShareService } from '../../src/nest/journey/journey-share.service';
|
||||
import { TrekPhotosRepository } from '../../src/nest/photos/trek-photos.repository';
|
||||
import { UnsplashService } from '../../src/nest/unsplash/unsplash.service';
|
||||
import { PlacePhotoCacheService } from '../../src/nest/place-photos/place-photo-cache.service';
|
||||
import { RuntimeEnvService } from '../../src/nest/app-config/runtime-env.service';
|
||||
import { makeNotificationsService, makeNotificationPreferencesService } from './notifications';
|
||||
|
||||
/**
|
||||
@@ -73,7 +80,17 @@ export function createMcpTestRegistry(): McpRegistry {
|
||||
const packingService = new PackingService(dbService, permissionsService, realtimeService);
|
||||
const collabService = new CollabService(dbService, permissionsService, realtimeService);
|
||||
const mapsService = new MapsService(dbService);
|
||||
const placesService = new PlacesService(dbService, permissionsService, realtimeService, mapsService, queryHelpersService);
|
||||
const journeyDomain = new JourneyDomainService(dbService, realtimeService, new TrekPhotosRepository(dbService));
|
||||
// The last three were previously omitted, which left them `undefined` at
|
||||
// runtime — silently fine while nothing called them, a TypeError the moment
|
||||
// the journey skeleton hooks landed on the place write paths. tsconfig only
|
||||
// includes `src`, so nothing here is typechecked; pass them for real.
|
||||
const placesService = new PlacesService(
|
||||
dbService, permissionsService, realtimeService, mapsService, queryHelpersService,
|
||||
new UnsplashService(dbService, new RuntimeEnvService()),
|
||||
new PlacePhotoCacheService(dbService, new RuntimeEnvService()),
|
||||
journeyDomain,
|
||||
);
|
||||
const reservationsService = new ReservationsService(dbService, permissionsService, budgetService, realtimeService);
|
||||
const tripsService = new TripsService(
|
||||
dbService,
|
||||
@@ -103,16 +120,17 @@ export function createMcpTestRegistry(): McpRegistry {
|
||||
new ReservationsMcp(reservationsService, daysService, budgetService, authService),
|
||||
new DayNotesMcp(new DayNotesService(dbService, permissionsService, realtimeService), authService),
|
||||
new DaysMcp(daysService, dbService, placesService, authService),
|
||||
new AssignmentsMcp(new AssignmentsService(dbService, permissionsService, realtimeService, queryHelpersService), daysService, authService),
|
||||
new AssignmentsMcp(new AssignmentsService(dbService, permissionsService, realtimeService, queryHelpersService, journeyDomain), daysService, authService),
|
||||
new CollabMcp(collabService, authService),
|
||||
new VacayMcp(new VacayService(dbService, realtimeService), authService),
|
||||
new TripsMcp(tripsService, todoService, collabService, authService),
|
||||
new ShareMcp(new ShareService(dbService, new SettingsService(dbService), permissionsService, queryHelpersService), authService),
|
||||
new MapsMcp(mapsService),
|
||||
new PlacesMcp(placesService, mapsService, dbService, authService),
|
||||
new PlacesMcp(placesService, mapsService, dbService, authService, journeyDomain),
|
||||
new CollectionsMcp(new CollectionsService(dbService, permissionsService, realtimeService), dbService, authService),
|
||||
new TransitMcp(new TransitService(), daysService, reservationsService, dbService, authService),
|
||||
new AtlasMcp(new AtlasService(dbService)),
|
||||
new JourneyMcp(journeyDomain, new JourneyShareService(dbService, journeyDomain)),
|
||||
new NotificationsMcp(makeNotificationsService(dbService, realtimeService), authService),
|
||||
],
|
||||
{ accessPolicy: trekMcpAccessPolicy, validateAccess: trekMcpValidateAccess },
|
||||
|
||||
@@ -42,7 +42,7 @@ vi.mock('../../../src/nest/addons/addons.bridge', async (importOriginal) => {
|
||||
import { createTables } from '../../../src/db/schema';
|
||||
import { runMigrations } from '../../../src/db/migrations';
|
||||
import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createUser } from '../../helpers/factories';
|
||||
import { createUser, createTrip } from '../../helpers/factories';
|
||||
import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';
|
||||
|
||||
beforeAll(() => {
|
||||
@@ -144,3 +144,350 @@ describe('Tool: update_journey_preferences', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The rest of the surface. The legacy registrar had no test file of its own —
|
||||
// the two hydration cases above were the whole of it — so every tool below is
|
||||
// covered here for the first time: the happy path, the "not found or access
|
||||
// denied" branch a non-member hits, and the demo-mode denial on writes.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** A journey owned by someone else — every access check must refuse it. */
|
||||
function foreignJourney() {
|
||||
const { user: other } = createUser(testDb);
|
||||
const j = testDb.prepare(
|
||||
'INSERT INTO journeys (user_id, title, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?)',
|
||||
).run(other.id, 'Not yours', 'draft', Date.now(), Date.now());
|
||||
return { otherId: other.id, journeyId: Number(j.lastInsertRowid) };
|
||||
}
|
||||
|
||||
async function seedJourney(h: McpHarness, title = 'J') {
|
||||
return (parseToolResult(await h.client.callTool({
|
||||
name: 'create_journey', arguments: { title },
|
||||
})) as any).journey;
|
||||
}
|
||||
|
||||
describe('journey read tools', () => {
|
||||
it('list_journeys returns the caller-visible journeys', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
await seedJourney(h, 'Alpha');
|
||||
const data = parseToolResult(await h.client.callTool({ name: 'list_journeys', arguments: {} })) as any;
|
||||
expect(data.journeys.map((j: any) => j.title)).toContain('Alpha');
|
||||
});
|
||||
});
|
||||
|
||||
it('get_journey hydrates entries, contributors and trips', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const data = parseToolResult(await h.client.callTool({
|
||||
name: 'get_journey', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(data.journey.id).toBe(journey.id);
|
||||
expect(Array.isArray(data.journey.entries)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('get_journey refuses a journey the caller cannot see', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({ name: 'get_journey', arguments: { journeyId } });
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('list_journey_entries returns the entries', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
await h.client.callTool({
|
||||
name: 'create_journey_entry', arguments: { journeyId: journey.id, entry_date: '2026-07-01', title: 'D1' },
|
||||
});
|
||||
const data = parseToolResult(await h.client.callTool({
|
||||
name: 'list_journey_entries', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(data.entries).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('list_journey_entries refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({ name: 'list_journey_entries', arguments: { journeyId } });
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('list_journey_contributors returns the contributor rows', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const data = parseToolResult(await h.client.callTool({
|
||||
name: 'list_journey_contributors', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(Array.isArray(data.contributors)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('list_journey_contributors refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({ name: 'list_journey_contributors', arguments: { journeyId } });
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('get_journey_suggestions and list_journey_available_trips answer with arrays', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const s = parseToolResult(await h.client.callTool({ name: 'get_journey_suggestions', arguments: {} })) as any;
|
||||
const t = parseToolResult(await h.client.callTool({ name: 'list_journey_available_trips', arguments: {} })) as any;
|
||||
expect(Array.isArray(s.trips)).toBe(true);
|
||||
expect(Array.isArray(t.trips)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('journey write tools', () => {
|
||||
it('update_journey applies the change and refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const updated = parseToolResult(await h.client.callTool({
|
||||
name: 'update_journey', arguments: { journeyId: journey.id, title: 'Renamed', status: 'active' },
|
||||
})) as any;
|
||||
expect(updated.journey.title).toBe('Renamed');
|
||||
const denied = await h.client.callTool({ name: 'update_journey', arguments: { journeyId, title: 'X' } });
|
||||
expect(denied.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('delete_journey removes it and refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const gone = parseToolResult(await h.client.callTool({
|
||||
name: 'delete_journey', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(gone.success).toBe(true);
|
||||
const denied = await h.client.callTool({ name: 'delete_journey', arguments: { journeyId } });
|
||||
expect(denied.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('add_journey_trip links a trip, remove_journey_trip unlinks it', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const added = parseToolResult(await h.client.callTool({
|
||||
name: 'add_journey_trip', arguments: { journeyId: journey.id, tripId: trip.id },
|
||||
})) as any;
|
||||
expect(added.success).toBe(true);
|
||||
const removed = parseToolResult(await h.client.callTool({
|
||||
name: 'remove_journey_trip', arguments: { journeyId: journey.id, tripId: trip.id },
|
||||
})) as any;
|
||||
expect(removed.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('add_journey_trip refuses a foreign journey; remove_journey_trip is idempotent but refuses one', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
expect((await h.client.callTool({
|
||||
name: 'add_journey_trip', arguments: { journeyId, tripId: trip.id },
|
||||
})).isError).toBe(true);
|
||||
// Unlinking a trip that was never linked is a no-op, not an error — the
|
||||
// gate is journey ownership, not whether the row existed.
|
||||
expect((parseToolResult(await h.client.callTool({
|
||||
name: 'remove_journey_trip', arguments: { journeyId: journey.id, tripId: trip.id },
|
||||
})) as any).success).toBe(true);
|
||||
expect((await h.client.callTool({
|
||||
name: 'remove_journey_trip', arguments: { journeyId, tripId: trip.id },
|
||||
})).isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('create_journey_entry refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({
|
||||
name: 'create_journey_entry', arguments: { journeyId, entry_date: '2026-07-01' },
|
||||
});
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('update_journey_entry and delete_journey_entry refuse an unknown entry', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
expect((await h.client.callTool({
|
||||
name: 'update_journey_entry', arguments: { entryId: 999999, title: 'X' },
|
||||
})).isError).toBe(true);
|
||||
expect((await h.client.callTool({
|
||||
name: 'delete_journey_entry', arguments: { entryId: 999999 },
|
||||
})).isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('delete_journey_entry removes an owned entry', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const entry = (parseToolResult(await h.client.callTool({
|
||||
name: 'create_journey_entry', arguments: { journeyId: journey.id, entry_date: '2026-07-01' },
|
||||
})) as any).entry;
|
||||
const data = parseToolResult(await h.client.callTool({
|
||||
name: 'delete_journey_entry', arguments: { entryId: entry.id },
|
||||
})) as any;
|
||||
expect(data.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('reorder_journey_entries reorders, and rejects IDs from outside the journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const a = (parseToolResult(await h.client.callTool({
|
||||
name: 'create_journey_entry', arguments: { journeyId: journey.id, entry_date: '2026-07-01', title: 'A' },
|
||||
})) as any).entry;
|
||||
const b = (parseToolResult(await h.client.callTool({
|
||||
name: 'create_journey_entry', arguments: { journeyId: journey.id, entry_date: '2026-07-02', title: 'B' },
|
||||
})) as any).entry;
|
||||
const reordered = parseToolResult(await h.client.callTool({
|
||||
name: 'reorder_journey_entries', arguments: { journeyId: journey.id, orderedIds: [b.id, a.id] },
|
||||
})) as any;
|
||||
expect(reordered.success).toBe(true);
|
||||
expect((await h.client.callTool({
|
||||
name: 'reorder_journey_entries', arguments: { journeyId: journey.id, orderedIds: [999999] },
|
||||
})).isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('contributor tools add, re-role and remove; each refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { user: guest } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
expect((parseToolResult(await h.client.callTool({
|
||||
name: 'add_journey_contributor', arguments: { journeyId: journey.id, targetUserId: guest.id, role: 'editor' },
|
||||
})) as any).success).toBe(true);
|
||||
expect((parseToolResult(await h.client.callTool({
|
||||
name: 'update_journey_contributor_role', arguments: { journeyId: journey.id, targetUserId: guest.id, role: 'viewer' },
|
||||
})) as any).success).toBe(true);
|
||||
expect((parseToolResult(await h.client.callTool({
|
||||
name: 'remove_journey_contributor', arguments: { journeyId: journey.id, targetUserId: guest.id },
|
||||
})) as any).success).toBe(true);
|
||||
|
||||
for (const name of ['add_journey_contributor', 'update_journey_contributor_role']) {
|
||||
expect((await h.client.callTool({
|
||||
name, arguments: { journeyId, targetUserId: guest.id, role: 'editor' },
|
||||
})).isError).toBe(true);
|
||||
}
|
||||
expect((await h.client.callTool({
|
||||
name: 'remove_journey_contributor', arguments: { journeyId, targetUserId: guest.id },
|
||||
})).isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('update_journey_preferences refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({
|
||||
name: 'update_journey_preferences', arguments: { journeyId, hide_skeletons: true },
|
||||
});
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('journey share-link tools', () => {
|
||||
it('creates, reads and revokes the link', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
// No link yet — the tool answers with a null shareLink, not an error.
|
||||
const empty = parseToolResult(await h.client.callTool({
|
||||
name: 'get_journey_share_link', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(empty.shareLink ?? null).toBeNull();
|
||||
|
||||
const created = parseToolResult(await h.client.callTool({
|
||||
name: 'create_journey_share_link', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(created.shareLink).toBeTruthy();
|
||||
|
||||
const read = parseToolResult(await h.client.callTool({
|
||||
name: 'get_journey_share_link', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(read.shareLink).toBeTruthy();
|
||||
|
||||
const revoked = parseToolResult(await h.client.callTool({
|
||||
name: 'delete_journey_share_link', arguments: { journeyId: journey.id },
|
||||
})) as any;
|
||||
expect(revoked.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('every share tool refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = foreignJourney();
|
||||
await withHarness(user.id, async (h) => {
|
||||
for (const name of ['get_journey_share_link', 'create_journey_share_link', 'delete_journey_share_link']) {
|
||||
expect((await h.client.callTool({ name, arguments: { journeyId } })).isError).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('demo mode', () => {
|
||||
// The read tools are deliberately NOT demo-gated, matching the legacy
|
||||
// registrar: only the writes and the share-link mutations refuse.
|
||||
const WRITES: Array<[string, Record<string, unknown>]> = [
|
||||
['create_journey', { title: 'X' }],
|
||||
['update_journey', { journeyId: 1, title: 'X' }],
|
||||
['delete_journey', { journeyId: 1 }],
|
||||
['add_journey_trip', { journeyId: 1, tripId: 1 }],
|
||||
['remove_journey_trip', { journeyId: 1, tripId: 1 }],
|
||||
['create_journey_entry', { journeyId: 1, entry_date: '2026-07-01' }],
|
||||
['update_journey_entry', { entryId: 1, title: 'X' }],
|
||||
['delete_journey_entry', { entryId: 1 }],
|
||||
['reorder_journey_entries', { journeyId: 1, orderedIds: [1] }],
|
||||
['add_journey_contributor', { journeyId: 1, targetUserId: 2, role: 'editor' }],
|
||||
['update_journey_contributor_role', { journeyId: 1, targetUserId: 2, role: 'viewer' }],
|
||||
['remove_journey_contributor', { journeyId: 1, targetUserId: 2 }],
|
||||
['update_journey_preferences', { journeyId: 1, hide_skeletons: true }],
|
||||
['create_journey_share_link', { journeyId: 1 }],
|
||||
['delete_journey_share_link', { journeyId: 1 }],
|
||||
];
|
||||
|
||||
it.each(WRITES)('%s is blocked for a demo user', async (name, args) => {
|
||||
process.env.DEMO_MODE = 'true';
|
||||
const { user } = createUser(testDb, { email: 'demo@nomad.app' });
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({ name, arguments: args });
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('list_journeys still answers for a demo user', async () => {
|
||||
process.env.DEMO_MODE = 'true';
|
||||
const { user } = createUser(testDb, { email: 'demo@nomad.app' });
|
||||
await withHarness(user.id, async (h) => {
|
||||
const data = parseToolResult(await h.client.callTool({ name: 'list_journeys', arguments: {} })) as any;
|
||||
expect(Array.isArray(data.journeys)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+436
-176
File diff suppressed because it is too large
Load Diff
+60
-59
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Unit tests for journeyShareService — JOURNEY-SHARE-001 through JOURNEY-SHARE-018.
|
||||
* Unit tests for JourneyShareService — JOURNEY-SHARE-001 through JOURNEY-SHARE-018.
|
||||
* Uses a real in-memory SQLite DB so SQL logic is exercised faithfully.
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||
@@ -34,14 +34,15 @@ import { createTables } from '../../../src/db/schema';
|
||||
import { runMigrations } from '../../../src/db/migrations';
|
||||
import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createUser, createJourney, createJourneyEntry } from '../../helpers/factories';
|
||||
import {
|
||||
createOrUpdateJourneyShareLink,
|
||||
getJourneyShareLink,
|
||||
deleteJourneyShareLink,
|
||||
validateShareTokenForPhoto,
|
||||
validateShareTokenForAsset,
|
||||
getPublicJourney,
|
||||
} from '../../../src/services/journeyShareService';
|
||||
import { DatabaseService } from '../../../src/nest/database/database.service';
|
||||
import { RealtimeService } from '../../../src/nest/realtime/realtime.service';
|
||||
import { TrekPhotosRepository } from '../../../src/nest/photos/trek-photos.repository';
|
||||
import { JourneyDomainService } from '../../../src/nest/journey/journey-domain.service';
|
||||
import { JourneyShareService } from '../../../src/nest/journey/journey-share.service';
|
||||
import { db as dbConn } from '../../../src/db/database';
|
||||
|
||||
const dbs = new DatabaseService(dbConn);
|
||||
const svc = new JourneyShareService(dbs, new JourneyDomainService(dbs, new RealtimeService(), new TrekPhotosRepository(dbs)));
|
||||
|
||||
beforeAll(() => {
|
||||
createTables(testDb);
|
||||
@@ -100,7 +101,7 @@ describe('createOrUpdateJourneyShareLink', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
|
||||
const result = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const result = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
expect(result.created).toBe(true);
|
||||
expect(result.token).toBeTruthy();
|
||||
@@ -111,13 +112,13 @@ describe('createOrUpdateJourneyShareLink', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
|
||||
createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true,
|
||||
share_gallery: false,
|
||||
share_map: false,
|
||||
});
|
||||
|
||||
const link = getJourneyShareLink(journey.id);
|
||||
const link = svc.getJourneyShareLink(journey.id);
|
||||
expect(link).not.toBeNull();
|
||||
expect(link!.share_timeline).toBe(true);
|
||||
expect(link!.share_gallery).toBe(false);
|
||||
@@ -128,12 +129,12 @@ describe('createOrUpdateJourneyShareLink', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
|
||||
const first = createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
const first = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true,
|
||||
share_gallery: true,
|
||||
share_map: true,
|
||||
});
|
||||
const second = createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
const second = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true,
|
||||
share_gallery: false,
|
||||
share_map: false,
|
||||
@@ -142,7 +143,7 @@ describe('createOrUpdateJourneyShareLink', () => {
|
||||
expect(second.created).toBe(false);
|
||||
expect(second.token).toBe(first.token);
|
||||
|
||||
const link = getJourneyShareLink(journey.id);
|
||||
const link = svc.getJourneyShareLink(journey.id);
|
||||
expect(link!.share_gallery).toBe(false);
|
||||
expect(link!.share_map).toBe(false);
|
||||
});
|
||||
@@ -152,8 +153,8 @@ describe('createOrUpdateJourneyShareLink', () => {
|
||||
const j1 = createJourney(testDb, user.id);
|
||||
const j2 = createJourney(testDb, user.id);
|
||||
|
||||
const r1 = createOrUpdateJourneyShareLink(j1.id, user.id, {});
|
||||
const r2 = createOrUpdateJourneyShareLink(j2.id, user.id, {});
|
||||
const r1 = svc.createOrUpdateJourneyShareLink(j1.id, user.id, {});
|
||||
const r2 = svc.createOrUpdateJourneyShareLink(j2.id, user.id, {});
|
||||
|
||||
expect(r1.token).not.toBe(r2.token);
|
||||
});
|
||||
@@ -164,7 +165,7 @@ describe('getJourneyShareLink', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
|
||||
const result = getJourneyShareLink(journey.id);
|
||||
const result = svc.getJourneyShareLink(journey.id);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
@@ -172,13 +173,13 @@ describe('getJourneyShareLink', () => {
|
||||
it('JOURNEY-SHARE-006: returns share link info when it exists', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true,
|
||||
share_gallery: false,
|
||||
share_map: true,
|
||||
});
|
||||
|
||||
const result = getJourneyShareLink(journey.id);
|
||||
const result = svc.getJourneyShareLink(journey.id);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.token).toBeTruthy();
|
||||
@@ -193,19 +194,19 @@ describe('deleteJourneyShareLink', () => {
|
||||
it('JOURNEY-SHARE-007: owner can remove an existing share link', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
const ok = deleteJourneyShareLink(journey.id, user.id);
|
||||
const ok = svc.deleteJourneyShareLink(journey.id, user.id);
|
||||
|
||||
expect(ok).toBe(true);
|
||||
expect(getJourneyShareLink(journey.id)).toBeNull();
|
||||
expect(svc.getJourneyShareLink(journey.id)).toBeNull();
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-008: does not throw when deleting non-existent link', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
|
||||
expect(() => deleteJourneyShareLink(journey.id, user.id)).not.toThrow();
|
||||
expect(() => svc.deleteJourneyShareLink(journey.id, user.id)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -215,9 +216,9 @@ describe('validateShareTokenForPhoto', () => {
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const entry = createJourneyEntry(testDb, journey.id, user.id);
|
||||
const photoId = insertJourneyPhoto(entry.id, { ownerId: user.id });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
const result = validateShareTokenForPhoto(token, photoId);
|
||||
const result = svc.validateShareTokenForPhoto(token, photoId);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.journeyId).toBe(journey.id);
|
||||
@@ -225,7 +226,7 @@ describe('validateShareTokenForPhoto', () => {
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-010: returns null for invalid token', () => {
|
||||
const result = validateShareTokenForPhoto('nonexistent-token', 1);
|
||||
const result = svc.validateShareTokenForPhoto('nonexistent-token', 1);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
@@ -235,9 +236,9 @@ describe('validateShareTokenForPhoto', () => {
|
||||
const journey2 = createJourney(testDb, user.id);
|
||||
const entry2 = createJourneyEntry(testDb, journey2.id, user.id);
|
||||
const photoId = insertJourneyPhoto(entry2.id);
|
||||
const { token } = createOrUpdateJourneyShareLink(journey1.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey1.id, user.id, {});
|
||||
|
||||
const result = validateShareTokenForPhoto(token, photoId);
|
||||
const result = svc.validateShareTokenForPhoto(token, photoId);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
@@ -247,9 +248,9 @@ describe('validateShareTokenForPhoto', () => {
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const entry = createJourneyEntry(testDb, journey.id, user.id);
|
||||
const photoId = insertJourneyPhoto(entry.id, { ownerId: undefined });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
const result = validateShareTokenForPhoto(token, photoId);
|
||||
const result = svc.validateShareTokenForPhoto(token, photoId);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.ownerId).toBe(user.id);
|
||||
@@ -261,9 +262,9 @@ describe('validateShareTokenForPhoto', () => {
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const entry = createJourneyEntry(testDb, journey.id, user.id);
|
||||
const photoId = insertJourneyPhoto(entry.id, { ownerId: user.id });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, { share_timeline: true, share_gallery: false, share_map: true });
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, { share_timeline: true, share_gallery: false, share_map: true });
|
||||
|
||||
expect(validateShareTokenForPhoto(token, photoId)).toBeNull();
|
||||
expect(svc.validateShareTokenForPhoto(token, photoId)).toBeNull();
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-016: resolves correctly when trek_photos.id differs from journey_photos.id (Immich bulk-sync scenario)', () => {
|
||||
@@ -281,10 +282,10 @@ describe('validateShareTokenForPhoto', () => {
|
||||
|
||||
// This trek_photos row gets a high id (e.g. 6) while journey_photos id will be 1
|
||||
const trekPhotoId = insertJourneyPhoto(entry.id, { assetId: 'journey-asset-xyz', ownerId: user.id });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
// photoId = trek_photos.id (6), not journey_photos.id (1)
|
||||
const result = validateShareTokenForPhoto(token, trekPhotoId);
|
||||
const result = svc.validateShareTokenForPhoto(token, trekPhotoId);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.ownerId).toBe(user.id);
|
||||
@@ -298,16 +299,16 @@ describe('validateShareTokenForAsset', () => {
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const entry = createJourneyEntry(testDb, journey.id, user.id);
|
||||
insertJourneyPhoto(entry.id, { assetId: 'immich-asset-123', ownerId: user.id });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
const result = validateShareTokenForAsset(token, 'immich-asset-123');
|
||||
const result = svc.validateShareTokenForAsset(token, 'immich-asset-123');
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.ownerId).toBe(user.id);
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-014: returns null for invalid token', () => {
|
||||
const result = validateShareTokenForAsset('bad-token', 'some-asset');
|
||||
const result = svc.validateShareTokenForAsset('bad-token', 'some-asset');
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
@@ -317,20 +318,20 @@ describe('validateShareTokenForAsset', () => {
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const entry = createJourneyEntry(testDb, journey.id, user.id);
|
||||
insertJourneyPhoto(entry.id, { assetId: 'immich-asset-999', ownerId: user.id });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, { share_timeline: true, share_gallery: false, share_map: true });
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, { share_timeline: true, share_gallery: false, share_map: true });
|
||||
|
||||
expect(validateShareTokenForAsset(token, 'immich-asset-999')).toBeNull();
|
||||
expect(svc.validateShareTokenForAsset(token, 'immich-asset-999')).toBeNull();
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-015: denies (returns null) when the asset is not part of the shared journey', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
// A valid share token must NOT resolve arbitrary asset IDs to the owner —
|
||||
// otherwise it could proxy any asset out of the owner's Immich/Synology
|
||||
// library (IDOR). Only assets actually in the journey may resolve.
|
||||
const result = validateShareTokenForAsset(token, 'nonexistent-asset');
|
||||
const result = svc.validateShareTokenForAsset(token, 'nonexistent-asset');
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
@@ -338,7 +339,7 @@ describe('validateShareTokenForAsset', () => {
|
||||
|
||||
describe('getPublicJourney', () => {
|
||||
it('JOURNEY-SHARE-016: returns null for invalid token', () => {
|
||||
const result = getPublicJourney('invalid-token');
|
||||
const result = svc.getPublicJourney('invalid-token');
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
@@ -361,13 +362,13 @@ describe('getPublicJourney', () => {
|
||||
location_name: 'Kyoto',
|
||||
});
|
||||
insertJourneyPhoto(entry1.id);
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true,
|
||||
share_gallery: true,
|
||||
share_map: false,
|
||||
});
|
||||
|
||||
const result = getPublicJourney(token);
|
||||
const result = svc.getPublicJourney(token);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.journey.title).toBe('Japan 2026');
|
||||
@@ -394,9 +395,9 @@ describe('getPublicJourney', () => {
|
||||
title: 'Skeleton Entry',
|
||||
entry_date: '2026-01-11',
|
||||
});
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
const result = getPublicJourney(token);
|
||||
const result = svc.getPublicJourney(token);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.entries).toHaveLength(1);
|
||||
@@ -415,9 +416,9 @@ describe('getPublicJourney', () => {
|
||||
.run(JSON.stringify(['food', 'culture']), entry.id);
|
||||
insertJourneyPhoto(entry.id, { filePath: '/photos/a.jpg' });
|
||||
insertJourneyPhoto(entry.id, { filePath: '/photos/b.jpg' });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
const result = getPublicJourney(token);
|
||||
const result = svc.getPublicJourney(token);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
const enriched = result!.entries[0];
|
||||
@@ -428,9 +429,9 @@ describe('getPublicJourney', () => {
|
||||
it('JOURNEY-SHARE-020: returns empty entries array for journey with no entries', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id, { title: 'Empty Journey' });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {});
|
||||
|
||||
const result = getPublicJourney(token);
|
||||
const result = svc.getPublicJourney(token);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.entries).toEqual([]);
|
||||
@@ -447,11 +448,11 @@ describe('getPublicJourney', () => {
|
||||
});
|
||||
testDb.prepare('UPDATE journey_entries SET location_lat = ?, location_lng = ? WHERE id = ?').run(48.8566, 2.3522, entry.id);
|
||||
insertJourneyPhoto(entry.id);
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: false, share_gallery: false, share_map: false,
|
||||
});
|
||||
|
||||
const result = getPublicJourney(token)!;
|
||||
const result = svc.getPublicJourney(token)!;
|
||||
expect(result.entries).toEqual([]); // no timeline / story / GPS leaked
|
||||
expect(result.gallery).toEqual([]); // no gallery leaked
|
||||
expect(result.stats.entries).toBe(1); // counts stay accurate
|
||||
@@ -464,11 +465,11 @@ describe('getPublicJourney', () => {
|
||||
type: 'entry', title: 'Day 1', story: 'notes', entry_date: '2026-05-01', location_name: 'Paris',
|
||||
});
|
||||
testDb.prepare('UPDATE journey_entries SET location_lat = ?, location_lng = ? WHERE id = ?').run(48.8566, 2.3522, entry.id);
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true, share_gallery: true, share_map: false,
|
||||
});
|
||||
|
||||
const result = getPublicJourney(token)!;
|
||||
const result = svc.getPublicJourney(token)!;
|
||||
expect(result.entries).toHaveLength(1);
|
||||
const e = result.entries[0] as Record<string, unknown>;
|
||||
expect(e.story).toBe('notes'); // narrative present
|
||||
@@ -483,11 +484,11 @@ describe('getPublicJourney', () => {
|
||||
type: 'entry', title: 'Day 1', story: 'private notes', entry_date: '2026-05-01', location_name: 'Paris',
|
||||
});
|
||||
testDb.prepare('UPDATE journey_entries SET location_lat = ?, location_lng = ? WHERE id = ?').run(48.8566, 2.3522, entry.id);
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: false, share_gallery: false, share_map: true,
|
||||
});
|
||||
|
||||
const result = getPublicJourney(token)!;
|
||||
const result = svc.getPublicJourney(token)!;
|
||||
expect(result.entries).toHaveLength(1);
|
||||
const e = result.entries[0] as Record<string, unknown>;
|
||||
expect(e.location_lat).toBe(48.8566); // coords for the map
|
||||
@@ -501,11 +502,11 @@ describe('getPublicJourney', () => {
|
||||
type: 'entry', title: 'Day 1', story: 'notes', entry_date: '2026-05-01',
|
||||
});
|
||||
insertJourneyPhoto(entry.id, { ownerId: user.id });
|
||||
const { token } = createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true, share_gallery: false, share_map: true,
|
||||
});
|
||||
|
||||
const result = getPublicJourney(token)!;
|
||||
const result = svc.getPublicJourney(token)!;
|
||||
expect(result.gallery).toEqual([]); // gallery array withheld
|
||||
expect(result.entries).toHaveLength(1);
|
||||
expect((result.entries[0] as Record<string, unknown>).photos).toEqual([]); // inline photos withheld too
|
||||
@@ -19,7 +19,7 @@ vi.mock('../../../src/db/database', () => ({
|
||||
}));
|
||||
import { db as dbConn } from '../../../src/db/database';
|
||||
import { DatabaseService } from '../../../src/nest/database/database.service';
|
||||
vi.mock('../../../src/services/journeyService', () => ({ canAccessJourney }));
|
||||
import type { JourneyDomainService } from '../../../src/nest/journey/journey-domain.service';
|
||||
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
|
||||
|
||||
import { JournalEntryRowsController } from '../../../src/nest/plugins/journal-entry-rows.controller';
|
||||
@@ -35,7 +35,7 @@ function controller(invoke: (id: string) => unknown, providers = ['p1']) {
|
||||
providersOf: vi.fn(() => providers),
|
||||
invokeHook: vi.fn(async (id: string) => invoke(id)),
|
||||
} as unknown as PluginRuntimeService;
|
||||
return { c: new JournalEntryRowsController(runtime, new DatabaseService(dbConn), addonsStub), runtime };
|
||||
return { c: new JournalEntryRowsController(runtime, new DatabaseService(dbConn), addonsStub, { canAccessJourney } as unknown as JourneyDomainService), runtime };
|
||||
}
|
||||
const row = (over: Record<string, unknown> = {}) => ({ label: 'Distance', value: '12 km', ...over });
|
||||
|
||||
|
||||
@@ -243,14 +243,14 @@ const reservationsStub = {
|
||||
syncBudgetOnUpdate() {},
|
||||
notifyBookingChange() {},
|
||||
} as unknown as ReservationsService;
|
||||
vi.mock('../../../src/services/journeyService', () => ({
|
||||
// Consumed by the real assignments.service.ts module (loaded un-mocked as a
|
||||
// factory constructor dep); the instance is stubbed, so this is never called.
|
||||
reconcileTripSkeletons: vi.fn(),
|
||||
// Journey is a constructor-injected stub since the journey fold (same behaviors
|
||||
// as the old services/journeyService path mock, keyed by the service methods).
|
||||
const { onPlaceCreated, onPlaceUpdated, onPlaceDeleted } = vi.hoisted(() => ({
|
||||
onPlaceCreated: vi.fn(), onPlaceUpdated: vi.fn(), onPlaceDeleted: vi.fn(),
|
||||
}));
|
||||
const journeyStub = {
|
||||
// The skeleton hooks the place writes fire (#1705).
|
||||
onPlaceCreated: vi.fn(),
|
||||
onPlaceUpdated: vi.fn(),
|
||||
onPlaceDeleted: vi.fn(),
|
||||
onPlaceCreated, onPlaceUpdated, onPlaceDeleted,
|
||||
listJourneys: vi.fn((uid: number) => [{ id: 1, owner: uid }]),
|
||||
// journeyId 88 = no access (listEntries self-gates to null); else returns entries
|
||||
listEntries: vi.fn((journeyId: number, uid: number) => (journeyId === 88 ? null : [{ id: 10, journey_id: journeyId, author_id: uid }])),
|
||||
@@ -258,7 +258,9 @@ vi.mock('../../../src/services/journeyService', () => ({
|
||||
createEntry: vi.fn((journeyId: number, uid: number, data: unknown) => (journeyId === 99 ? null : { id: 120, journey_id: journeyId, created_by: uid, ...(data as object) })),
|
||||
updateEntry: vi.fn((entryId: number, _uid: number, data: unknown) => (entryId === 99 ? null : { id: entryId, ...(data as object) })),
|
||||
deleteEntry: vi.fn((entryId: number) => entryId !== 99),
|
||||
}));
|
||||
createJourney: vi.fn((uid: number, data: unknown) => ({ id: 130, owner: uid, ...(data as object) })),
|
||||
deleteJourney: vi.fn((journeyId: number) => journeyId !== 99),
|
||||
} as unknown as JourneyDomainService;
|
||||
// Atlas is a constructor-injected stub since the atlas fold (same behaviors as
|
||||
// the old services/atlasService path mock, keyed by the service method names).
|
||||
const atlasStub = {
|
||||
@@ -307,7 +309,6 @@ const vacayStub = {
|
||||
import { PluginHostDepsFactory, type PluginCallRouter } from '../../../src/nest/plugins/host/plugin-host-deps.factory';
|
||||
import { getPluginDataDb, closePluginDataDb } from '../../../src/nest/plugins/host/plugin-host-state';
|
||||
import { db as mockDb } from '../../../src/db/database';
|
||||
import { onPlaceCreated, onPlaceUpdated, onPlaceDeleted } from '../../../src/services/journeyService';
|
||||
import type { BudgetService } from '../../../src/nest/budget/budget.service';
|
||||
import type { ExchangeRatesService } from '../../../src/nest/budget/exchange-rates.service';
|
||||
import type { ReservationsService } from '../../../src/nest/reservations/reservations.service';
|
||||
@@ -318,6 +319,7 @@ import type { PackingService } from '../../../src/nest/packing/packing.service';
|
||||
import type { DayNotesService } from '../../../src/nest/days/day-notes.service';
|
||||
import type { DaysService } from '../../../src/nest/days/days.service';
|
||||
import type { AssignmentsService } from '../../../src/nest/assignments/assignments.service';
|
||||
import type { JourneyDomainService } from '../../../src/nest/journey/journey-domain.service';
|
||||
import type { PluginOAuthService } from '../../../src/nest/plugins/plugin-oauth.service';
|
||||
import type { LlmConfigResolver } from '../../../src/nest/llm-parse/llm-config.resolver';
|
||||
import type { FilesService } from '../../../src/nest/files/files.service';
|
||||
@@ -351,7 +353,7 @@ const tripsStub = {
|
||||
list: () => [{ id: 1 }],
|
||||
removeMember: vi.fn(),
|
||||
} as unknown as import('../../../src/nest/trips/trips.service').TripsService;
|
||||
const factory = new PluginHostDepsFactory(budgetStub, reservationsStub, tagsStub, categoriesStub, todoStub, packingStub, oauthStub, dayNotesStub, assignmentsStub, llmConfigStub, new DatabaseService(mockDb), filesStub, collabStub, vacayStub, daysStub, permissionsStub, exchangeRatesStub, addonsStub, new RealtimeService(), tripsStub, placesStub, collectionsStub, atlasStub, notificationsStub, membershipStub);
|
||||
const factory = new PluginHostDepsFactory(budgetStub, reservationsStub, tagsStub, categoriesStub, todoStub, packingStub, oauthStub, dayNotesStub, assignmentsStub, llmConfigStub, new DatabaseService(mockDb), filesStub, collabStub, vacayStub, daysStub, permissionsStub, exchangeRatesStub, addonsStub, new RealtimeService(), tripsStub, placesStub, collectionsStub, atlasStub, notificationsStub, membershipStub, journeyStub);
|
||||
const stubRouter: PluginCallRouter = { callPlugin: async () => undefined, emitPluginEvent: () => {} };
|
||||
const createRealRpcHost = (id: string, granted: ReadonlySet<string>, router: PluginCallRouter = stubRouter) => factory.create(id, granted, router);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user