Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { auditEvent, withAuditMiddleware } from "./audit.js";
|
||||
|
||||
describe("foundation audit helpers", () => {
|
||||
it("normalizes empty optional fields and falls back to system actor type", async () => {
|
||||
const client = { auditEvent: { create: vi.fn(async (args) => args.data) } };
|
||||
|
||||
await auditEvent(
|
||||
{
|
||||
action: "resource.updated",
|
||||
tenantId: undefined,
|
||||
actorId: undefined,
|
||||
actorType: " ",
|
||||
targetType: undefined,
|
||||
targetId: undefined,
|
||||
requestId: undefined,
|
||||
metadata: undefined,
|
||||
},
|
||||
client,
|
||||
);
|
||||
|
||||
expect(client.auditEvent.create).toHaveBeenCalledWith({
|
||||
data: {
|
||||
tenantId: null,
|
||||
actorId: null,
|
||||
actorType: "system",
|
||||
action: "resource.updated",
|
||||
targetType: null,
|
||||
targetId: null,
|
||||
requestId: null,
|
||||
metadata: null,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves trimmed actor types and skips null middleware events", async () => {
|
||||
const client = { auditEvent: { create: vi.fn(async (args) => args.data) } };
|
||||
await auditEvent({ action: "resource.created", actorType: " user " }, client);
|
||||
|
||||
expect(client.auditEvent.create).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({ action: "resource.created", actorType: "user" }),
|
||||
});
|
||||
|
||||
client.auditEvent.create.mockClear();
|
||||
const handler = withAuditMiddleware(async () => ({ id: "result_1" }), () => null, client);
|
||||
|
||||
await expect(handler()).resolves.toEqual({ id: "result_1" });
|
||||
expect(client.auditEvent.create).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user