Repository Public
1import { describe, expect, it } from "vitest";2import { exportFileName, filtersFromParams, filtersToQueryString, isoToUtcInput, utcInputToIso } from "./logic";34describe("audit logic", () => {5 it("reads datetime-local values as UTC", () => {6 expect(utcInputToIso("2026-11-18T21:05")).toBe("2026-11-18T21:05:00.000Z");7 expect(utcInputToIso("2026-11-18T21:05:09")).toBe("2026-11-18T21:05:09.000Z");8 expect(utcInputToIso("")).toBeNull();9 expect(utcInputToIso("yesterday")).toBeNull();10 expect(isoToUtcInput("2026-11-18T21:05:00.000Z")).toBe("2026-11-18T21:05");11 expect(isoToUtcInput(undefined)).toBe("");12 expect(isoToUtcInput("nope")).toBe("");13 });14 it("round-trips filters through the query string and drops unknown outcomes", () => {15 const qs = filtersToQueryString({ action: "auth.login", outcome: "denied", correlation_id: "abc" });16 expect(qs).toBe("?action=auth.login&outcome=denied&correlation_id=abc");17 expect(filtersFromParams(new URLSearchParams(qs))).toEqual({ action: "auth.login", outcome: "denied", correlation_id: "abc" });18 expect(filtersFromParams(new URLSearchParams("outcome=maybe&x=1&action=%20"))).toEqual({});19 expect(filtersToQueryString({})).toBe("");20 });21 it("names the export file from the UTC bounds", () => {22 expect(exportFileName("2026-11-01T00:00:00.000Z", "2026-11-18T21:05:00.000Z")).toBe("mcc-audit-20261101T0000Z-20261118T2105Z.jsonl");23 });24});25