Skip to content

Commit f556cc3

Browse files
committed
fix tests
1 parent 87ea625 commit f556cc3

File tree

7 files changed

+35
-71
lines changed

7 files changed

+35
-71
lines changed

tests/integration/tools/atlas-search/atlasSearchHelpers.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ObjectId } from "bson";
22
import { defaultTestConfig, IntegrationTest, setupIntegrationTest } from "../../helpers.js";
3-
import { deleteAndWaitCluster, waitClusterState, withProject } from "../atlas/atlasHelpers.js";
3+
import { waitClusterState, withProject } from "../atlas/atlasHelpers.js";
44

55
export function describeWithAtlasSearch(
66
name: string,
@@ -20,7 +20,7 @@ export function describeWithAtlasSearch(
2020

2121
describe(name, () => {
2222
withProject(integration, ({ getProjectId }) => {
23-
const clusterName = "ClusterTest-" + new ObjectId().toString();
23+
const clusterName = `ClusterTest-${new ObjectId()}`;
2424
beforeAll(async () => {
2525
const projectId = getProjectId();
2626

@@ -49,14 +49,6 @@ export function describeWithAtlasSearch(
4949
});
5050
});
5151

52-
afterAll(async () => {
53-
const projectId = getProjectId();
54-
55-
const session = integration.mcpServer().session;
56-
57-
await deleteAndWaitCluster(session, projectId, clusterName);
58-
});
59-
6052
fn({
6153
...integration,
6254
connectMcpClient: async () => {

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,6 @@ describeWithAtlas("ip access lists", (integration) => {
2222
values.push(ipInfo.currentIpv4Address);
2323
});
2424

25-
afterAll(async () => {
26-
const apiClient = integration.mcpServer().session.apiClient;
27-
28-
const projectId = getProjectId();
29-
30-
for (const value of values) {
31-
await apiClient.deleteProjectIpAccessList({
32-
params: {
33-
path: {
34-
groupId: projectId,
35-
entryValue: value,
36-
},
37-
},
38-
});
39-
}
40-
});
41-
4225
describe("atlas-create-access-list", () => {
4326
it("should have correct metadata", async () => {
4427
const { tools } = await integration.mcpClient().listTools();

tests/integration/tools/atlas/atlasHelpers.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,37 @@ type ProjectTestFunction = (args: ProjectTestArgs) => void;
3535
export function withProject(integration: IntegrationTest, fn: ProjectTestFunction): void {
3636
describe("with project", () => {
3737
let projectId: string = "";
38+
const projectName = `testProj-${new ObjectId()}`;
3839

3940
beforeAll(async () => {
4041
const apiClient = integration.mcpServer().session.apiClient;
4142

42-
const group = await createProject(apiClient);
43+
const group = await createProject(apiClient, projectName);
4344
projectId = group.id || "";
4445
});
4546

4647
afterAll(async () => {
4748
const apiClient = integration.mcpServer().session.apiClient;
4849

50+
const clusters = await apiClient.listClusters({
51+
params: {
52+
path: {
53+
groupId: projectId,
54+
},
55+
},
56+
});
57+
58+
const deletePromises =
59+
clusters?.results?.map((cluster) => {
60+
if (cluster.name) {
61+
return deleteAndWaitCluster(integration.mcpServer().session, projectId, cluster.name);
62+
}
63+
64+
return Promise.resolve();
65+
}) ?? [];
66+
67+
await Promise.all(deletePromises);
68+
4969
await apiClient.deleteProject({
5070
params: {
5171
path: {
@@ -55,11 +75,9 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
5575
});
5676
});
5777

58-
const args = {
78+
fn({
5979
getProjectId: () => projectId,
60-
};
61-
62-
fn(args);
80+
});
6381
});
6482
}
6583

@@ -81,11 +99,7 @@ export function parseTable(text: string): Record<string, string>[] {
8199
});
82100
}
83101

84-
export const randomId = new ObjectId().toString();
85-
86-
async function createProject(apiClient: ApiClient): Promise<Group> {
87-
const projectName: string = `testProj-` + randomId;
88-
102+
async function createProject(apiClient: ApiClient, projectName: string): Promise<Group> {
89103
const orgs = await apiClient.listOrganizations();
90104
if (!orgs?.results?.length || !orgs.results[0].id) {
91105
throw new Error("No orgs found");
@@ -122,7 +136,7 @@ export async function waitClusterState(session: Session, projectId: string, clus
122136
}
123137
}
124138

125-
export async function deleteAndWaitCluster(session: Session, projectId: string, clusterName: string) {
139+
async function deleteAndWaitCluster(session: Session, projectId: string, clusterName: string) {
126140
await session.apiClient.deleteCluster({
127141
params: {
128142
path: {

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import { Session } from "../../../../src/session.js";
1+
import { ObjectId } from "bson";
22
import { expectDefined } from "../../helpers.js";
3-
import { describeWithAtlas, withProject, randomId, waitClusterState, deleteAndWaitCluster } from "./atlasHelpers.js";
3+
import { describeWithAtlas, withProject, waitClusterState } from "./atlasHelpers.js";
44
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
55

66
describeWithAtlas("clusters", (integration) => {
77
withProject(integration, ({ getProjectId }) => {
8-
const clusterName = "ClusterTest-" + randomId;
9-
10-
afterAll(async () => {
11-
const projectId = getProjectId();
12-
13-
const session: Session = integration.mcpServer().session;
14-
15-
await deleteAndWaitCluster(session, projectId, clusterName);
16-
});
8+
const clusterName = `ClusterTest-${new ObjectId()}`;
179

1810
describe("atlas-create-free-cluster", () => {
1911
it("should have correct metadata", async () => {

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2-
import { Session } from "../../../../src/session.js";
3-
import { describeWithAtlas, withProject, randomId } from "./atlasHelpers.js";
2+
import { describeWithAtlas, withProject } from "./atlasHelpers.js";
43
import { expectDefined } from "../../helpers.js";
4+
import { ObjectId } from "bson";
55

66
describeWithAtlas("db users", (integration) => {
7-
const userName = "testuser-" + randomId;
7+
const userName = `testuser-${new ObjectId()}`;
88
withProject(integration, ({ getProjectId }) => {
9-
afterAll(async () => {
10-
const projectId = getProjectId();
11-
12-
const session: Session = integration.mcpServer().session;
13-
await session.apiClient.deleteDatabaseUser({
14-
params: {
15-
path: {
16-
groupId: projectId,
17-
username: userName,
18-
databaseName: "admin",
19-
},
20-
},
21-
});
22-
});
23-
249
describe("atlas-create-db-user", () => {
2510
it("should have correct metadata", async () => {
2611
const { tools } = await integration.mcpClient().listTools();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describeWithAtlas("orgs", (integration) => {
1818
expect(response.content).toHaveLength(1);
1919
const data = parseTable(response.content[0].text as string);
2020
expect(data).toHaveLength(1);
21-
expect(data[0]["Organization Name"]).toEqual("MongoDB MCP Test");
21+
expect(data[0]["Organization Name"]).toBeDefined();
2222
});
2323
});
2424
});

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import { ObjectId } from "mongodb";
33
import { parseTable, describeWithAtlas } from "./atlasHelpers.js";
44
import { expectDefined } from "../../helpers.js";
55

6-
const randomId = new ObjectId().toString();
7-
86
describeWithAtlas("projects", (integration) => {
9-
const projName = "testProj-" + randomId;
7+
const projName = `testProj-${new ObjectId()}`;
108

119
afterAll(async () => {
1210
const session = integration.mcpServer().session;

0 commit comments

Comments
 (0)