import { describe, expect, it } from "vitest"; import { buildFeatureFlagStudioVM, deriveFeatureFlagRisk } from "./feature-flag-studio.vm.js"; describe("feature flag studio view-model", () => { it("classifies global enabled flags without targeting as high risk", () => { expect( deriveFeatureFlagRisk({ id: "flag_1", name: "maintenance", description: "Maintenance", enabled: true, scope: "global", filtersCount: 0, eventsCount: 0, rulesConfigured: false, variantsCount: 0, }) ).toBe("high"); }); it("builds rollout summary and top flags", () => { const vm = buildFeatureFlagStudioVM({ flags: [ { id: "flag_a", name: "a", description: "A", enabled: true, scope: "global", filtersCount: 0, eventsCount: 3, rulesConfigured: false, variantsCount: 0, }, { id: "flag_b", name: "b", description: "B", enabled: true, scope: "tenant", tenantId: "tenant_1", filtersCount: 1, eventsCount: 9, rulesConfigured: true, variantsCount: 2, enabledFrom: "2026-07-09T00:00:00.000Z", }, { id: "flag_c", name: "c", description: "C", enabled: false, scope: "global", filtersCount: 0, eventsCount: 1, rulesConfigured: false, variantsCount: 0, }, ], }); expect(vm.status).toBe("ready"); if (vm.status !== "ready") return; expect(vm.data.summary).toMatchObject({ flagsTotal: 3, flagsEnabled: 2, flagsDisabled: 1, triggersTotal: 13, scopedFlags: 1, targetedFlags: 1, scheduledFlags: 1, highRiskFlags: 1, }); expect(vm.data.topFlags[0]?.name).toBe("b"); }); });