Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ apiGet: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", () => mocks);
|
|
|
|
import { getAuditEvent, searchAuditLog } from "./auditLog";
|
|
|
|
beforeEach(() => mocks.apiGet.mockReset());
|
|
|
|
describe("auditLog service", () => {
|
|
it("searchAuditLog sends only non-empty filters with a 0-based page", async () => {
|
|
mocks.apiGet.mockResolvedValue({ content: [{ id: "e1" }], totalElements: 9 });
|
|
const out = await searchAuditLog({ actor: "admin", module: "", action: "USER_UPDATE", outcome: "FAILURE", from: "2026-11-01", to: "", page: 2, pageSize: 10 });
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/audit-log?actor=admin&action=USER_UPDATE&outcome=FAILURE&from=2026-11-01&page=1&size=10");
|
|
expect(out).toEqual({ items: [{ id: "e1" }], total: 9 });
|
|
});
|
|
|
|
it("searchAuditLog tolerates an empty body", async () => {
|
|
mocks.apiGet.mockResolvedValue(null);
|
|
expect(await searchAuditLog({ page: 1, pageSize: 10 })).toEqual({ items: [], total: 0 });
|
|
});
|
|
|
|
it("getAuditEvent GETs one event by encoded id", async () => {
|
|
mocks.apiGet.mockResolvedValue({ id: "a/b" });
|
|
await getAuditEvent("a/b");
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/audit-log/a%2Fb");
|
|
});
|
|
});
|