islandflow/services/api/tests/alert-context.test.ts
dirtydishes 44431c4e66
All checks were successful
CI / Validate (push) Successful in 1m13s
expand ci quality gates
2026-05-30 02:34:28 -04:00

20 lines
828 B
TypeScript

import { describe, expect, it } from "bun:test";
import { isAlertContextPath, parseAlertContextTraceIdPath } from "../src/alert-context";
describe("alert context route helpers", () => {
it("extracts a valid alert trace id from the context endpoint path", () => {
expect(parseAlertContextTraceIdPath("/flow/alerts/alert%3Actx%2Fone/context")).toBe(
"alert:ctx/one"
);
});
it("returns null for unrelated alert paths", () => {
expect(isAlertContextPath("/flow/alerts")).toBe(false);
expect(parseAlertContextTraceIdPath("/flow/alerts/alert:ctx")).toBeNull();
});
it("rejects malformed trace ids safely", () => {
expect(() => parseAlertContextTraceIdPath("/flow/alerts/%20/context")).toThrow();
expect(() => parseAlertContextTraceIdPath("/flow/alerts/%24bad/context")).toThrow();
});
});