feat(import): run catalog synchronizations as durable jobs
This commit is contained in:
@@ -16,7 +16,7 @@ const mocks = vi.hoisted(() => ({
|
||||
}));
|
||||
vi.mock("@/lib/redis", () => ({ redis: { set: mocks.set, eval: mocks.eval } }));
|
||||
vi.mock("@/lib/server-log", () => ({ logServerError: vi.fn() }));
|
||||
vi.mock("./audit", () => ({ logAudit: vi.fn() }));
|
||||
vi.mock("./audit", () => ({ logAudit: vi.fn().mockResolvedValue(undefined) }));
|
||||
vi.mock("./catalog-git-queue", () => ({ withCatalogExport: mocks.export }));
|
||||
vi.mock("./clone-sources", () => ({ getSource: async () => null }));
|
||||
vi.mock("./furni-job-store", () => ({
|
||||
@@ -42,6 +42,8 @@ vi.mock("./rcon", () => ({
|
||||
|
||||
vi.mock("./catalog-git-export", () => ({ runCatalogExport: vi.fn() }));
|
||||
|
||||
vi.mock("./furni-sync-item", () => ({ runSyncJobItem: mocks.import }));
|
||||
|
||||
import { drainFurnitureImports } from "./furni-job-worker";
|
||||
|
||||
let job: ImportJob;
|
||||
@@ -223,3 +225,27 @@ it("does not save a translated outcome after ownership is lost during translatio
|
||||
expect(snapshots.at(-1)?.items[0].state).toBe("running");
|
||||
expect(mocks.updateCatalog).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("restores the original operation context while running a durable job", async () => {
|
||||
const { getOperationContext } = await import(
|
||||
"@/lib/foundation/request-context"
|
||||
);
|
||||
job.operationId = "original-operation";
|
||||
mocks.import.mockImplementation(async () => {
|
||||
expect(getOperationContext()).toEqual({
|
||||
operationId: "original-operation",
|
||||
userId: 5,
|
||||
});
|
||||
return { ok: true, itemId: 900, warnings: [] };
|
||||
});
|
||||
await drainFurnitureImports();
|
||||
expect(getOperationContext()).toEqual({});
|
||||
});
|
||||
|
||||
it("keeps successful imports complete if their audit write fails", async () => {
|
||||
const { logAudit } = await import("./audit");
|
||||
vi.mocked(logAudit).mockRejectedValueOnce(new Error("Audit unavailable"));
|
||||
await drainFurnitureImports();
|
||||
expect(job.items[0].state).toBe("done");
|
||||
expect(job.items[0].warnings).toContain("Audit record could not be saved");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user