Skip to content

Commit dcfcad0

Browse files
committed
update tests
1 parent b811a9c commit dcfcad0

File tree

4 files changed

+44
-70
lines changed

4 files changed

+44
-70
lines changed

src/tools/atlas/connect/connectCluster.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ function sleep(ms: number): Promise<void> {
2222
export const ConnectClusterArgs = {
2323
projectId: AtlasArgs.projectId().describe("Atlas project ID"),
2424
clusterName: AtlasArgs.clusterName().describe("Atlas cluster name"),
25-
connectionType: AtlasArgs.connectionType().describe(
26-
"Type of connection (standard, private, or privateEndpoint) to an Atlas cluster"
27-
),
2825
};
2926

3027
export class ConnectClusterTool extends AtlasToolBase {

tests/integration/tools/atlas/alerts.test.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { expectDefined, getResponseElements } from "../../helpers.js";
2-
import { parseTable, describeWithAtlas, withProject } from "./atlasHelpers.js";
1+
import { expectDefined, getResponseContent } from "../../helpers.js";
2+
import { describeWithAtlas, withProject } from "./atlasHelpers.js";
33
import { expect, it } from "vitest";
44

55
describeWithAtlas("atlas-list-alerts", (integration) => {
@@ -13,26 +13,20 @@ describeWithAtlas("atlas-list-alerts", (integration) => {
1313
});
1414

1515
withProject(integration, ({ getProjectId }) => {
16-
it("returns alerts in table format", async () => {
16+
it("returns alerts in JSON format", async () => {
1717
const response = await integration.mcpClient().callTool({
1818
name: "atlas-list-alerts",
1919
arguments: { projectId: getProjectId() },
2020
});
2121

22-
const elements = getResponseElements(response.content);
23-
expect(elements).toHaveLength(1);
24-
25-
const data = parseTable(elements[0]?.text ?? "");
26-
27-
// Since we can't guarantee alerts will exist, we just verify the table structure
28-
if (data.length > 0) {
29-
const alert = data[0];
30-
expect(alert).toHaveProperty("Alert ID");
31-
expect(alert).toHaveProperty("Status");
32-
expect(alert).toHaveProperty("Created");
33-
expect(alert).toHaveProperty("Updated");
34-
expect(alert).toHaveProperty("Type");
35-
expect(alert).toHaveProperty("Comment");
22+
const content = getResponseContent(response.content);
23+
// check that there are alerts or no alerts
24+
if (content.includes("Found alerts in project")) {
25+
expect(content).toContain("<untrusted-user-data-");
26+
// expect projectId in the content
27+
expect(content).toContain(getProjectId());
28+
} else {
29+
expect(content).toContain("No alerts found");
3630
}
3731
});
3832
});

tests/integration/tools/atlas/clusters.test.ts

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import type { Session } from "../../../../src/common/session.js";
2-
import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js";
3-
import {
4-
describeWithAtlas,
5-
withProject,
6-
randomId,
7-
parseTable,
8-
deleteCluster,
9-
waitCluster,
10-
sleep,
11-
} from "./atlasHelpers.js";
2+
import { expectDefined, getResponseContent } from "../../helpers.js";
3+
import { describeWithAtlas, withProject, randomId, deleteCluster, waitCluster, sleep } from "./atlasHelpers.js";
124
import { afterAll, beforeAll, describe, expect, it } from "vitest";
135

146
describeWithAtlas("clusters", (integration) => {
@@ -48,9 +40,11 @@ describeWithAtlas("clusters", (integration) => {
4840
region: "US_EAST_1",
4941
},
5042
});
51-
const elements = getResponseElements(response.content);
52-
expect(elements).toHaveLength(2);
53-
expect(elements[0]?.text).toContain("has been created");
43+
const content = getResponseContent(response.content);
44+
expect(content).toContain("Cluster");
45+
expect(content).toContain(clusterName);
46+
expect(content).toContain("has been created");
47+
expect(content).toContain("US_EAST_1");
5448

5549
// Check that the current IP is present in the access list
5650
const accessList = await session.apiClient.listProjectIpAccessLists({
@@ -80,11 +74,10 @@ describeWithAtlas("clusters", (integration) => {
8074
name: "atlas-inspect-cluster",
8175
arguments: { projectId, clusterName: clusterName },
8276
});
83-
const elements = getResponseElements(response.content);
84-
expect(elements).toHaveLength(2);
85-
expect(elements[0]?.text).toContain("Cluster details:");
86-
expect(elements[1]?.text).toContain("<untrusted-user-data-");
87-
expect(elements[1]?.text).toContain(`${clusterName}`);
77+
const content = getResponseContent(response.content);
78+
expect(content).toContain("Cluster details:");
79+
expect(content).toContain("<untrusted-user-data-");
80+
expect(content).toContain(clusterName);
8881
});
8982
});
9083

@@ -105,14 +98,10 @@ describeWithAtlas("clusters", (integration) => {
10598
.mcpClient()
10699
.callTool({ name: "atlas-list-clusters", arguments: { projectId } });
107100

108-
const elements = getResponseElements(response);
109-
expect(elements).toHaveLength(2);
110-
111-
expect(elements[1]?.text).toContain("<untrusted-user-data-");
112-
expect(elements[1]?.text).toContain(`${clusterName} | `);
113-
const data = parseTable(getDataFromUntrustedContent(elements[1]?.text ?? ""));
114-
expect(data.length).toBeGreaterThanOrEqual(1);
115-
expect(elements[0]?.text).toMatch(`Found ${data.length} clusters in project`);
101+
const content = getResponseContent(response.content);
102+
expect(content).toContain("<untrusted-user-data-");
103+
expect(content).toMatch(`Found clusters in project`);
104+
expect(content).toContain(projectId);
116105
});
117106
});
118107

@@ -164,23 +153,20 @@ describeWithAtlas("clusters", (integration) => {
164153
arguments: { projectId, clusterName, connectionType },
165154
});
166155

167-
const elements = getResponseElements(response.content);
168-
expect(elements.length).toBeGreaterThanOrEqual(1);
169-
if (elements[0]?.text.includes(`Connected to cluster "${clusterName}"`)) {
156+
const content = getResponseContent(response.content);
157+
expect(content).toContain("Connected to cluster");
158+
expect(content).toContain(clusterName);
159+
if (content.includes(`Connected to cluster "${clusterName}"`)) {
170160
connected = true;
171161

172162
// assert that some of the element s have the message
173-
expect(
174-
elements.some((element) =>
175-
element.text.includes(
176-
"Note: A temporary user has been created to enable secure connection to the cluster. For more information, see https://dochub.mongodb.org/core/mongodb-mcp-server-tools-considerations"
177-
)
178-
)
179-
).toBe(true);
163+
expect(content).toContain(
164+
"Note: A temporary user has been created to enable secure connection to the cluster. For more information, see https://dochub.mongodb.org/core/mongodb-mcp-server-tools-considerations"
165+
);
180166

181167
break;
182168
} else {
183-
expect(elements[0]?.text).toContain(`Attempting to connect to cluster "${clusterName}"...`);
169+
expect(content).toContain(`Attempting to connect to cluster "${clusterName}"...`);
184170
}
185171
await sleep(500);
186172
}
@@ -193,19 +179,18 @@ describeWithAtlas("clusters", (integration) => {
193179
name: "find",
194180
arguments: { database: "some-db", collection: "some-collection" },
195181
});
196-
const elements = getResponseElements(response.content);
197-
expect(elements).toHaveLength(2);
198-
expect(elements[0]?.text).toContain(
182+
const content = getResponseContent(response.content);
183+
expect(content).toContain(
199184
"You need to connect to a MongoDB instance before you can access its data."
200185
);
201186
// Check if the response contains all available test tools.
202187
if (process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true") {
203188
// The tool atlas-local-connect-deployment may be disabled in some test environments if Docker is not available.
204-
expect(elements[1]?.text).toContain(
189+
expect(content).toContain(
205190
'Please use one of the following tools: "atlas-connect-cluster", "connect" to connect to a MongoDB instance'
206191
);
207192
} else {
208-
expect(elements[1]?.text).toContain(
193+
expect(content).toContain(
209194
'Please use one of the following tools: "atlas-connect-cluster", "atlas-local-connect-deployment", "connect" to connect to a MongoDB instance'
210195
);
211196
}

tests/integration/tools/atlas/orgs.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js";
2-
import { parseTable, describeWithAtlas, withCredentials } from "./atlasHelpers.js";
1+
import { expectDefined, getResponseContent } from "../../helpers.js";
2+
import { describeWithAtlas, withCredentials } from "./atlasHelpers.js";
33
import { describe, expect, it } from "vitest";
44

55
describeWithAtlas("orgs", (integration) => {
@@ -13,12 +13,10 @@ describeWithAtlas("orgs", (integration) => {
1313

1414
it("returns org names", async () => {
1515
const response = await integration.mcpClient().callTool({ name: "atlas-list-orgs", arguments: {} });
16-
const elements = getResponseElements(response);
17-
expect(elements[0]?.text).toContain("Found 1 organizations");
18-
expect(elements[1]?.text).toContain("<untrusted-user-data-");
19-
const data = parseTable(getDataFromUntrustedContent(elements[1]?.text ?? ""));
20-
expect(data).toHaveLength(1);
21-
expect(data[0]?.["Organization Name"]).toEqual("MongoDB MCP Test");
16+
const content = getResponseContent(response.content);
17+
expect(content).toContain("Found 1 organizations");
18+
expect(content).toContain("<untrusted-user-data-");
19+
expect(content).toContain("MongoDB MCP Test");
2220
});
2321
});
2422
});

0 commit comments

Comments
 (0)