Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.9 kB ยท 66 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import { describe, expect, it } from "vitest";
import { auditEntityKind, fieldRefKind, toEntityId, toEntityIds,} from "./entity-refs.client";
describe("toEntityId", () => { for (const [value, expected] of [ [4, 4], ["42", 42], [0, undefined], [-1, undefined], [1.5, undefined], ["", undefined], ["4a", undefined], [" 4", undefined], [null, undefined], [Number.MAX_SAFE_INTEGER + 1, undefined], ] as const) { it(`parses ${JSON.stringify(value)}`, () => { expect(toEntityId(value)).toBe(expected); }); }});
describe("toEntityIds", () => { it("returns every id of a numeric list", () => { expect(toEntityIds([3, 4])).toEqual([3, 4]); });
it("rejects empty lists, strings and lists with one bad entry", () => { expect(toEntityIds([])).toBeUndefined(); expect(toEntityIds(["3"])).toBeUndefined(); expect(toEntityIds([3, 0])).toBeUndefined(); expect(toEntityIds("3,4")).toBeUndefined(); });});
describe("fieldRefKind", () => { it("maps known id fields", () => { expect(fieldRefKind("pageId")).toBe("page"); expect(fieldRefKind("monitorIds")).toBe("monitor"); expect(fieldRefKind("componentImpacts")).toBe("componentImpacts"); });
it("ignores unknown and inherited keys", () => { expect(fieldRefKind("retry")).toBeUndefined(); expect(fieldRefKind("constructor")).toBeUndefined(); expect(fieldRefKind("toString")).toBeUndefined(); });});
describe("auditEntityKind", () => { it("maps audit entity types with a card", () => { expect(auditEntityKind("status_report")).toBe("statusReport"); expect(auditEntityKind("private_location")).toBe("privateLocation"); });
it("returns undefined for types without a card", () => { expect(auditEntityKind("api_key")).toBeUndefined(); expect(auditEntityKind("__proto__")).toBeUndefined(); });});