refactor(memories, photos, packing, share): async DB-touching methods; transactions through UnitOfWork

This commit is contained in:
jubnl
2026-09-22 02:21:06 +02:00
parent 6b755314d8
commit 37992de7ab
48 changed files with 1250 additions and 1219 deletions
@@ -68,7 +68,7 @@ const photoCache = new PlacePhotoCacheService(dbs, makeStorageFixture('photos/go
let packing: PackingService;
let places: PlacesService;
beforeAll(async () => {
packing = new PackingService(dbs, new PermissionsService(dbs, await createTestUnitOfWork(dbs.connection)), realtime, notificationsStub());
packing = new PackingService(dbs, new PermissionsService(dbs, await createTestUnitOfWork(dbs.connection)), realtime, notificationsStub(), await createTestUnitOfWork(dbs.connection));
places = new PlacesService(
dbs,
new PermissionsService(dbs, await createTestUnitOfWork(dbs.connection)),
@@ -145,25 +145,25 @@ describe('PlacesService.update — optimistic concurrency', () => {
});
describe('updateItem (packing) — optimistic concurrency', () => {
it('migration added updated_at and createItem stamps it', () => {
it('migration added updated_at and createItem stamps it', async () => {
const cols = testDb.prepare("PRAGMA table_info('packing_items')").all() as { name: string }[];
expect(cols.map(c => c.name)).toContain('updated_at');
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const item = packing.createItem(trip.id, { name: 'Socks' }) as { id: number; updated_at: string | null };
const item = await packing.createItem(trip.id, { name: 'Socks' }) as { id: number; updated_at: string | null };
expect(item.updated_at).toBeTruthy();
});
it('returns a conflict when the packing token is stale', () => {
it('returns a conflict when the packing token is stale', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const item = packing.createItem(trip.id, { name: 'Socks' }, user.id) as { id: number; updated_at: string };
const item = await packing.createItem(trip.id, { name: 'Socks' }, user.id) as { id: number; updated_at: string };
const stale = packing.updateItem(trip.id, item.id, { name: 'Mine' }, ['name'], '1999-01-01 00:00:00', user.id);
const stale = await packing.updateItem(trip.id, item.id, { name: 'Mine' }, ['name'], '1999-01-01 00:00:00', user.id);
expect(isUpdateConflict(stale)).toBe(true);
const fresh = packing.updateItem(trip.id, item.id, { name: 'Edited' }, ['name'], item.updated_at, user.id);
const fresh = await packing.updateItem(trip.id, item.id, { name: 'Edited' }, ['name'], item.updated_at, user.id);
expect(isUpdateConflict(fresh)).toBe(false);
expect((fresh as { name: string }).name).toBe('Edited');
});
@@ -54,22 +54,22 @@ describe('trek_photos media_type', () => {
expect(cols).toContain('duration_ms');
});
it('a local photo defaults to image', () => {
const id = getOrCreateLocalTrekPhoto('journey/a.jpg');
expect(resolveTrekPhoto(id)!.media_type).toBe('image');
it('a local photo defaults to image', async () => {
const id = await getOrCreateLocalTrekPhoto('journey/a.jpg');
expect((await resolveTrekPhoto(id))!.media_type).toBe('image');
});
it('a local video stores media_type=video + duration', () => {
const id = getOrCreateLocalTrekPhoto('journey/clip.mp4', 'journey/poster.jpg', null, null, 'video', 4200);
const row = resolveTrekPhoto(id)!;
it('a local video stores media_type=video + duration', async () => {
const id = await getOrCreateLocalTrekPhoto('journey/clip.mp4', 'journey/poster.jpg', null, null, 'video', 4200);
const row = (await resolveTrekPhoto(id))!;
expect(row.media_type).toBe('video');
expect(row.duration_ms).toBe(4200);
expect(row.thumbnail_path).toBe('journey/poster.jpg');
});
it('a provider photo can be registered as video', () => {
it('a provider photo can be registered as video', async () => {
const { user } = createUser(testDb);
const id = getOrCreateTrekPhoto('immich', 'asset-1', user.id, undefined, 'video');
expect(resolveTrekPhoto(id)!.media_type).toBe('video');
const id = await getOrCreateTrekPhoto('immich', 'asset-1', user.id, undefined, 'video');
expect((await resolveTrekPhoto(id))!.media_type).toBe('video');
});
});