place-contrib: record origins for collection copies and booking imports

A place copied from a collection and a venue a booking import creates now
record their details as an import, so a later edit compares against what was
really written. Dawarich and the background enrichment write none of the
shareable fields, so they need nothing.

The admin panel asks again for a few seconds while a fresh installation is
still fetching its key, so the prompt appears without a reload.
This commit is contained in:
Maurice
2026-10-30 19:55:55 +01:00
parent 3f2dec6c47
commit 71cd6c2de4
8 changed files with 70 additions and 6 deletions
@@ -16,6 +16,8 @@ vi.mock('../../../../src/db/database', () => ({
getPlaceWithTags: () => null,
}));
const permissionsStub = { checkPermission: vi.fn(() => true) };
// The origin bookkeeping of the venues a confirm creates; its own suite is place-origins.service.test.ts.
const origins = { recordImported: vi.fn(async () => undefined) };
// Runs the callback in place; the tests that care about the boundary wrap it to record it.
const uowStub = { transactional: <T>(fn: () => Promise<T>) => fn() };
@@ -58,6 +60,7 @@ function make(opts: { kit?: boolean; ai?: boolean; extract?: any; parse?: any })
maps as never,
places as never,
uowStub as never,
origins as never,
),
extractor,
llmParse,
@@ -264,6 +267,7 @@ describe('BookingImportService.confirm venue website (#2483)', () => {
{ geocodeQuery: vi.fn() } as never,
places as never,
uowStub as never,
origins as never,
);
const item = (website?: string) => ({
type: 'restaurant',
@@ -284,6 +288,8 @@ describe('BookingImportService.confirm venue website (#2483)', () => {
undefined,
undefined,
]);
// The venues' details came from the booking: recorded once, as an import, after the loop.
expect(origins.recordImported).toHaveBeenLastCalledWith([7, 7, 7]);
});
});
@@ -355,6 +361,7 @@ describe('BookingImportService.confirm writes the booking with its cost', () =>
{ geocodeQuery: vi.fn() } as never,
places as never,
uow as never,
origins as never,
);
return { svc, reservations, budget, places, realtime, order, costEvents };
}
@@ -120,6 +120,9 @@ const removeIfUnreferenced = (id: string) => photoCache.removeIfUnreferenced(id)
// (part B) finished the conversion: `DatabaseService` is GONE from the constructor
// entirely (savePlace onward was its last use) — the trip/place/tag/user
// repositories below are Task 2's own additions.
// The origin bookkeeping after a copy; its own suite is place-origins.service.test.ts.
const originsForSpy = { recordImported: vi.fn(async () => undefined) };
beforeAll(async () => {
tripsRepoForSpy = await createTestTripsRepo(testDb);
permissionsForSpy = new PermissionsService(await createTestAppSettingsRepo(testDb), await createTestUnitOfWork(testDb));
@@ -134,6 +137,7 @@ beforeAll(async () => {
await createTestTagsRepo(testDb), await createTestUsersRepo(testDb),
buildPlaceImportService(),
placesHooks as never,
originsForSpy as never,
);
photoCache = new PlacePhotoCacheService(
makeStorageFixture('photos/google/').storage,
@@ -504,6 +508,8 @@ describe('copyToTrip', () => {
const res = await svc.copyToTrip(u.id, { trip_id: trip.id, place_ids: [p1.id, p2.id] }, copyEvents(trip.id));
expect(res.copied).toBe(1);
expect(res.skipped.map((s) => s.name)).toEqual(['Pantheon']);
// What was copied is the collection's, so it is recorded as an import, never as typed.
expect(originsForSpy.recordImported).toHaveBeenLastCalledWith(res.created.map((c) => c.id));
const inserted = (await findRow(await orm(), Places, { trip: trip.id, name: 'Colosseum' }))!;
expect(inserted.reservation_status).toBe('none'); // itinerary column took the table default