Files
TREK/server/tests/helpers/places-library-fixture.ts
T
Maurice 7a06db393f fix(ci): repair server and shared gates after the place identities change
Push run 46275645144 on dev (f69a4c1a2) was red in these jobs:

- Server types: UserPlacesRepository.create, UserPlaceMergesRepository.create
  and UserPlaceLinksRepository.insert shadowed MikroORM's EntityRepository
  methods with other signatures (TS2416), which also broke defineEntity on the
  three entities (TS2769). They are createOwn, record and insertUses now.
- Server lint: collections.service.ts had grown to 1411 lines against 1410.
  The trip tag lookup of a copy moved into collections.helpers.ts
  (tripTagIdsOf, tagKeyOf); the size baseline is lowered to the 1398 it holds.
- ASTCAP-001/002/005b: the trip chat core had taken in PlacesLibraryMcp,
  PlaceIdentitiesMcp and TripCollectionsMcp, so core and the tours group
  offered 132 tools against 128. They load with the collections group now.
- PLIB-001, PLIB-MCP-001 and the places library e2e: the two entries named
  Museum tie on the name and go by their anchor, which the expected order
  hard coded the other way. The fixture orders every tie by its anchors.
- ENT-003 and CLASSFIELD-002: the five new entities and their 18 NOT NULL
  columns without a default are counted.
- Shared tests: collections.ratingBadge was missing in 26 locales; each has
  its translation now.
2026-11-29 16:14:42 +01:00

191 lines
7.6 KiB
TypeScript

