|
| 1 | +import * as sinon from "sinon"; |
| 2 | +import { expect } from "chai"; |
| 3 | +import { McpContext } from "../types"; |
| 4 | +import { availablePrompts } from "./index"; |
| 5 | +// We import the *module* so we can stub the exported function on it |
| 6 | +import * as availabilityUtil from "../util/availability"; |
| 7 | + |
| 8 | +describe("availablePrompts", () => { |
| 9 | + let sandbox: sinon.SinonSandbox; |
| 10 | + let getDefaultFeatureAvailabilityCheckStub: sinon.SinonStub; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + sandbox = sinon.createSandbox(); |
| 14 | + // Default stub checks to return false |
| 15 | + getDefaultFeatureAvailabilityCheckStub = sandbox.stub( |
| 16 | + availabilityUtil, |
| 17 | + "getDefaultFeatureAvailabilityCheck", |
| 18 | + ); |
| 19 | + |
| 20 | + getDefaultFeatureAvailabilityCheckStub.withArgs("crashlytics").returns(async () => false); |
| 21 | + getDefaultFeatureAvailabilityCheckStub.callThrough(); |
| 22 | + }); |
| 23 | + |
| 24 | + afterEach(() => { |
| 25 | + sandbox.restore(); |
| 26 | + }); |
| 27 | + |
| 28 | + const mockContext: McpContext = { |
| 29 | + projectId: "test-project", |
| 30 | + accountEmail: "[email protected]", |
| 31 | + config: {} as any, |
| 32 | + host: { |
| 33 | + logger: { |
| 34 | + debug: () => void 0, |
| 35 | + info: () => void 0, |
| 36 | + warn: () => void 0, |
| 37 | + error: () => void 0, |
| 38 | + }, |
| 39 | + } as any, |
| 40 | + rc: {} as any, |
| 41 | + firebaseCliCommand: "firebase", |
| 42 | + isBillingEnabled: true, |
| 43 | + }; |
| 44 | + |
| 45 | + it("should return core prompts by default", async () => { |
| 46 | + const prompts = await availablePrompts(mockContext, [], []); |
| 47 | + const corePrompt = prompts.find((p) => p.mcp._meta?.feature === "core"); |
| 48 | + expect(corePrompt).to.exist; |
| 49 | + }); |
| 50 | + |
| 51 | + it("should include feature-specific prompts when activeFeatures is provided", async () => { |
| 52 | + const prompts = await availablePrompts(mockContext, ["crashlytics"]); |
| 53 | + |
| 54 | + const features = [...new Set(prompts.map((p) => p.mcp._meta?.feature))]; |
| 55 | + expect(features).to.have.members(["core", "crashlytics"]); |
| 56 | + |
| 57 | + // getDefaultFeatureAvailabilityCheck execution is deferred/lazy-loaded in prompt.ts |
| 58 | + // Since activeFeatures bypasses checking .isAvailable on the prompt, the stub should NOT be called. |
| 59 | + expect(getDefaultFeatureAvailabilityCheckStub.called).to.be.false; |
| 60 | + }); |
| 61 | + |
| 62 | + it("should not include feature prompts if not in activeFeatures", async () => { |
| 63 | + const prompts = await availablePrompts(mockContext, [], []); |
| 64 | + const crashPrompt = prompts.find((p) => p.mcp._meta?.feature === "crashlytics"); |
| 65 | + expect(crashPrompt).to.not.exist; |
| 66 | + }); |
| 67 | + |
| 68 | + it("should fallback to detectedFeatures if activeFeatures is empty", async () => { |
| 69 | + // For this test, we want availability to be true |
| 70 | + getDefaultFeatureAvailabilityCheckStub.withArgs("crashlytics").returns(async () => true); |
| 71 | + |
| 72 | + const prompts = await availablePrompts(mockContext, [], ["crashlytics"]); |
| 73 | + const features = [...new Set(prompts.map((p) => p.mcp._meta?.feature))]; |
| 74 | + expect(features).to.have.members(["core", "crashlytics"]); |
| 75 | + |
| 76 | + // Fallback logic calls isAvailable(), which invokes our lazy check, calling getDefault... |
| 77 | + expect(getDefaultFeatureAvailabilityCheckStub.called).to.be.true; |
| 78 | + }); |
| 79 | +}); |
0 commit comments