Skip to content

Commit c9dd279

Browse files
chore: adapt server.test.ts to use describeWithMongoDB
1 parent 7029428 commit c9dd279

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

tests/integration/server.test.ts

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defaultDriverOptions, defaultTestConfig, expectDefined, setupIntegrationTest } from "./helpers.js";
1+
import { defaultTestConfig, expectDefined } from "./helpers.js";
22
import { defaultTestSuiteConfig, describeWithMongoDB } from "./tools/mongodb/mongodbHelpers.js";
33
import { describe, expect, it } from "vitest";
44

@@ -25,73 +25,77 @@ describe("Server integration test", () => {
2525
}
2626
);
2727

28-
describe("with atlas", () => {
29-
const integration = setupIntegrationTest(
30-
() => ({
28+
describeWithMongoDB(
29+
"with atlas",
30+
(integration) => {
31+
describe("list capabilities", () => {
32+
it("should return positive number of tools and have some atlas tools", async () => {
33+
const tools = await integration.mcpClient().listTools();
34+
expectDefined(tools);
35+
expect(tools.tools.length).toBeGreaterThan(0);
36+
37+
const atlasTools = tools.tools.filter((tool) => tool.name.startsWith("atlas-"));
38+
expect(atlasTools.length).toBeGreaterThan(0);
39+
});
40+
41+
it("should return no prompts", async () => {
42+
await expect(() => integration.mcpClient().listPrompts()).rejects.toMatchObject({
43+
message: "MCP error -32601: Method not found",
44+
});
45+
});
46+
47+
it("should return capabilities", () => {
48+
const capabilities = integration.mcpClient().getServerCapabilities();
49+
expectDefined(capabilities);
50+
expectDefined(capabilities?.logging);
51+
expectDefined(capabilities?.completions);
52+
expectDefined(capabilities?.tools);
53+
expectDefined(capabilities?.resources);
54+
expect(capabilities.experimental).toBeUndefined();
55+
expect(capabilities.prompts).toBeUndefined();
56+
});
57+
});
58+
},
59+
{
60+
...defaultTestSuiteConfig,
61+
getUserConfig: () => ({
3162
...defaultTestConfig,
3263
apiClientId: "test",
3364
apiClientSecret: "test",
3465
}),
35-
() => defaultDriverOptions
36-
);
66+
}
67+
);
3768

38-
describe("list capabilities", () => {
39-
it("should return positive number of tools and have some atlas tools", async () => {
69+
describeWithMongoDB(
70+
"with read-only mode",
71+
(integration) => {
72+
it("should only register read and metadata operation tools when read-only mode is enabled", async () => {
4073
const tools = await integration.mcpClient().listTools();
4174
expectDefined(tools);
4275
expect(tools.tools.length).toBeGreaterThan(0);
4376

44-
const atlasTools = tools.tools.filter((tool) => tool.name.startsWith("atlas-"));
45-
expect(atlasTools.length).toBeGreaterThan(0);
46-
});
47-
48-
it("should return no prompts", async () => {
49-
await expect(() => integration.mcpClient().listPrompts()).rejects.toMatchObject({
50-
message: "MCP error -32601: Method not found",
51-
});
52-
});
77+
// Check that we have some tools available (the read and metadata ones)
78+
expect(tools.tools.some((tool) => tool.name === "find")).toBe(true);
79+
expect(tools.tools.some((tool) => tool.name === "collection-schema")).toBe(true);
80+
expect(tools.tools.some((tool) => tool.name === "list-databases")).toBe(true);
81+
expect(tools.tools.some((tool) => tool.name === "atlas-list-orgs")).toBe(true);
82+
expect(tools.tools.some((tool) => tool.name === "atlas-list-projects")).toBe(true);
5383

54-
it("should return capabilities", () => {
55-
const capabilities = integration.mcpClient().getServerCapabilities();
56-
expectDefined(capabilities);
57-
expectDefined(capabilities?.logging);
58-
expectDefined(capabilities?.completions);
59-
expectDefined(capabilities?.tools);
60-
expectDefined(capabilities?.resources);
61-
expect(capabilities.experimental).toBeUndefined();
62-
expect(capabilities.prompts).toBeUndefined();
84+
// Check that non-read tools are NOT available
85+
expect(tools.tools.some((tool) => tool.name === "insert-one")).toBe(false);
86+
expect(tools.tools.some((tool) => tool.name === "update-many")).toBe(false);
87+
expect(tools.tools.some((tool) => tool.name === "delete-one")).toBe(false);
88+
expect(tools.tools.some((tool) => tool.name === "drop-collection")).toBe(false);
6389
});
64-
});
65-
});
66-
67-
describe("with read-only mode", () => {
68-
const integration = setupIntegrationTest(
69-
() => ({
90+
},
91+
{
92+
...defaultTestSuiteConfig,
93+
getUserConfig: () => ({
7094
...defaultTestConfig,
7195
readOnly: true,
7296
apiClientId: "test",
7397
apiClientSecret: "test",
7498
}),
75-
() => defaultDriverOptions
76-
);
77-
78-
it("should only register read and metadata operation tools when read-only mode is enabled", async () => {
79-
const tools = await integration.mcpClient().listTools();
80-
expectDefined(tools);
81-
expect(tools.tools.length).toBeGreaterThan(0);
82-
83-
// Check that we have some tools available (the read and metadata ones)
84-
expect(tools.tools.some((tool) => tool.name === "find")).toBe(true);
85-
expect(tools.tools.some((tool) => tool.name === "collection-schema")).toBe(true);
86-
expect(tools.tools.some((tool) => tool.name === "list-databases")).toBe(true);
87-
expect(tools.tools.some((tool) => tool.name === "atlas-list-orgs")).toBe(true);
88-
expect(tools.tools.some((tool) => tool.name === "atlas-list-projects")).toBe(true);
89-
90-
// Check that non-read tools are NOT available
91-
expect(tools.tools.some((tool) => tool.name === "insert-one")).toBe(false);
92-
expect(tools.tools.some((tool) => tool.name === "update-many")).toBe(false);
93-
expect(tools.tools.some((tool) => tool.name === "delete-one")).toBe(false);
94-
expect(tools.tools.some((tool) => tool.name === "drop-collection")).toBe(false);
95-
});
96-
});
99+
}
100+
);
97101
});

0 commit comments

Comments
 (0)