mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
f833a05461
A tour can now point at the packing list of its trip, as a whole or at one of its categories (say "Hiking gear" for a hike), and shows it in its detail. The new Packing list section reads the list live as the user may see it: the backpack tile with the item count on its corner and the category's own colour, how many are packed with a thin progress bar, the first items ticked off or not with their quantity, how many more there are, and a button that opens the trip's Lists tab. Who may change the tour links one, changes it or lets go through a dialog that lists the whole list and every category with its colour and item count, and writes only on its confirm. It is a reference, never a copy: the items stay in Packing, are ticked off and edited there, and each traveller sees in the tour only the items Packing shows them, so an item kept to oneself never shows through a tour. A category that is renamed, cleared or only holds items of others reads as missing, an empty one as empty, a link that could not be read says so with a retry, and while Lists are switched off the link stays, dimmed, and can still be let go. Removing the link, or the tour, leaves the list and every item as they are. Nothing suggests or changes an item by itself. On the server the link is a row of its own in the tours domain (tour_packing_links, migration 046110), one per tour and gone with it. GET, PUT and DELETE /api/trips/:tripId/tours/:placeId/packing-link read it with the trip and change it with place_edit; linking needs the Lists addon and, for a category, an item of it the user can see. The writes answer the tour with its link and tell the trip through tours:changed, so the offline client queues them as writes of the tour and replays them like one. A copied trip keeps its tours' links, a tour saved as new or taken over does not. The MCP tools get_tour_packing, link_tour_packing and unlink_tour_packing run over the same service and checks; the read also hands the tour's facts as context for suggesting what to pack, which only becomes an item through the packing tools. The empty category placeholder now lives in @trek/shared so both sides leave it out alike. All 27 locales carry the new strings, and the wiki describes the link and the tools.
65 lines
3.0 KiB
TypeScript
65 lines
3.0 KiB
TypeScript
/**
|
|
* TripsService.copy and a tour's packing link (P2D-XD-01): the copied tour
|
|
* points at the same packing list or category of the copied trip, whose
|
|
* packing list is copied too, and the source keeps its own link.
|
|
*
|
|
* Real in-memory SQLite over the container: the service comes out of
|
|
* TripsModule, and the rows are seeded and read through the ORM factories.
|
|
*/
|
|
import { PackingItems } from '../../../src/db/entities/PackingItems.entity';
|
|
import { Places } from '../../../src/db/entities/Places.entity';
|
|
import { TourPackingLinks } from '../../../src/db/entities/TourPackingLinks.entity';
|
|
import { TripsModule } from '../../../src/nest/trips/trips.module';
|
|
import { TripsService } from '../../../src/nest/trips/trips.service';
|
|
import { createSnapshotTestDb } from '../../helpers/db-mock';
|
|
import { makePackingItem } from '../../helpers/factories/packing';
|
|
import { makePlace } from '../../helpers/factories/places';
|
|
import { countRows, findRow } from '../../helpers/factories/rows';
|
|
import { linkTourPacking, makeTour } from '../../helpers/factories/tours';
|
|
import { makeTrip } from '../../helpers/factories/trips';
|
|
import { makeUser } from '../../helpers/factories/users';
|
|
import { createTestModule, type TestModule } from '../../helpers/test-module';
|
|
import { MikroORM } from '@mikro-orm/core';
|
|
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
|
|
const db = createSnapshotTestDb();
|
|
let t: TestModule;
|
|
let svc: TripsService;
|
|
const orm = () => t.get(MikroORM);
|
|
|
|
beforeAll(async () => {
|
|
t = await createTestModule({ db, imports: [TripsModule] });
|
|
svc = t.get(TripsService);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await t.close();
|
|
db.close();
|
|
});
|
|
|
|
describe('copy: a tour pointing at its packing list (P2D-XD-01)', () => {
|
|
it('TRIP-SVC-096: the copied tour points at the same category of the copied list; a tour without a link gets none', async () => {
|
|
const { user } = await makeUser(orm());
|
|
const trip = await makeTrip(orm(), user.id, { title: 'Alps' });
|
|
const hike = await makePlace(orm(), trip.id, { name: 'Ridge' });
|
|
await makeTour(orm(), hike.id);
|
|
const walk = await makePlace(orm(), trip.id, { name: 'Old town' });
|
|
await makeTour(orm(), walk.id, { tourTypeRef: 'walk' });
|
|
await makePackingItem(orm(), trip.id, { name: 'Boots', category: 'Hiking gear' });
|
|
await linkTourPacking(orm(), hike.id, 'Hiking gear', user.id);
|
|
|
|
const newTripId = await svc.copy(trip.id, user.id, 'Alps again');
|
|
|
|
const copiedHike = await findRow(orm(), Places, { trip: newTripId, name: 'Ridge' });
|
|
const copiedWalk = await findRow(orm(), Places, { trip: newTripId, name: 'Old town' });
|
|
expect(await findRow(orm(), TourPackingLinks, { place: copiedHike?.id })).toMatchObject({
|
|
category: 'Hiking gear',
|
|
});
|
|
expect(await countRows(orm(), TourPackingLinks, { place: copiedWalk?.id })).toBe(0);
|
|
expect(await countRows(orm(), PackingItems, { trip: newTripId, category: 'Hiking gear' })).toBe(1);
|
|
// The source keeps its own link.
|
|
expect(await findRow(orm(), TourPackingLinks, { place: hike.id })).toMatchObject({ category: 'Hiking gear' });
|
|
});
|
|
});
|