60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { entitlementLimitTypes, evaluateProductAccess, featureKeys, productBlueprintIds } from "./index.js";
|
|
|
|
const crmSaas = productBlueprintIds.crmSaas;
|
|
|
|
describe("evaluateProductAccess denied-entitlement passthrough", () => {
|
|
it("returns the missing-subscription entitlement under inherit without running the role gate", () => {
|
|
const decision = evaluateProductAccess({
|
|
blueprintId: crmSaas,
|
|
featureKey: featureKeys.crmBasic,
|
|
hasSubscription: false,
|
|
limitType: entitlementLimitTypes.included,
|
|
// A valid permission is supplied, but the denied entitlement must short-circuit before the gate.
|
|
tenantRolePermissionNames: ["app.dashboard.view"],
|
|
});
|
|
|
|
expect(decision).toMatchObject({
|
|
allowed: false,
|
|
reason: "missing-subscription",
|
|
blueprintId: crmSaas,
|
|
tenantOverride: "inherit",
|
|
});
|
|
expect(decision.requiredTenantRolePermission).toBeUndefined();
|
|
});
|
|
|
|
it("passes an exhausted monthly quota straight through under an inherited override", () => {
|
|
const decision = evaluateProductAccess({
|
|
blueprintId: crmSaas,
|
|
featureKey: featureKeys.supportTickets,
|
|
hasSubscription: true,
|
|
limitType: entitlementLimitTypes.monthly,
|
|
limit: 50,
|
|
used: 50,
|
|
period: "2026-06",
|
|
tenantRolePermissionNames: ["app.dashboard.view"],
|
|
});
|
|
|
|
expect(decision).toMatchObject({
|
|
allowed: false,
|
|
reason: "monthly-exhausted",
|
|
blueprintId: crmSaas,
|
|
tenantOverride: "inherit",
|
|
remaining: 0,
|
|
period: "2026-06",
|
|
});
|
|
expect(decision.requiredTenantRolePermission).toBeUndefined();
|
|
});
|
|
|
|
it("defaults the tenant override to inherit when none is supplied", () => {
|
|
const decision = evaluateProductAccess({
|
|
blueprintId: crmSaas,
|
|
featureKey: featureKeys.crmBasic,
|
|
hasSubscription: false,
|
|
});
|
|
|
|
expect(decision.tenantOverride).toBe("inherit");
|
|
});
|
|
});
|