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.
5.8 kB ยท 186 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187import { expect } from "@std/expect";import { describe, it } from "@std/testing/bdd";
import { addStatusReportUpdateChanges } from "./add-status-report-update";import { createStatusReportChanges } from "./create-status-report";import { resolveStatusReportChanges } from "./resolve-status-report";import { updateStatusReportChanges } from "./update-status-report";
type CreateInput = Parameters<typeof createStatusReportChanges>[0];type AddInput = Parameters<typeof addStatusReportUpdateChanges>[0];type UpdateInput = Parameters<typeof updateStatusReportChanges>[0];type ResolveInput = Parameters<typeof resolveStatusReportChanges>[0];
// safe because the mappers only read the fields each fixture setsfunction asInput<T>(value: Record<string, unknown>): T { return value as T;}
const fields = (rows: { field: string }[]) => rows.map((r) => r.field);
describe("createStatusReportChanges", () => { const base = { title: "API outage", status: "investigating", message: "Looking into it", pageId: 7, notify: true, };
it("lists the required fields for a draft", () => { expect(createStatusReportChanges(asInput<CreateInput>(base))).toEqual([ { field: "title", after: "API outage" }, { field: "status", after: "investigating" }, { field: "message", after: "Looking into it" }, { field: "pageId", after: 7 }, { field: "notify", after: true }, ]); });
it("adds optional fields only when present", () => { const rows = createStatusReportChanges( asInput<CreateInput>({ ...base, pageComponentIds: [1, 2], componentImpacts: [{ pageComponentId: 1, impact: "major_outage" }], date: "2024-01-01T00:00:00Z", }), ); expect(rows.slice(5)).toEqual([ { field: "pageComponentIds", after: [1, 2] }, { field: "componentImpacts", after: [{ pageComponentId: 1, impact: "major_outage" }], }, { field: "date", after: "2024-01-01T00:00:00Z" }, ]); });
it("skips empty component lists and a null date", () => { const rows = createStatusReportChanges( asInput<CreateInput>({ ...base, pageComponentIds: [], componentImpacts: [], date: null, }), ); expect(fields(rows)).toEqual([ "title", "status", "message", "pageId", "notify", ]); });
it("prefers the applied notify flag and appends createdAt", () => { const rows = createStatusReportChanges(asInput<CreateInput>(base), { id: 1, notified: false, createdAt: "2024-01-02T00:00:00Z", }); expect(rows.find((r) => r.field === "notify")?.after).toBe(false); expect(rows.at(-1)).toEqual({ field: "createdAt", after: "2024-01-02T00:00:00Z", }); });
it("keeps the input notify flag when the result omits it", () => { const rows = createStatusReportChanges(asInput<CreateInput>(base), { id: 1, }); expect(rows.find((r) => r.field === "notify")?.after).toBe(true); expect(fields(rows)).not.toContain("createdAt"); });});
describe("addStatusReportUpdateChanges", () => { const base = { statusReportId: 3, status: "monitoring", message: "Fix deployed", notify: false, };
it("lists the update fields", () => { expect(addStatusReportUpdateChanges(asInput<AddInput>(base))).toEqual([ { field: "statusReportId", after: 3 }, { field: "status", after: "monitoring" }, { field: "message", after: "Fix deployed" }, { field: "notify", after: false }, ]); });
it("keeps impacts structured, keeps the date and uses the applied notify flag", () => { const rows = addStatusReportUpdateChanges( asInput<AddInput>({ ...base, componentImpacts: [{ pageComponentId: 4, impact: "operational" }], date: "2024-01-01T00:00:00Z", }), { statusReportUpdateId: 9, notified: true }, ); expect(rows.find((r) => r.field === "notify")?.after).toBe(true); expect(rows.slice(4)).toEqual([ { field: "componentImpacts", after: [{ pageComponentId: 4, impact: "operational" }], }, { field: "date", after: "2024-01-01T00:00:00Z" }, ]); });});
describe("updateStatusReportChanges", () => { it("only lists the fields the model proposed", () => { expect( updateStatusReportChanges( asInput<UpdateInput>({ statusReportId: 5, title: "New title" }), ), ).toEqual([ { field: "statusReportId", after: 5 }, { field: "title", after: "New title" }, ]); });
it("keeps an explicitly empty component list", () => { expect( fields( updateStatusReportChanges( asInput<UpdateInput>({ statusReportId: 5, status: "resolved", pageComponentIds: [], }), ), ), ).toEqual(["statusReportId", "status", "pageComponentIds"]); });});
describe("resolveStatusReportChanges", () => { const base = { statusReportId: 2, message: "All good", notify: true };
it("always sets the status to resolved", () => { expect(resolveStatusReportChanges(asInput<ResolveInput>(base))).toEqual([ { field: "statusReportId", after: 2 }, { field: "status", after: "resolved" }, { field: "message", after: "All good" }, { field: "notify", after: true }, ]); });
it("appends the date and uses the applied notify flag", () => { const rows = resolveStatusReportChanges( asInput<ResolveInput>({ ...base, date: "2024-01-01T00:00:00Z" }), { statusReportUpdateId: 1, notified: false }, ); expect(rows.find((r) => r.field === "notify")?.after).toBe(false); expect(rows.at(-1)).toEqual({ field: "date", after: "2024-01-01T00:00:00Z", }); });});