import { describe, expect, it } from "vitest"; import { featureKeys, 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.07.20"); }); 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.07.20"); }); 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(""); } }); it("marks core modules as included-in-core and keeps the Email-Marketing add-on subscription-gated (Fundament D)", () => { const blueprint = getDefaultProductBlueprint(); const includedInCoreByKey = new Map(blueprint.features.map((feature) => [feature.featureKey, feature.includedInCore])); // Core modules every tenant receives regardless of subscription (plan-gate removed). for (const coreKey of [ featureKeys.dashboard, featureKeys.crmBasic, featureKeys.leads, featureKeys.projects, featureKeys.files, featureKeys.tasks, featureKeys.hr, featureKeys.integrations, featureKeys.telephony, featureKeys.chat, featureKeys.booking, featureKeys.forms, featureKeys.signature, featureKeys.billing, featureKeys.search, featureKeys.automation, featureKeys.emailInbox, featureKeys.api, featureKeys.workflowEngine, featureKeys.mcp, featureKeys.users, ]) { expect(includedInCoreByKey.get(coreKey), `${coreKey} is a core module`).toBe(true); } // The Email-Marketing add-on (incl. its audience lists) stays subscription-gated. for (const addOnKey of [featureKeys.emailMarketing, featureKeys.importedLists, featureKeys.crmBasedLists]) { expect(includedInCoreByKey.get(addOnKey), `${addOnKey} is a paid add-on`).toBe(false); } for (const addOnKey of [featureKeys.customerPortal, featureKeys.customerPortalCustomDomain]) { expect(includedInCoreByKey.get(addOnKey), `${addOnKey} is commercially gated`).toBe(false); } expect(includedInCoreByKey.get(featureKeys.kwpIntegration), "KWP is a subscription-gated add-on").toBe(false); }); it("keeps KWP subscription-gated and non-toggleable by tenants", () => { expect(getDefaultProductBlueprint().features.find((feature) => feature.featureKey === featureKeys.kwpIntegration)).toMatchObject({ defaultEnabled: true, tenantToggleable: false, includedInCore: false, requiresTenantRolePermission: "integrations.read", }); }); it("does not permit tenant overrides to self-enable portal products", () => { const blueprint = getDefaultProductBlueprint(); for (const featureKey of [featureKeys.customerPortal, featureKeys.customerPortalCustomDomain]) { expect(blueprint.features.find((feature) => feature.featureKey === featureKey)).toMatchObject({ defaultEnabled: true, tenantToggleable: false, includedInCore: false, requiresTenantRolePermission: "portal.admin", }); } }); });