34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { assertKnownFeatureKey, getFeatureGate, isFeatureKey } from "./index.js";
|
|
|
|
describe("feature gate edge cases", () => {
|
|
it("includes the offending key in the assertion error message", () => {
|
|
expect(() => assertKnownFeatureKey("totally-made-up")).toThrow(RangeError);
|
|
expect(() => assertKnownFeatureKey("totally-made-up")).toThrow(/totally-made-up/);
|
|
});
|
|
|
|
it("rejects the empty string as a feature key", () => {
|
|
expect(isFeatureKey("")).toBe(false);
|
|
expect(getFeatureGate("")).toBeUndefined();
|
|
});
|
|
|
|
it("returns the full registry item for a known key via the lookup overload", () => {
|
|
const rateLimit = getFeatureGate("rate-limit-per-minute");
|
|
|
|
expect(rateLimit).toBeDefined();
|
|
expect(rateLimit?.category).toBe("usage");
|
|
// Rate limits are capped or off, never metered monthly.
|
|
expect(rateLimit?.supportedLimitTypes).toEqual(["not-included", "max", "unlimited"]);
|
|
expect(rateLimit?.supportedLimitTypes).not.toContain("monthly");
|
|
});
|
|
|
|
it("constrains pure access features to the access limit family", () => {
|
|
const knowledgeBaseRead = getFeatureGate("knowledge-base-read");
|
|
|
|
expect(knowledgeBaseRead?.supportedLimitTypes).toEqual(["not-included", "included", "unlimited"]);
|
|
expect(knowledgeBaseRead?.supportedLimitTypes).not.toContain("max");
|
|
expect(knowledgeBaseRead?.supportedLimitTypes).not.toContain("monthly");
|
|
});
|
|
});
|