cm_whatsapp_bot_v1/apps/bot/src/audit.test.ts

33 lines
801 B
TypeScript

import { describe, expect, it } from "vitest";
import type { DB } from "./db.js";
import { writeAuditLog } from "./audit.js";
describe("writeAuditLog", () => {
it("inserts a row with normalized fields", async () => {
const inserted: unknown[] = [];
const fakeDb = {
insert: () => ({
values: (v: unknown) => {
inserted.push(v);
return Promise.resolve();
},
}),
} as unknown as DB;
await writeAuditLog(fakeDb, {
operatorId: null,
source: "telegram",
action: "test.event",
payload: { foo: "bar" },
});
expect(inserted).toHaveLength(1);
expect(inserted[0]).toMatchObject({
operatorId: null,
source: "telegram",
action: "test.event",
payload: { foo: "bar" },
});
});
});