Skip to content

Commit 150a59e

Browse files
committed
add unit tests
1 parent f148623 commit 150a59e

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/common/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { z } from "zod";
1111
const levenshtein = levenshteinModule.default;
1212

1313
const previewFeatures = z.enum(["vectorSearch"]);
14-
export type PreviewFeatures = z.infer<typeof previewFeatures>;
14+
export type PreviewFeature = z.infer<typeof previewFeatures>;
1515

1616
// From: https://github.com/mongodb-js/mongosh/blob/main/packages/cli-repl/src/arg-parser.ts
1717
export const OPTIONS = {

src/tools/tool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Session } from "../common/session.js";
66
import { LogId } from "../common/logger.js";
77
import type { Telemetry } from "../telemetry/telemetry.js";
88
import { type ToolEvent } from "../telemetry/types.js";
9-
import type { PreviewFeatures, UserConfig } from "../common/config.js";
9+
import type { PreviewFeature, UserConfig } from "../common/config.js";
1010
import type { Server } from "../server.js";
1111
import type { Elicitation } from "../elicitation.js";
1212

@@ -321,8 +321,8 @@ export abstract class ToolBase {
321321
this.telemetry.emitEvents([event]);
322322
}
323323

324-
protected isFeatureEnabled(flag: PreviewFeatures): boolean {
325-
return this.config.previewFeatures.includes(flag);
324+
protected isFeatureEnabled(feature: PreviewFeature): boolean {
325+
return this.config.previewFeatures.includes(feature);
326326
}
327327
}
328328

tests/unit/toolBase.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { z } from "zod";
33
import { ToolBase, type OperationType, type ToolCategory, type ToolConstructorParams } from "../../src/tools/tool.js";
44
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
55
import type { Session } from "../../src/common/session.js";
6-
import type { UserConfig } from "../../src/common/config.js";
6+
import type { PreviewFeature, UserConfig } from "../../src/common/config.js";
77
import type { Telemetry } from "../../src/telemetry/telemetry.js";
88
import type { Elicitation } from "../../src/elicitation.js";
99
import type { CompositeLogger } from "../../src/common/logger.js";
@@ -32,6 +32,7 @@ describe("ToolBase", () => {
3232

3333
mockConfig = {
3434
confirmationRequiredTools: [],
35+
previewFeatures: [],
3536
} as unknown as UserConfig;
3637

3738
mockTelemetry = {} as Telemetry;
@@ -100,6 +101,21 @@ describe("ToolBase", () => {
100101
expect(mockRequestConfirmation).toHaveBeenCalledTimes(1);
101102
});
102103
});
104+
105+
describe("isFeatureEnabled", () => {
106+
it("should return false for any feature by default", () => {
107+
expect(testTool["isFeatureEnabled"]("vectorSearch")).to.equal(false);
108+
expect(testTool["isFeatureEnabled"]("someOtherFeature" as PreviewFeature)).to.equal(false);
109+
});
110+
111+
it("should return true for enabled features", () => {
112+
mockConfig.previewFeatures = ["vectorSearch", "someOtherFeature" as PreviewFeature];
113+
expect(testTool["isFeatureEnabled"]("vectorSearch")).to.equal(true);
114+
expect(testTool["isFeatureEnabled"]("someOtherFeature" as PreviewFeature)).to.equal(true);
115+
116+
expect(testTool["isFeatureEnabled"]("anotherFeature" as PreviewFeature)).to.equal(false);
117+
});
118+
});
103119
});
104120

105121
class TestTool extends ToolBase {

0 commit comments

Comments
 (0)