fix(server): update ocr & faces after asset edit (#29303)
* fix: update ocr & faces after asset edit * chore: remove client-side refresh * fix(server): sync asset OCR visibility changes * chore: prettier format * test: missing updatedAt * chore: remove comment * chore: fix test * chore: update migration timestamp * chore(server): AssetOcrSyncReset * chore: migration timestamps --------- Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
This commit is contained in:
@@ -56,6 +56,7 @@ describe(OcrService.name, () => {
|
||||
boxScore: 0.99,
|
||||
id: expect.any(String),
|
||||
updateId: expect.any(String),
|
||||
updatedAt: expect.any(Date),
|
||||
text: 'Test OCR',
|
||||
textScore: 0.95,
|
||||
isVisible: true,
|
||||
@@ -107,6 +108,7 @@ describe(OcrService.name, () => {
|
||||
boxScore: 0.7,
|
||||
id: expect.any(String),
|
||||
updateId: expect.any(String),
|
||||
updatedAt: expect.any(Date),
|
||||
text: 'One',
|
||||
textScore: 0.9,
|
||||
isVisible: true,
|
||||
@@ -124,6 +126,7 @@ describe(OcrService.name, () => {
|
||||
boxScore: 0.67,
|
||||
id: expect.any(String),
|
||||
updateId: expect.any(String),
|
||||
updatedAt: expect.any(Date),
|
||||
text: 'Two',
|
||||
textScore: 0.89,
|
||||
isVisible: true,
|
||||
@@ -141,6 +144,7 @@ describe(OcrService.name, () => {
|
||||
boxScore: 0.65,
|
||||
id: expect.any(String),
|
||||
updateId: expect.any(String),
|
||||
updatedAt: expect.any(Date),
|
||||
text: 'Three',
|
||||
textScore: 0.88,
|
||||
isVisible: true,
|
||||
@@ -158,6 +162,7 @@ describe(OcrService.name, () => {
|
||||
boxScore: 0.62,
|
||||
id: expect.any(String),
|
||||
updateId: expect.any(String),
|
||||
updatedAt: expect.any(Date),
|
||||
text: 'Four',
|
||||
textScore: 0.87,
|
||||
isVisible: true,
|
||||
@@ -175,6 +180,7 @@ describe(OcrService.name, () => {
|
||||
boxScore: 0.6,
|
||||
id: expect.any(String),
|
||||
updateId: expect.any(String),
|
||||
updatedAt: expect.any(Date),
|
||||
text: 'Five',
|
||||
textScore: 0.86,
|
||||
isVisible: true,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { SyncEntityType, SyncRequestType } from 'src/enum';
|
||||
import { OcrRepository } from 'src/repositories/ocr.repository';
|
||||
import { DB } from 'src/schema';
|
||||
import { SyncTestContext } from 'test/medium.factory';
|
||||
import { factory } from 'test/small.factory';
|
||||
import { getKyselyDB } from 'test/utils';
|
||||
|
||||
let defaultDatabase: Kysely<DB>;
|
||||
@@ -303,6 +304,61 @@ describe(SyncEntityType.AssetOcrV1, () => {
|
||||
await ctx.syncAckAll(auth, updatedResponse);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetOcrV1]);
|
||||
});
|
||||
|
||||
it('should sync in-place OCR visibility toggles (e.g. after an asset edit)', async () => {
|
||||
const { auth, user, ctx } = await setup();
|
||||
|
||||
const ocrRepo = ctx.get(OcrRepository);
|
||||
const { asset } = await ctx.newAsset({ ownerId: user.id });
|
||||
await ocrRepo.upsert(
|
||||
asset.id,
|
||||
[
|
||||
{
|
||||
assetId: asset.id,
|
||||
x1: 0.1,
|
||||
y1: 0.2,
|
||||
x2: 0.9,
|
||||
y2: 0.2,
|
||||
x3: 0.9,
|
||||
y3: 0.8,
|
||||
x4: 0.1,
|
||||
y4: 0.8,
|
||||
boxScore: 0.95,
|
||||
textScore: 0.92,
|
||||
text: 'Hello World',
|
||||
isVisible: true,
|
||||
},
|
||||
],
|
||||
'Hello World',
|
||||
);
|
||||
|
||||
const response = await ctx.syncStream(auth, [SyncRequestType.AssetOcrV1]);
|
||||
const ocrId = (response[0] as { data: { id: string } }).data.id;
|
||||
await ctx.syncAckAll(auth, response);
|
||||
|
||||
await ocrRepo.updateOcrVisibilities(
|
||||
asset.id,
|
||||
[],
|
||||
[factory.assetOcr({ id: ocrId, assetId: asset.id, text: 'Hello World' })],
|
||||
);
|
||||
|
||||
const updatedResponse = await ctx.syncStream(auth, [SyncRequestType.AssetOcrV1]);
|
||||
expect(updatedResponse).toEqual([
|
||||
{
|
||||
ack: expect.any(String),
|
||||
data: expect.objectContaining({
|
||||
id: ocrId,
|
||||
assetId: asset.id,
|
||||
isVisible: false,
|
||||
}),
|
||||
type: 'AssetOcrV1',
|
||||
},
|
||||
expect.objectContaining({ type: SyncEntityType.SyncCompleteV1 }),
|
||||
]);
|
||||
|
||||
await ctx.syncAckAll(auth, updatedResponse);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetOcrV1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe(SyncEntityType.AssetOcrDeleteV1, () => {
|
||||
|
||||
@@ -185,10 +185,12 @@ const assetOcrFactory = (
|
||||
textScore?: number;
|
||||
text?: string;
|
||||
isVisible?: boolean;
|
||||
updatedAt?: Date;
|
||||
} = {},
|
||||
) => ({
|
||||
id: newUuid(),
|
||||
updateId: newUuidV7(),
|
||||
updatedAt: newDate(),
|
||||
assetId: newUuid(),
|
||||
x1: 0.1,
|
||||
y1: 0.2,
|
||||
|
||||
Reference in New Issue
Block a user