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.
3.4 kB ยท 108 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import { expect } from "@std/expect";import { describe, it } from "@std/testing/bdd";
import { createMaintenanceChanges } from "./create-maintenance";import { addMaintenanceUpdateChanges, deleteMaintenanceUpdateChanges, updateMaintenanceUpdateChanges,} from "./maintenance-update";
// safe because the mappers only read the fields each fixture setsfunction asInput<T>(value: Record<string, unknown>): T { return value as T;}
describe("createMaintenanceChanges", () => { const input = asInput<Parameters<typeof createMaintenanceChanges>[0]>({ title: "DB upgrade", message: "Short downtime", from: "2024-01-01T00:00:00Z", to: "2024-01-01T01:00:00Z", pageId: 1, pageComponentIds: [2, 3], notify: true, });
it("lists every field in a fixed order", () => { expect(createMaintenanceChanges(input)).toEqual([ { field: "title", after: "DB upgrade" }, { field: "message", after: "Short downtime" }, { field: "from", after: "2024-01-01T00:00:00Z" }, { field: "to", after: "2024-01-01T01:00:00Z" }, { field: "pageId", after: 1 }, { field: "pageComponentIds", after: [2, 3] }, { field: "notify", after: true }, ]); });
it("prefers the applied notify flag", () => { const rows = createMaintenanceChanges(input, { id: 1, notified: false }); expect(rows.at(-1)).toEqual({ field: "notify", after: false }); });});
describe("addMaintenanceUpdateChanges", () => { type Input = Parameters<typeof addMaintenanceUpdateChanges>[0];
it("omits the id and date for a draft without a date", () => { expect( addMaintenanceUpdateChanges( asInput<Input>({ maintenanceId: 4, message: "Started", notify: true }), ), ).toEqual([ { field: "maintenanceId", after: 4 }, { field: "message", after: "Started" }, { field: "notify", after: true }, ]); });
it("leads with the applied id and uses the applied notify flag", () => { expect( addMaintenanceUpdateChanges( asInput<Input>({ maintenanceId: 4, message: "Started", date: "2024-01-01T00:00:00Z", notify: true, }), { id: 11, notified: false }, ), ).toEqual([ { field: "id", after: 11 }, { field: "maintenanceId", after: 4 }, { field: "message", after: "Started" }, { field: "date", after: "2024-01-01T00:00:00Z" }, { field: "notify", after: false }, ]); });});
describe("updateMaintenanceUpdateChanges", () => { type Input = Parameters<typeof updateMaintenanceUpdateChanges>[0];
it("lists only the provided fields", () => { expect(updateMaintenanceUpdateChanges(asInput<Input>({ id: 3 }))).toEqual([ { field: "id", after: 3 }, ]); expect( updateMaintenanceUpdateChanges( asInput<Input>({ id: 3, message: "Edited", date: "2024-01-01" }), ), ).toEqual([ { field: "id", after: 3 }, { field: "message", after: "Edited" }, { field: "date", after: "2024-01-01" }, ]); });});
describe("deleteMaintenanceUpdateChanges", () => { it("shows the id as removed", () => { const rows = deleteMaintenanceUpdateChanges( asInput<Parameters<typeof deleteMaintenanceUpdateChanges>[0]>({ id: 8 }), ); expect(rows).toEqual([{ field: "id", before: 8 }]); expect("after" in rows[0]).toBe(false); });});