feat(core-audit): withAudit wraps and attaches runtime __audited marker
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, expectTypeOf, vi } from "vitest";
|
||||
import { withAudit, type Audited } from "@/with-audit";
|
||||
import type { IAuditLog } from "@/audit-log.interface";
|
||||
import { isAudited } from "@repo/core-shared/conformance";
|
||||
|
||||
function makeAuditLog(): IAuditLog {
|
||||
return {
|
||||
@@ -17,6 +18,22 @@ describe("withAudit", () => {
|
||||
expectTypeOf(wrapped).toMatchTypeOf<Audited<typeof fn>>();
|
||||
});
|
||||
|
||||
it("attaches __audited as a non-enumerable property on the wrapped function", () => {
|
||||
const auditLog = makeAuditLog();
|
||||
const fn = async () => ({ ok: true });
|
||||
const wrapped = withAudit(auditLog, fn);
|
||||
expect(isAudited(wrapped)).toBe(true);
|
||||
expect(Object.keys(wrapped)).not.toContain("__audited");
|
||||
});
|
||||
|
||||
it("does NOT pollute the original input function with the brand", () => {
|
||||
const auditLog = makeAuditLog();
|
||||
const fn = async () => ({ ok: true });
|
||||
const wrapped = withAudit(auditLog, fn);
|
||||
expect(isAudited(fn)).toBe(false);
|
||||
expect(wrapped).not.toBe(fn);
|
||||
});
|
||||
|
||||
it("passes input and output through unchanged", async () => {
|
||||
const auditLog = makeAuditLog();
|
||||
const fn = async (input: { id: string }) => ({ ok: true, id: input.id });
|
||||
|
||||
Reference in New Issue
Block a user