修复数字员工同步业务失败识别
This commit is contained in:
@@ -139,6 +139,80 @@ describe("digital employee sync service", () => {
|
||||
expect(mockState.ensureSchemaCalls).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("accepts backend ReqResult acknowledgements", async () => {
|
||||
insertPlan("plan-reqresult-ok");
|
||||
insertOutbox("plan:upsert:plan-reqresult-ok", "plan", "plan-reqresult-ok");
|
||||
mockState.fetch.mockResolvedValue(
|
||||
jsonResponse({
|
||||
code: "0000",
|
||||
message: "success",
|
||||
data: {
|
||||
acked: [
|
||||
{
|
||||
outbox_id: "plan:upsert:plan-reqresult-ok",
|
||||
entity_type: "plan",
|
||||
entity_id: "plan-reqresult-ok",
|
||||
remote_id: "remote-plan-reqresult-ok",
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const { flushDigitalEmployeeSyncOutbox } = await import("./syncService");
|
||||
const status = await flushDigitalEmployeeSyncOutbox({ force: true });
|
||||
|
||||
expect(status.lastSyncError).toBeNull();
|
||||
expect(status.pending).toBe(0);
|
||||
expect(status.failed).toBe(0);
|
||||
expect(readOutbox("plan:upsert:plan-reqresult-ok")).toMatchObject({
|
||||
status: "synced",
|
||||
error: null,
|
||||
attempts: 1,
|
||||
});
|
||||
expect(readPlan("plan-reqresult-ok")).toMatchObject({
|
||||
sync_status: "synced",
|
||||
remote_id: "remote-plan-reqresult-ok",
|
||||
sync_error: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("marks backend ReqResult business failures as failed", async () => {
|
||||
insertPlan("plan-rejected");
|
||||
insertOutbox("plan:upsert:plan-rejected", "plan", "plan-rejected");
|
||||
mockState.fetch.mockResolvedValue(
|
||||
jsonResponse({
|
||||
code: "0001",
|
||||
message: "客户端 Key header 缺失",
|
||||
data: null,
|
||||
}),
|
||||
);
|
||||
|
||||
const { flushDigitalEmployeeSyncOutbox } = await import("./syncService");
|
||||
const status = await flushDigitalEmployeeSyncOutbox({ force: true });
|
||||
|
||||
expect(status.lastSyncError).toBe("客户端 Key header 缺失");
|
||||
expect(status.pending).toBe(0);
|
||||
expect(status.failed).toBe(1);
|
||||
expect(readOutbox("plan:upsert:plan-rejected")).toMatchObject({
|
||||
status: "failed",
|
||||
error: "客户端 Key header 缺失",
|
||||
attempts: 1,
|
||||
});
|
||||
expect(readPlan("plan-rejected")).toMatchObject({
|
||||
sync_status: "failed",
|
||||
sync_error: "客户端 Key header 缺失",
|
||||
});
|
||||
expect(readAttempts()).toEqual([
|
||||
expect.objectContaining({
|
||||
outbox_id: "plan:upsert:plan-rejected",
|
||||
attempt_no: 1,
|
||||
status: "failed",
|
||||
error: "客户端 Key header 缺失",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps unacknowledged rows retryable after a partial backend ack", async () => {
|
||||
insertPlan("plan-1");
|
||||
insertPlan("plan-2");
|
||||
|
||||
Reference in New Issue
Block a user