50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { renderAuditExportNdjson, type AuditExportRow, type AuditIntegritySummary } from "./audit-export.helpers.server";
|
|
|
|
const integrity: AuditIntegritySummary = { ok: true, inspected: 1, firstBreakId: null, reason: null };
|
|
|
|
function row(overrides: Partial<AuditExportRow> = {}): AuditExportRow {
|
|
return {
|
|
id: "a1",
|
|
createdAt: new Date("2026-06-24T08:00:00.000Z"),
|
|
tenantId: "t1",
|
|
actorType: "user",
|
|
actorId: "u1",
|
|
actorEmail: "a@example.com",
|
|
actorIp: null,
|
|
actorUserAgent: null,
|
|
action: "kontakt.created",
|
|
targetType: "Kontakt",
|
|
targetId: "k1",
|
|
requestId: null,
|
|
sourceModule: "crm",
|
|
outcome: "success",
|
|
dataSensitivity: "internal",
|
|
regulatoryScope: ["gdpr"],
|
|
metadata: { a: 1 },
|
|
previousHash: null,
|
|
eventHash: "h1",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("renderAuditExportNdjson", () => {
|
|
it("emits an integrity header line followed by one JSON object per row", () => {
|
|
const out = renderAuditExportNdjson([row(), row({ id: "a2" })], integrity);
|
|
const lines = out.trimEnd().split("\n");
|
|
expect(lines).toHaveLength(3);
|
|
expect(JSON.parse(lines[0])).toEqual({ _integrity: integrity });
|
|
const first = JSON.parse(lines[1]);
|
|
expect(first.id).toBe("a1");
|
|
// Dates are serialized to ISO strings, not Date objects.
|
|
expect(first.createdAt).toBe("2026-06-24T08:00:00.000Z");
|
|
expect(first.regulatoryScope).toEqual(["gdpr"]);
|
|
expect(JSON.parse(lines[2]).id).toBe("a2");
|
|
});
|
|
|
|
it("produces only the header line for an empty export", () => {
|
|
const out = renderAuditExportNdjson([], integrity);
|
|
expect(out.trimEnd().split("\n")).toHaveLength(1);
|
|
});
|
|
});
|