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.5 kB ยท 128 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129import { db, eq } from "@openstatus/db";import { monitor } from "@openstatus/db/src/schema";import { allPlans } from "@openstatus/db/src/schema/plan/config";import { expect } from "@std/expect";import { afterAll, beforeAll, test } from "@std/testing/bdd";import { TRPCError } from "@trpc/server";
import { edgeRouter } from "../edge";import { createInnerTRPCContext } from "../trpc";
let otherWorkspaceMonitorId: number;
beforeAll(async () => { const m = await db .insert(monitor) .values({ workspaceId: 3, name: "Other workspace monitor", jobType: "http", periodicity: "1m", url: "https://example.com", regions: "ams", active: true, }) .returning() .get(); otherWorkspaceMonitorId = m.id;});
afterAll(async () => { await db.delete(monitor).where(eq(monitor.id, otherWorkspaceMonitorId));});
test("pageComponent.updateOrder rejects monitorId from another workspace", async () => { const ctx = createInnerTRPCContext({ req: undefined, session: { user: { id: "1" } }, // @ts-expect-error - minimal workspace for test workspace: { id: 1, limits: allPlans.team.limits }, }); const caller = edgeRouter.createCaller(ctx);
try { await caller.pageComponent.updateOrder({ pageId: 1, // page 1 belongs to workspace 1 components: [ { id: 1, monitorId: otherWorkspaceMonitorId, // monitor from workspace 2 order: 0, name: "Injected Monitor", type: "monitor", }, ], groups: [], }); throw new Error("Should have thrown"); } catch (e) { expect(e).toBeInstanceOf(TRPCError); expect((e as TRPCError).code).toBe("FORBIDDEN"); }});
test("pageComponent.updateOrder rejects monitorId from another workspace in groups", async () => { const ctx = createInnerTRPCContext({ req: undefined, session: { user: { id: "1" } }, // @ts-expect-error - minimal workspace for test workspace: { id: 1, limits: allPlans.team.limits }, }); const caller = edgeRouter.createCaller(ctx);
try { await caller.pageComponent.updateOrder({ pageId: 1, components: [], groups: [ { order: 0, name: "Injected Group", components: [ { monitorId: otherWorkspaceMonitorId, // monitor from workspace 2 order: 0, name: "Injected Monitor in Group", type: "monitor", }, ], }, ], }); throw new Error("Should have thrown"); } catch (e) { expect(e).toBeInstanceOf(TRPCError); expect((e as TRPCError).code).toBe("FORBIDDEN"); }});
test("pageComponent.updateOrder succeeds with own workspace monitorId", async () => { const ctx = createInnerTRPCContext({ req: undefined, session: { user: { id: "1" } }, // @ts-expect-error - minimal workspace for test workspace: { id: 1, limits: allPlans.team.limits }, }); const caller = edgeRouter.createCaller(ctx);
const result = await caller.pageComponent.updateOrder({ pageId: 1, components: [ { monitorId: 1, // monitor 1 belongs to workspace 1 order: 0, name: "OpenStatus Monitor", type: "monitor", }, { monitorId: 2, // monitor 2 belongs to workspace 1 order: 1, name: "Google Monitor", type: "monitor", }, ], groups: [], });
expect(result).toEqual({ success: true });});