1
0
mirror of https://github.com/immich-app/immich.git synced 2025-08-08 23:07:06 +02:00

feat: pending sync reset flag (#19861)

This commit is contained in:
Jason Rasmussen
2025-07-11 09:38:02 -04:00
committed by GitHub
parent 34f0f6c813
commit 4b3a4725c6
28 changed files with 499 additions and 27 deletions

View File

@ -0,0 +1,63 @@
import { Kysely } from 'kysely';
import { SyncEntityType, SyncRequestType } from 'src/enum';
import { DB } from 'src/schema';
import { SyncTestContext } from 'test/medium.factory';
import { getKyselyDB } from 'test/utils';
let defaultDatabase: Kysely<DB>;
const setup = async (db?: Kysely<DB>) => {
const ctx = new SyncTestContext(db || defaultDatabase);
const { auth, user, session } = await ctx.newSyncAuthUser();
return { auth, user, session, ctx };
};
beforeAll(async () => {
defaultDatabase = await getKyselyDB();
});
describe(SyncEntityType.SyncResetV1, () => {
it('should work', async () => {
const { auth, ctx } = await setup();
const response = await ctx.syncStream(auth, [SyncRequestType.AssetsV1]);
expect(response).toEqual([]);
});
it('should detect a pending sync reset', async () => {
const { auth, ctx } = await setup();
auth.session!.isPendingSyncReset = true;
const response = await ctx.syncStream(auth, [SyncRequestType.AssetsV1]);
expect(response).toEqual([{ type: SyncEntityType.SyncResetV1, data: {} }]);
});
it('should not send other dtos when a reset is pending', async () => {
const { auth, user, ctx } = await setup();
await ctx.newAsset({ ownerId: user.id });
await expect(ctx.syncStream(auth, [SyncRequestType.AssetsV1])).resolves.toHaveLength(1);
auth.session!.isPendingSyncReset = true;
await expect(ctx.syncStream(auth, [SyncRequestType.AssetsV1])).resolves.toEqual([
{ type: SyncEntityType.SyncResetV1, data: {} },
]);
});
it('should allow resetting a pending reset when requesting changes ', async () => {
const { auth, user, ctx } = await setup();
await ctx.newAsset({ ownerId: user.id });
auth.session!.isPendingSyncReset = true;
await expect(ctx.syncStream(auth, [SyncRequestType.AssetsV1], true)).resolves.toEqual([
expect.objectContaining({
type: SyncEntityType.AssetV1,
}),
]);
});
});