/**
* The lists and trips the "All places" suites read, seeded through the ORM
* factories. The user `me` owns the trip Alps and the list Food, is a member
* of `friend`'s trip Rome and a viewer of `friend`'s list Rome sights;
* `stranger` owns a trip and a list `me` cannot open.
*
* Alps holds the normal places Café Central, Museum, Hotel Sonne (lodging) and
* Camp Lake (a road trip campsite a stay points at), and the places "All
* places" leaves out: a tour, an imported track and a fuel stop. Food holds a
* copy of each kind the grouping rule tells apart.
*/
import { CollectionLabels } from '../../src/db/entities/CollectionLabels.entity';
import { CollectionPlaceRatings } from '../../src/db/entities/CollectionPlaceRatings.entity';
import { PlaceRatings } from '../../src/db/entities/PlaceRatings.entity';
import {
addCollectionMember,
labelCollectionPlace,
makeCollection,
makeCollectionPlace,
} from './factories/collections';
import type { FactoryOrm } from './factories/context';
import { makeDayAccommodation, makeDayAssignment } from './factories/itinerary';
import { makePlace } from './factories/places';
import { makeReservation } from './factories/reservations';
import { createRow, insertRows } from './factories/rows';
import { makeTour } from './factories/tours';
import { addTripMember, makeTrip, readTripDays } from './factories/trips';
import { makeUser } from './factories/users';
export async function seedLibrary(orm: FactoryOrm) {
const { user: me } = await makeUser(orm);
const { user: friend } = await makeUser(orm);
const { user: stranger } = await makeUser(orm);
const alps = await makeTrip(orm, me.id, { title: 'Alps', start_date: '2026-07-01', end_date: '2026-07-03' });
const rome = await makeTrip(orm, friend.id, { title: 'Rome' });
await addTripMember(orm, rome.id, me.id);
const elsewhere = await makeTrip(orm, stranger.id, { title: 'Elsewhere' });
const cafe = await makePlace(orm, alps.id, {
name: 'Café Central',
address: 'Herrengasse 14, Wien',
lat: 48.2104,
lng: 16.3655,
google_place_id: 'g-cafe',
notes: 'Book a table',
description: 'A coffee house',
});
const museum = await makePlace(orm, alps.id, {
name: 'Museum',
lat: 47.2681,
lng: 11.3933,
google_place_id: 'g-museum',
});
const hotel = await makePlace(orm, alps.id, { name: 'Hotel Sonne', stop_type: 'hotel' });
const camp = await makePlace(orm, alps.id, { name: 'Camp Lake', stop_type: 'campsite' });
const ridge = await makePlace(orm, alps.id, { name: 'Ridge walk' });
await makeTour(orm, ridge.id);
const track = await makePlace(orm, alps.id, { name: 'Imported track', route_geometry: '[[47,11],[47.1,11.1]]' });
const pump = await makePlace(orm, alps.id, { name: 'Fuel pump', stop_type: 'fuel' });
const days = await readTripDays(orm, alps.id);
const [day1, day2] = days;
if (!day1 || !day2) throw new Error('seedLibrary: Alps has no days');
await makeDayAccommodation(orm, alps.id, camp.id, day1.id, day2.id);
await makeDayAssignment(orm, day1.id, cafe.id, { assignment_time: '09:00' });
await makeReservation(orm, alps.id, { place: hotel.id, title: 'Hotel Sonne', type: 'hotel' });
await insertRows(orm, PlaceRatings, [
{ place: cafe.id, user: me.id, rating: 4 },
{ place: cafe.id, user: friend.id, rating: 2 },
]);
const forum = await makePlace(orm, rome.id, { name: 'Forum Romanum', lat: 41.8925, lng: 12.4853 });
const hidden = await makePlace(orm, elsewhere.id, { name: 'Hidden', lat: 1, lng: 1 });
const food = await makeCollection(orm, me.id, { name: 'Food' });
// The same place: it came from Café Central, same name once trimmed and lowered, a few metres off.
const savedCafe = await makeCollectionPlace(orm, food.id, me.id, {
name: ' café central ',
lat: 48.21042,
lng: 16.36551,
source_trip_id: alps.id,
source_place_id: cafe.id,
status: 'want',
notes: 'Try the cake',
});
// The same place by its provider id, whatever it is called and with no position.
const savedMuseum = await makeCollectionPlace(orm, food.id, me.id, {
name: 'Tiroler Landesmuseum',
lat: null,
lng: null,
google_place_id: 'g-museum',
source_trip_id: alps.id,
source_place_id: museum.id,
});
// Came from Café Central but renamed: a name of its own keeps it apart.
const lunch = await makeCollectionPlace(orm, food.id, me.id, {
name: 'Lunch spot',
lat: 48.2104,
lng: 16.3655,
source_trip_id: alps.id,
source_place_id: cafe.id,
});
// Same name and spot as Café Central, but another provider id: a different place.
const conflicting = await makeCollectionPlace(orm, food.id, me.id, {
name: 'Café Central',
lat: 48.2104,
lng: 16.3655,
google_place_id: 'g-other',
source_trip_id: alps.id,
source_place_id: cafe.id,
});
// Same name and spot as Museum, but no source: a name never groups on its own.
const namesake = await makeCollectionPlace(orm, food.id, me.id, { name: 'Museum', lat: 47.2681, lng: 11.3933 });
// Points at a place of a trip `me` cannot open.
const hiddenCopy = await makeCollectionPlace(orm, food.id, me.id, {
name: 'Hidden copy',
lat: 1,
lng: 1,
source_trip_id: elsewhere.id,
source_place_id: hidden.id,
});
const label = await createRow(orm, CollectionLabels, { collection: food.id, name: 'Must', color: '#ff0000' });
await labelCollectionPlace(orm, savedCafe.id, label.id);
await insertRows(orm, CollectionPlaceRatings, [{ collectionPlace: savedCafe.id, user: me.id, rating: 5 }]);
const sights = await makeCollection(orm, friend.id, { name: 'Rome sights' });
await addCollectionMember(orm, sights.id, me.id, { role: 'viewer' });
const pantheon = await makeCollectionPlace(orm, sights.id, friend.id, { name: 'Pantheon', status: 'visited' });
const secrets = await makeCollection(orm, stranger.id, { name: 'Secrets' });
const secret = await makeCollectionPlace(orm, secrets.id, stranger.id, {
name: 'Café Central',
lat: 48.2104,
lng: 16.3655,
source_trip_id: alps.id,
source_place_id: cafe.id,
});
return {
me,
friend,
stranger,
alps,
rome,
elsewhere,
day1,
places: { cafe, museum, hotel, camp, ridge, track, pump, forum, hidden },
lists: { food, sights, secrets },
saved: { savedCafe, savedMuseum, lunch, conflicting, namesake, hiddenCopy, pantheon, secret },
label,
};
}
export type LibraryFixture = Awaited<ReturnType<typeof seedLibrary>>;
/**
* The keys of `me`'s entries by name. Two entries of the same name go by their
* anchor (`id * 4 + kind`, a trip place's kind 1, a saved place's 2; a saved
* place grouped with a trip place takes the trip place's), so the order of a
* tie follows the ids the seed got.
*/
export function expectedKeysByName(f: LibraryFixture): string[] {
const { places, saved } = f;
return [
...cafeTie(f),
`trip:${places.camp.id}`,
`trip:${places.forum.id}`,
`list:${saved.hiddenCopy.id}`,
`trip:${places.hotel.id}`,
`list:${saved.lunch.id}`,
...museumTie(f),
`list:${saved.pantheon.id}`,
];
}
/** Two entries of one name, in the order their anchors give. */
function byAnchor(trip: number, list: number): string[] {
const pair = [`list:${list}`, `trip:${trip}`];
return list * 4 + 2 < trip * 4 + 1 ? pair : [...pair].reverse();
}
/** The two entries named Café Central, in the order their anchors give. */
export function cafeTie(f: LibraryFixture): string[] {
return byAnchor(f.places.cafe.id, f.saved.conflicting.id);
}
/** The two entries named Museum (the trip place with its saved copy, and the namesake), as their anchors give. */
export function museumTie(f: LibraryFixture): string[] {
return byAnchor(f.places.museum.id, f.saved.namesake.id);
}