mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
* feat: sync assets, partner assets, exif, and partner exif Co-authored-by: Zack Pollard <zack@futo.org> Co-authored-by: Alex Tran <alex.tran1502@gmail.com> * refactor: remove duplicate where clause and orderBy statements in sync queries * fix: asset deletes not filtering by ownerId --------- Co-authored-by: Zack Pollard <zack@futo.org> Co-authored-by: Alex Tran <alex.tran1502@gmail.com> Co-authored-by: Zack Pollard <zackpollard@ymail.com>
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import { TestContext, TestFactory } from 'test/factory';
|
|
import { getKyselyDB } from 'test/utils';
|
|
|
|
describe('audit', () => {
|
|
let context: TestContext;
|
|
|
|
beforeAll(async () => {
|
|
const db = await getKyselyDB();
|
|
context = await TestContext.from(db).create();
|
|
});
|
|
|
|
describe('partners_audit', () => {
|
|
it('should not cascade user deletes to partners_audit', async () => {
|
|
const user1 = TestFactory.user();
|
|
const user2 = TestFactory.user();
|
|
|
|
await context
|
|
.getFactory()
|
|
.withUser(user1)
|
|
.withUser(user2)
|
|
.withPartner({ sharedById: user1.id, sharedWithId: user2.id })
|
|
.create();
|
|
|
|
await context.user.delete(user1, true);
|
|
|
|
await expect(
|
|
context.db.selectFrom('partners_audit').select(['id']).where('sharedById', '=', user1.id).execute(),
|
|
).resolves.toHaveLength(0);
|
|
});
|
|
});
|
|
|
|
describe('assets_audit', () => {
|
|
it('should not cascade user deletes to assets_audit', async () => {
|
|
const user = TestFactory.user();
|
|
const asset = TestFactory.asset({ ownerId: user.id });
|
|
|
|
await context.getFactory().withUser(user).withAsset(asset).create();
|
|
|
|
await context.user.delete(user, true);
|
|
|
|
await expect(
|
|
context.db.selectFrom('assets_audit').select(['id']).where('assetId', '=', asset.id).execute(),
|
|
).resolves.toHaveLength(0);
|
|
});
|
|
});
|
|
|
|
describe('exif', () => {
|
|
it('should automatically set updatedAt and updateId when the row is updated', async () => {
|
|
const user = TestFactory.user();
|
|
const asset = TestFactory.asset({ ownerId: user.id });
|
|
const exif = { assetId: asset.id, make: 'Canon' };
|
|
|
|
await context.getFactory().withUser(user).withAsset(asset).create();
|
|
await context.asset.upsertExif(exif);
|
|
|
|
const before = await context.db
|
|
.selectFrom('exif')
|
|
.select(['updatedAt', 'updateId'])
|
|
.where('assetId', '=', asset.id)
|
|
.executeTakeFirstOrThrow();
|
|
|
|
await context.asset.upsertExif({ assetId: asset.id, make: 'Canon 2' });
|
|
|
|
const after = await context.db
|
|
.selectFrom('exif')
|
|
.select(['updatedAt', 'updateId'])
|
|
.where('assetId', '=', asset.id)
|
|
.executeTakeFirstOrThrow();
|
|
|
|
expect(before.updateId).not.toEqual(after.updateId);
|
|
expect(before.updatedAt).not.toEqual(after.updatedAt);
|
|
});
|
|
});
|
|
});
|