mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
Tours: tests follow the provenance read and the shared day assignment, the tours addon ends MCP sessions, a line without a point is not copied
The repository stubs of the tour service tests answer findProvenance, which getTour and createTour read since P2C-02. Switching the Tours addon off now ends live MCP sessions like every other addon that gates a tool (MCP-GATE-PARITY-001). copyTour refuses a line without a point instead of placing the copy at 0/0, and new tests cover the reachable paths of the copy, the source check and the provenance of a snapshot without its import record, including a trip copy keeping that record. On the client the shared day assignment hands the plan exactly the tour and the day, the new visibility store is reset between tests, and the tests of the sidebar, the detail, the phone sheet and the origin section match the views this PR built.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import type { McpContext } from '../../../src/nest-mcp';
|
||||
import { ToursMcp } from '../../../src/nest/tours/tours.mcp';
|
||||
import { ToursModule } from '../../../src/nest/tours/tours.module';
|
||||
import { ToursService } from '../../../src/nest/tours/tours.service';
|
||||
import { createSnapshotTestDb } from '../../helpers/db-mock';
|
||||
import {
|
||||
addTripMember,
|
||||
@@ -20,7 +21,7 @@ import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createTestModule, type TestModule } from '../../helpers/test-module';
|
||||
import { createTour } from '../../helpers/tours-repos';
|
||||
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const db = createSnapshotTestDb();
|
||||
let t: TestModule;
|
||||
@@ -111,4 +112,15 @@ describe('ToursMcp', () => {
|
||||
error: 'Tour not found.',
|
||||
});
|
||||
});
|
||||
|
||||
it('TOURS-MCP-005: a failure other than a missing tour is not passed off as not found', async () => {
|
||||
const { user, trip, ridge } = fixture();
|
||||
const failure = new Error('database gone');
|
||||
const getTour = vi.spyOn(t.get(ToursService), 'getTour').mockRejectedValueOnce(failure);
|
||||
try {
|
||||
await expect(mcp.getTourPlan({ tripId: trip.id, placeId: ridge.id }, ctx(user.id))).rejects.toBe(failure);
|
||||
} finally {
|
||||
getTour.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ import 'reflect-metadata';
|
||||
import type { PlacesRepository } from '../../../src/db/repositories/Places.repository';
|
||||
import type { TourTypesRepository } from '../../../src/db/repositories/TourTypes.repository';
|
||||
import type { TourWaypointsRepository } from '../../../src/db/repositories/TourWaypoints.repository';
|
||||
import type { ToursRepository } from '../../../src/db/repositories/Tours.repository';
|
||||
import type { TourProvenanceRow, ToursRepository } from '../../../src/db/repositories/Tours.repository';
|
||||
import type { RuntimeEnvService } from '../../../src/nest/app-config/runtime-env.service';
|
||||
import { DayAssignmentsController } from '../../../src/nest/assignments/assignments.controller';
|
||||
import type { AssignmentsService } from '../../../src/nest/assignments/assignments.service';
|
||||
@@ -252,14 +252,36 @@ function tourRepositoryFixture(ownerTripId: number) {
|
||||
wanderer_ref: null,
|
||||
match_confidence: 1,
|
||||
max_hiking_difficulty: 2,
|
||||
origin: 'trek',
|
||||
planned: 0,
|
||||
has_waypoints: 1,
|
||||
};
|
||||
const provenance: TourProvenanceRow = {
|
||||
origin: 'trek',
|
||||
origin_file_name: null,
|
||||
created_at: null,
|
||||
wanderer_ref: null,
|
||||
has_recorded_track: 0,
|
||||
derived_from_place_id: null,
|
||||
derived_from_name: null,
|
||||
source_instance: null,
|
||||
source_external_id: null,
|
||||
source_external_url: null,
|
||||
source_external_updated: null,
|
||||
source_imported_at: null,
|
||||
source_content_hash: null,
|
||||
source_local_hash: null,
|
||||
route_geometry: null,
|
||||
name: 'Ridge walk',
|
||||
};
|
||||
const uow = { transactional: vi.fn(async <T>(fn: () => Promise<T>): Promise<T> => await fn()) };
|
||||
const toursRepo = {
|
||||
findInTrip: vi.fn(async (tripId: number, placeId: number) =>
|
||||
tripId === ownerTripId && placeId === 42 ? row : undefined,
|
||||
),
|
||||
findProvenance: vi.fn(async (tripId: number, placeId: number) =>
|
||||
tripId === ownerTripId && placeId === 42 ? provenance : undefined,
|
||||
),
|
||||
updateInTrip: vi.fn(async () => true),
|
||||
keepRecordedTrack: vi.fn(async () => undefined),
|
||||
};
|
||||
@@ -291,6 +313,7 @@ describe('Real ToursService update trip boundary (stubbed repositories)', () =>
|
||||
const f = tourRepositoryFixture(8);
|
||||
expect((await f.service.getTour('8', '42')).tour.place_id).toBe(42);
|
||||
f.toursRepo.findInTrip.mockClear();
|
||||
f.toursRepo.findProvenance.mockClear();
|
||||
f.waypointsRepo.listForPlace.mockClear();
|
||||
|
||||
const error: unknown = await f.service.updateTour('7', '42', input, 'socket').catch((e: unknown) => e);
|
||||
@@ -305,6 +328,7 @@ describe('Real ToursService update trip boundary (stubbed repositories)', () =>
|
||||
f.waypointsRepo.deleteForPlace,
|
||||
f.waypointsRepo.insertForPlace,
|
||||
f.waypointsRepo.listForPlace,
|
||||
f.toursRepo.findProvenance,
|
||||
f.placesRepo.findWithTagsAndRatings,
|
||||
f.places.broadcast,
|
||||
]) {
|
||||
@@ -337,5 +361,6 @@ describe('Real ToursService update trip boundary (stubbed repositories)', () =>
|
||||
expect(f.waypointsRepo.insertForPlace).toHaveBeenCalledExactlyOnceWith(42, input.waypoints);
|
||||
expect(f.placesRepo.findWithTagsAndRatings).toHaveBeenCalledWith(42);
|
||||
expect(f.places.broadcast).toHaveBeenCalledWith('7', 'place:updated', { place: { id: 42, trip_id: 7 } }, 'socket');
|
||||
expect(f.toursRepo.findProvenance).toHaveBeenCalledExactlyOnceWith(7, 42);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import type { PlacesRepository } from '../../../src/db/repositories/Places.repository';
|
||||
import type { TourTypesRepository } from '../../../src/db/repositories/TourTypes.repository';
|
||||
import type { TourWaypointsRepository } from '../../../src/db/repositories/TourWaypoints.repository';
|
||||
import type { ToursRepository } from '../../../src/db/repositories/Tours.repository';
|
||||
import type { TourProvenanceRow, ToursRepository } from '../../../src/db/repositories/Tours.repository';
|
||||
import type { UnitOfWork } from '../../../src/nest/database/unit-of-work';
|
||||
import type { PlacesService } from '../../../src/nest/places/places.service';
|
||||
import { ToursService } from '../../../src/nest/tours/tours.service';
|
||||
@@ -63,9 +63,28 @@ function makeService() {
|
||||
wanderer_ref: null,
|
||||
match_confidence: 1,
|
||||
max_hiking_difficulty: 2,
|
||||
origin: 'trek',
|
||||
planned: 0,
|
||||
has_waypoints: 1,
|
||||
};
|
||||
const provenance: TourProvenanceRow = {
|
||||
origin: 'trek',
|
||||
origin_file_name: null,
|
||||
created_at: '2026-10-01 08:00:00',
|
||||
wanderer_ref: null,
|
||||
has_recorded_track: 0,
|
||||
derived_from_place_id: null,
|
||||
derived_from_name: null,
|
||||
source_instance: null,
|
||||
source_external_id: null,
|
||||
source_external_url: null,
|
||||
source_external_updated: null,
|
||||
source_imported_at: null,
|
||||
source_content_hash: null,
|
||||
source_local_hash: null,
|
||||
route_geometry: JSON.stringify(request.route_geometry),
|
||||
name: request.name,
|
||||
};
|
||||
const place = { id: 42, trip_id: 7 };
|
||||
let inTransaction = false;
|
||||
/** Records whether each write ran inside the transaction. */
|
||||
@@ -87,6 +106,7 @@ function makeService() {
|
||||
};
|
||||
const toursRepo = {
|
||||
findInTrip: vi.fn(async (): Promise<typeof row | undefined> => row),
|
||||
findProvenance: vi.fn(async (): Promise<TourProvenanceRow | undefined> => provenance),
|
||||
insertTour: inTx(undefined),
|
||||
updateInTrip: inTx(true),
|
||||
keepRecordedTrack: inTx(undefined),
|
||||
@@ -163,6 +183,15 @@ describe('ToursService planner contracts (mock-only; SQLite rollback semantics a
|
||||
expect(setup.toursRepo.findInTrip).toHaveBeenCalledWith(7, 42);
|
||||
expect(result.tour).toMatchObject({ name: 'Ridge walk', planned: false, has_waypoints: true });
|
||||
expect(result.waypoints).toEqual(request.waypoints);
|
||||
expect(setup.toursRepo.findProvenance).toHaveBeenCalledExactlyOnceWith(7, 42);
|
||||
expect(result.provenance).toEqual({
|
||||
origin: 'trek',
|
||||
createdAt: '2026-10-01 08:00:00',
|
||||
source: { kind: 'trek' },
|
||||
derivedFrom: null,
|
||||
plannedOver: false,
|
||||
editedLocally: null,
|
||||
});
|
||||
expect(setup.places.broadcast).toHaveBeenNthCalledWith(1, '7', 'tours:changed', { placeIds: [42] }, 'socket-1');
|
||||
expect(setup.places.broadcast).toHaveBeenNthCalledWith(2, '7', 'place:created', { place: setup.place }, 'socket-1');
|
||||
});
|
||||
@@ -204,6 +233,11 @@ describe('ToursService planner contracts (mock-only; SQLite rollback semantics a
|
||||
{ lat: 48, lng: 11, role: 'start', sequence: 0 },
|
||||
{ lat: 48.02, lng: 11.04, role: 'end', sequence: 1 },
|
||||
]);
|
||||
expect(legacyGpx.provenance).toMatchObject({ origin: 'trek', source: { kind: 'trek' } });
|
||||
|
||||
// The provenance read is scoped to the trip as well: no row there is the same 404.
|
||||
setup.toursRepo.findProvenance.mockResolvedValueOnce(undefined);
|
||||
await expect(setup.service.getTour('7', '42')).rejects.toBeInstanceOf(NotFoundException);
|
||||
for (const method of [
|
||||
setup.uow.transactional,
|
||||
setup.placesRepo.insertTourPlace,
|
||||
|
||||
Reference in New Issue
Block a user