import { describe, expect, it } from "vitest"; import { getDefaultProductBlueprint, getProductBlueprint, productBlueprintIds, productBlueprints } from "./index.js"; describe("product blueprint lookups", () => { it("resolves the CRM SaaS blueprint by id and returns the shared registry instance", () => { const blueprint = getProductBlueprint(productBlueprintIds.crmSaas); expect(blueprint).toBeDefined(); expect(blueprint?.id).toBe(productBlueprintIds.crmSaas); // The lookup must hand back the frozen registry instance, not a fresh copy. expect(blueprint).toBe(productBlueprints[0]); expect(getProductBlueprint(productBlueprintIds.crmSaas)).toBe(getDefaultProductBlueprint()); }); it("returns undefined for an unknown blueprint id without throwing", () => { expect(getProductBlueprint("missing-blueprint")).toBeUndefined(); expect(getProductBlueprint("")).toBeUndefined(); }); it("exposes the default showcase blueprint as the CRM SaaS core", () => { const blueprint = getDefaultProductBlueprint(); expect(blueprint.id).toBe(productBlueprintIds.crmSaas); expect(blueprint.defaultShowcase).toBe(true); expect(blueprint.version).toBe("2026.05.15"); }); it("keeps blueprint fixtures deeply immutable", () => { expect(Object.isFrozen(productBlueprints)).toBe(true); for (const blueprint of productBlueprints) { expect(Object.isFrozen(blueprint)).toBe(true); expect(Object.isFrozen(blueprint.features)).toBe(true); for (const feature of blueprint.features) { expect(Object.isFrozen(feature)).toBe(true); } } const target = getDefaultProductBlueprint(); expect(() => { (target as { version: string }).version = "tampered"; }).toThrow(TypeError); expect(getDefaultProductBlueprint().version).toBe("2026.05.15"); }); it("gates every CRM SaaS feature behind a tenant role permission and enables it by default", () => { const blueprint = getDefaultProductBlueprint(); const featureKeysInBlueprint = blueprint.features.map((feature) => feature.featureKey); // Feature keys are unique within the blueprint feature set. expect(new Set(featureKeysInBlueprint).size).toBe(featureKeysInBlueprint.length); for (const feature of blueprint.features) { expect(feature.defaultEnabled, `${feature.featureKey} default enabled`).toBe(true); expect(typeof feature.requiresTenantRolePermission, `${feature.featureKey} required permission`).toBe("string"); expect(feature.requiresTenantRolePermission, `${feature.featureKey} non-empty permission`).not.toBe(""); } }); });