Skip to content

Commit 9a2c002

Browse files
chore: use describeWithMongoDB to setup test suites instead of custom wiring (#650)
1 parent 8e3c6a6 commit 9a2c002

File tree

12 files changed

+533
-480
lines changed

12 files changed

+533
-480
lines changed

tests/integration/common/connectionManager.oidc.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,19 @@ describe.skipIf(process.platform !== "linux")("ConnectionManager OIDC Tests", as
137137

138138
addCb?.(oidcIt);
139139
},
140-
() => oidcConfig,
141-
() => ({
142-
...setupDriverConfig({
143-
config: oidcConfig,
144-
defaults: {},
145-
}),
146-
}),
147-
{ runner: true, downloadOptions: { enterprise: true, version: mongodbVersion }, serverArgs }
140+
{
141+
getUserConfig: () => oidcConfig,
142+
getDriverOptions: () =>
143+
setupDriverConfig({
144+
config: oidcConfig,
145+
defaults: {},
146+
}),
147+
downloadOptions: {
148+
runner: true,
149+
downloadOptions: { enterprise: true, version: mongodbVersion },
150+
serverArgs,
151+
},
152+
}
148153
);
149154
}
150155

tests/integration/elicitation.test.ts

Lines changed: 257 additions & 248 deletions
Large diffs are not rendered by default.

tests/integration/indexCheck.test.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,12 @@ describe("IndexCheck integration tests", () => {
313313
});
314314
});
315315
},
316-
() => ({
317-
...defaultTestConfig,
318-
indexCheck: true, // Enable indexCheck
319-
})
316+
{
317+
getUserConfig: () => ({
318+
...defaultTestConfig,
319+
indexCheck: true, // Enable indexCheck
320+
}),
321+
}
320322
);
321323
});
322324

@@ -424,10 +426,12 @@ describe("IndexCheck integration tests", () => {
424426
expect(content).not.toContain("Index check failed");
425427
});
426428
},
427-
() => ({
428-
...defaultTestConfig,
429-
indexCheck: false, // Disable indexCheck
430-
})
429+
{
430+
getUserConfig: () => ({
431+
...defaultTestConfig,
432+
indexCheck: false, // Disable indexCheck
433+
}),
434+
}
431435
);
432436
});
433437

@@ -456,10 +460,12 @@ describe("IndexCheck integration tests", () => {
456460
expect(response.isError).toBeFalsy();
457461
});
458462
},
459-
() => ({
460-
...defaultTestConfig,
461-
// indexCheck not specified, should default to false
462-
})
463+
{
464+
getUserConfig: () => ({
465+
...defaultTestConfig,
466+
// indexCheck not specified, should default to false
467+
}),
468+
}
463469
);
464470
});
465471
});

tests/integration/resources/exportedData.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,7 @@ describeWithMongoDB(
173173
});
174174
});
175175
},
176-
() => userConfig
176+
{
177+
getUserConfig: () => userConfig,
178+
}
177179
);

tests/integration/server.test.ts

Lines changed: 63 additions & 60 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 { describeWithMongoDB } from "./tools/mongodb/mongodbHelpers.js";
33
import { describe, expect, it } from "vitest";
44

@@ -15,81 +15,84 @@ describe("Server integration test", () => {
1515
expect(atlasTools.length).toBeLessThanOrEqual(0);
1616
});
1717
},
18-
() => ({
19-
...defaultTestConfig,
20-
apiClientId: undefined,
21-
apiClientSecret: undefined,
22-
}),
23-
() => defaultDriverOptions
18+
{
19+
getUserConfig: () => ({
20+
...defaultTestConfig,
21+
apiClientId: undefined,
22+
apiClientSecret: undefined,
23+
}),
24+
}
2425
);
2526

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

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

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

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

0 commit comments

Comments
 (0)