import { describe, it, expect } from "vitest"; import { buildQueryString } from "./auditLog"; describe("buildQueryString", () => { it("converts page 1 to page=0 for the 0-based mobile-api", () => { const qs = buildQueryString({ page: 1, pageSize: 20 }); expect(qs).toContain("page=0"); }); it("converts page 2 to page=1", () => { const qs = buildQueryString({ page: 2, pageSize: 20 }); expect(qs).toContain("page=1"); }); it("clamps page 0 to 0 (Math.max guard)", () => { const qs = buildQueryString({ page: 0, pageSize: 20 }); expect(qs).toContain("page=0"); }); it("only sends allow-listed filters — actor", () => { const qs = buildQueryString({ page: 1, pageSize: 20, actor: "admin1" }); expect(qs).toContain("actor=admin1"); }); it("only sends allow-listed filters — actorType", () => { const qs = buildQueryString({ page: 1, pageSize: 20, actorType: "ADMIN" }); expect(qs).toContain("actorType=ADMIN"); }); it("only sends allow-listed filters — module", () => { const qs = buildQueryString({ page: 1, pageSize: 20, module: "BO_MEMBERS" }); expect(qs).toContain("module=BO_MEMBERS"); }); it("only sends allow-listed filters — action", () => { const qs = buildQueryString({ page: 1, pageSize: 20, action: "CREATE" }); expect(qs).toContain("action=CREATE"); }); it("only sends allow-listed filters — from", () => { const qs = buildQueryString({ page: 1, pageSize: 20, from: "2026-09-01" }); expect(qs).toContain("from=2026-09-01"); }); it("only sends allow-listed filters — to", () => { const qs = buildQueryString({ page: 1, pageSize: 20, to: "2026-09-28" }); expect(qs).toContain("to=2026-09-28"); }); it("only sends allow-listed filters — ip", () => { const qs = buildQueryString({ page: 1, pageSize: 20, ip: "203.0.113.1" }); expect(qs).toContain("ip=203.0.113.1"); }); it("does not send sortBy or sortDir (removed)", () => { const qs = buildQueryString({ page: 1, pageSize: 20, sortBy: "occurredAt", sortDir: "desc" }); expect(qs).not.toContain("sortBy"); expect(qs).not.toContain("sortDir"); }); it("sends size", () => { const qs = buildQueryString({ page: 1, pageSize: 50 }); expect(qs).toContain("size=50"); }); it("does not send undefined filters", () => { const qs = buildQueryString({ page: 1, pageSize: 20 }); expect(qs).not.toContain("actor"); expect(qs).not.toContain("actorType"); expect(qs).not.toContain("module"); expect(qs).not.toContain("action"); expect(qs).not.toContain("from"); expect(qs).not.toContain("to"); expect(qs).not.toContain("ip"); expect(qs).not.toContain("sortBy"); expect(qs).not.toContain("sortDir"); }); });