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.
1.4 kB ยท 42 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243import { expect } from "@std/expect";import { describe, test } from "@std/testing/bdd";
import { ForbiddenError } from "../errors";import { type Feature, isFeatureEnabled, requireFeature } from "../features";import type { Workspace } from "../types";
const none = new Set<string>();// No feature is gated right now; exercise the mechanism with a stand-in.const flag = "test-feature" as Feature;
describe("isFeatureEnabled", () => { test("off without an allowlist entry or env override", () => { expect(isFeatureEnabled({ id: 1 }, flag, none)).toBe(false); });
test("env override enables it for every workspace", () => { expect(isFeatureEnabled({ id: 987654321 }, flag, new Set([flag]))).toBe( true, ); });});
describe("requireFeature", () => { test("throws ForbiddenError when disabled", () => { // The package test script may enable features globally; clear it here. const processEnv: Record<string, string | undefined> = process.env; const saved = processEnv.OPENSTATUS_FEATURES; delete processEnv.OPENSTATUS_FEATURES; try { const workspace = { id: 987654321 } as Workspace; expect(() => requireFeature( { workspace, actor: { type: "system", job: "test" } }, flag, ), ).toThrow(ForbiddenError); } finally { if (saved !== undefined) processEnv.OPENSTATUS_FEATURES = saved; } });});