45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { serializeImpersonationAuditMetadata } from "./impersonation-audit.server.js";
|
|
|
|
describe("serializeImpersonationAuditMetadata value normalization", () => {
|
|
it("stringifies scalar values (number, boolean, bigint)", () => {
|
|
const serialized = serializeImpersonationAuditMetadata({
|
|
attempts: 3,
|
|
blocked: true,
|
|
sequence: 9007199254740993n,
|
|
});
|
|
|
|
expect(serialized).toBe(JSON.stringify({ attempts: "3", blocked: "true", sequence: "9007199254740993" }));
|
|
});
|
|
|
|
it("serializes Date values as ISO-8601 strings", () => {
|
|
const serialized = serializeImpersonationAuditMetadata({
|
|
occurredAt: new Date("2026-06-25T08:30:00.000Z"),
|
|
});
|
|
|
|
expect(serialized).toBe(JSON.stringify({ occurredAt: "2026-06-25T08:30:00.000Z" }));
|
|
});
|
|
|
|
it("drops null and undefined values because they normalize to empty strings", () => {
|
|
const serialized = serializeImpersonationAuditMetadata({
|
|
ip: "127.0.0.1",
|
|
reason: null,
|
|
note: undefined,
|
|
});
|
|
|
|
expect(serialized).toBe(JSON.stringify({ ip: "127.0.0.1" }));
|
|
});
|
|
|
|
it("returns null when every value normalizes away to empty", () => {
|
|
expect(serializeImpersonationAuditMetadata({ reason: null, note: undefined })).toBeNull();
|
|
});
|
|
|
|
it("falsey-but-meaningful scalars survive normalization", () => {
|
|
// 0 and false stringify to non-empty values, so they must be retained.
|
|
const serialized = serializeImpersonationAuditMetadata({ count: 0, enabled: false });
|
|
|
|
expect(serialized).toBe(JSON.stringify({ count: "0", enabled: "false" }));
|
|
});
|
|
});
|