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.
2.0 kB ยท 82 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283import { expect } from "@std/expect";import { describe, it } from "@std/testing/bdd";
import { deserialize, serialize } from "./serializing";import { DnsRecordAssertion, HeaderAssertion, JsonBodyAssertion, StatusAssertion, TextBodyAssertion,} from "./v1";
const raw = [ { version: "v1", type: "status", compare: "eq", target: 200 }, { version: "v1", type: "header", compare: "contains", key: "Content-Type", target: "json", }, { version: "v1", type: "textBody", compare: "not_empty", target: "" }, { version: "v1", type: "jsonBody", path: "$.status", compare: "contains", target: "ok", }, { version: "v1", type: "dnsRecord", key: "A", compare: "eq", target: "1.1.1.1", },];
describe("deserialize", () => { it("builds the matching class for each type", () => { const assertions = deserialize(JSON.stringify(raw)); expect(assertions.map((a) => a.constructor)).toEqual([ StatusAssertion, HeaderAssertion, TextBodyAssertion, JsonBodyAssertion, DnsRecordAssertion, ]); });
it("fills in a missing version", () => { const [a] = deserialize('[{"type":"status","compare":"eq","target":200}]'); expect(a.schema.version).toBe("v1"); });
it("returns nothing for an empty list", () => { expect(deserialize("[]")).toEqual([]); });
it("throws on an unknown type", () => { expect(() => deserialize('[{"type":"latency"}]')).toThrow( "unknown assertion type: latency", ); });
it("throws when a known type has invalid fields", () => { expect(() => deserialize('[{"type":"status","compare":"contains","target":200}]'), ).toThrow(); });
it("throws on malformed JSON", () => { expect(() => deserialize("not json")).toThrow(); });});
describe("serialize", () => { it("round-trips through deserialize", () => { const json = JSON.stringify(raw); expect(JSON.parse(serialize(deserialize(json)))).toEqual(raw); });});