Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/utils/integrations/appsEngineService.aggregate.test.ts
T
2026-07-08 16:15:37 +02:00

41 lines
1.8 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it } from "vitest";
import { aggregateSyncOutcome } from "./appsEngineService.server";
import type { AdapterSyncOutcome } from "@hivegrid/foundation";
// R-P5 — pure sync-aggregation: maps adapter item results to AppSyncRun counters
// and a terminal status (no DB).
const outcome = (statuses: Array<"synced" | "failed" | "skipped">): AdapterSyncOutcome => ({
summaryKey: "integrations.sync.summary.ok",
items: statuses.map((status, i) => ({ entityType: "contact", externalId: `ext-${i}`, operation: "created" as const, status })),
});
describe("aggregateSyncOutcome", () => {
it("all synced → completed", () => {
const agg = aggregateSyncOutcome(outcome(["synced", "synced"]));
expect(agg).toMatchObject({ itemsTotal: 2, itemsSucceeded: 2, itemsFailed: 0, status: "completed" });
});
it("some failed → partial", () => {
const agg = aggregateSyncOutcome(outcome(["synced", "failed"]));
expect(agg).toMatchObject({ itemsTotal: 2, itemsSucceeded: 1, itemsFailed: 1, status: "partial" });
});
it("all failed → failed", () => {
const agg = aggregateSyncOutcome(outcome(["failed", "failed"]));
expect(agg).toMatchObject({ itemsSucceeded: 0, itemsFailed: 2, status: "failed" });
});
it("empty run → completed with zero counters", () => {
const agg = aggregateSyncOutcome(outcome([]));
expect(agg).toMatchObject({ itemsTotal: 0, status: "completed" });
expect(agg.summaryKey).toBe("integrations.sync.summary.ok");
});
it("skipped items count toward total but not success/fail", () => {
const agg = aggregateSyncOutcome(outcome(["synced", "skipped"]));
expect(agg).toMatchObject({ itemsTotal: 2, itemsSucceeded: 1, itemsFailed: 0, status: "completed" });
});
});