mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
fix(tests): update test helpers and assertions for migration-98 photo schema
trek_photos is now the central registry; trip_photos and journey_photos reference it via photo_id FK. Updated all affected test helpers and direct-SQL assertions to join trek_photos instead of querying stale columns (asset_id, provider, owner_id) on the leaf tables. Also fix ATLAS-UNIT-019: getVisitedRegions now fires background geocoding and returns immediately, so the test must call it twice — once to trigger the fill, once after advancing fake timers to read cached results.
This commit is contained in:
@@ -473,10 +473,12 @@ describe('getVisitedRegions', () => {
|
||||
const trip = createTrip(testDb, user.id, { title: 'Paris Trip' });
|
||||
insertPlaceWithCoords(testDb, trip.id, 'Paris Hotel', 48.85, 2.35);
|
||||
|
||||
const resultPromise = getVisitedRegions(user.id);
|
||||
// First call triggers the background geocoding fire-and-forget
|
||||
await getVisitedRegions(user.id);
|
||||
// Advance all pending timers (including the 1100ms Nominatim rate-limit delay)
|
||||
await vi.runAllTimersAsync();
|
||||
const result = await resultPromise;
|
||||
// Second call returns now-cached data
|
||||
const result = await getVisitedRegions(user.id);
|
||||
|
||||
expect(result.regions['FR']).toBeDefined();
|
||||
|
||||
|
||||
@@ -1132,7 +1132,11 @@ describe('setPhotoProvider', () => {
|
||||
|
||||
setPhotoProvider(photo!.id, 'immich', 'immich-asset-789', user.id);
|
||||
|
||||
const updated = testDb.prepare('SELECT * FROM journey_photos WHERE id = ?').get(photo!.id) as any;
|
||||
const updated = testDb.prepare(`
|
||||
SELECT jp.*, tkp.provider, tkp.asset_id, tkp.owner_id
|
||||
FROM journey_photos jp JOIN trek_photos tkp ON tkp.id = jp.photo_id
|
||||
WHERE jp.id = ?
|
||||
`).get(photo!.id) as any;
|
||||
expect(updated.provider).toBe('immich');
|
||||
expect(updated.asset_id).toBe('immich-asset-789');
|
||||
expect(updated.owner_id).toBe(user.id);
|
||||
@@ -1321,9 +1325,11 @@ describe('Edge cases', () => {
|
||||
).get(journey.id) as any;
|
||||
expect(photoEntry).toBeDefined();
|
||||
|
||||
const photos = testDb.prepare(
|
||||
'SELECT * FROM journey_photos WHERE entry_id = ?'
|
||||
).all(photoEntry.id);
|
||||
const photos = testDb.prepare(`
|
||||
SELECT jp.*, tkp.asset_id FROM journey_photos jp
|
||||
JOIN trek_photos tkp ON tkp.id = jp.photo_id
|
||||
WHERE jp.entry_id = ?
|
||||
`).all(photoEntry.id);
|
||||
expect(photos.length).toBe(1);
|
||||
expect((photos[0] as any).asset_id).toBe('immich-photo-1');
|
||||
});
|
||||
|
||||
@@ -63,10 +63,17 @@ function insertJourneyPhoto(
|
||||
entryId: number,
|
||||
opts: { filePath?: string; assetId?: string; ownerId?: number } = {}
|
||||
): number {
|
||||
const provider = opts.assetId ? 'immich' : 'local';
|
||||
const filePath = !opts.assetId ? (opts.filePath ?? '/photos/test.jpg') : null;
|
||||
const trekResult = testDb.prepare(`
|
||||
INSERT INTO trek_photos (provider, asset_id, file_path, owner_id, created_at)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
`).run(provider, opts.assetId ?? null, filePath, opts.ownerId ?? null, Date.now());
|
||||
const trekId = trekResult.lastInsertRowid as number;
|
||||
const result = testDb.prepare(`
|
||||
INSERT INTO journey_photos (entry_id, file_path, caption, sort_order, created_at, asset_id, owner_id)
|
||||
VALUES (?, ?, NULL, 0, ?, ?, ?)
|
||||
`).run(entryId, opts.filePath ?? '/photos/test.jpg', Date.now(), opts.assetId ?? null, opts.ownerId ?? null);
|
||||
INSERT INTO journey_photos (entry_id, photo_id, caption, sort_order, created_at)
|
||||
VALUES (?, ?, NULL, 0, ?)
|
||||
`).run(entryId, trekId, Date.now());
|
||||
return result.lastInsertRowid as number;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user