Skip to content

Commit a918832

Browse files
committed
refactor: split tests
1 parent 5a3b06a commit a918832

File tree

11 files changed

+545
-411
lines changed

11 files changed

+545
-411
lines changed

.github/workflows/atlas_tests.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/code_health.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ jobs:
5151
- name: Install dependencies
5252
run: npm ci
5353
- name: Run tests
54+
env:
55+
MDB_MCP_API_CLIENT_ID: ${{ secrets.TEST_ATLAS_CLIENT_ID }}
56+
MDB_MCP_API_CLIENT_SECRET: ${{ secrets.TEST_ATLAS_CLIENT_SECRET }}
57+
MDB_MCP_API_BASE_URL: ${{ vars.TEST_ATLAS_BASE_URL }}
5458
run: npm test
5559
- name: Coveralls GitHub Action
5660
uses: coverallsapp/github-action@v2.3.6

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export default {
33
preset: "ts-jest/presets/default-esm",
44
testEnvironment: "node",
55
extensionsToTreatAsEsm: [".ts"],
6+
testTimeout: 30000, // 30 seconds
67
moduleNameMapper: {
78
"^(\\.{1,2}/.*)\\.js$": "$1", // Map .js to real paths for ESM
89
},

tests/integration/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ interface ParameterInfo {
1919

2020
type ToolInfo = Awaited<ReturnType<Client["listTools"]>>["tools"][number];
2121

22-
export function setupIntegrationTest(): {
22+
export interface IntegrationTest {
2323
mcpClient: () => Client;
2424
mcpServer: () => Server;
2525
mongoClient: () => MongoClient;
2626
connectionString: () => string;
2727
connectMcpClient: () => Promise<void>;
2828
randomDbName: () => string;
29-
} {
29+
};
30+
31+
export function setupIntegrationTest(): IntegrationTest {
3032
let mongoCluster: runner.MongoCluster | undefined;
3133
let mongoClient: MongoClient | undefined;
3234

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2+
import { Session } from "../../../../src/session.js";
3+
import { describeAtlas, withProject } from "./atlasHelpers.js";
4+
5+
describeAtlas("ip access lists", (integration) => {
6+
withProject(integration, ({ getProjectId }) => {
7+
let ipInfo: {
8+
currentIpv4Address: string;
9+
};
10+
11+
beforeAll(async () => {
12+
const session: Session = integration.mcpServer().session;
13+
session.ensureAuthenticated();
14+
ipInfo = await session.apiClient.getIpInfo();
15+
});
16+
17+
afterAll(async () => {
18+
const session: Session = integration.mcpServer().session;
19+
session.ensureAuthenticated();
20+
21+
const projectId = getProjectId();
22+
23+
await session.apiClient.deleteProjectIpAccessList({
24+
params: {
25+
path: {
26+
groupId: projectId,
27+
entryValue: ipInfo.currentIpv4Address,
28+
},
29+
},
30+
});
31+
32+
await session.apiClient.deleteProjectIpAccessList({
33+
params: {
34+
path: {
35+
groupId: projectId,
36+
entryValue: "8.8.8.8",
37+
},
38+
},
39+
});
40+
41+
await session.apiClient.deleteProjectIpAccessList({
42+
params: {
43+
path: {
44+
groupId: projectId,
45+
entryValue: "9.9.9.9/24",
46+
},
47+
},
48+
});
49+
});
50+
51+
describe("atlas-create-access-list", () => {
52+
it("should have correct metadata", async () => {
53+
const { tools } = await integration.mcpClient().listTools();
54+
const createAccessList = tools.find((tool) => tool.name === "atlas-create-access-list")!;
55+
expect(createAccessList).toBeDefined();
56+
expect(createAccessList.inputSchema.type).toBe("object");
57+
expect(createAccessList.inputSchema.properties).toBeDefined();
58+
expect(createAccessList.inputSchema.properties).toHaveProperty("projectId");
59+
expect(createAccessList.inputSchema.properties).toHaveProperty("ipAddresses");
60+
expect(createAccessList.inputSchema.properties).toHaveProperty("cidrBlocks");
61+
expect(createAccessList.inputSchema.properties).toHaveProperty("currentIpAddress");
62+
expect(createAccessList.inputSchema.properties).toHaveProperty("comment");
63+
});
64+
65+
it("should create an access list", async () => {
66+
const projectId = getProjectId();
67+
68+
const response = (await integration.mcpClient().callTool({
69+
name: "atlas-create-access-list",
70+
arguments: {
71+
projectId,
72+
ipAddresses: ["8.8.8.8"],
73+
cidrBlocks: ["9.9.9.9/24"],
74+
currentIpAddress: true,
75+
},
76+
})) as CallToolResult;
77+
expect(response.content).toBeArray();
78+
expect(response.content).toHaveLength(1);
79+
expect(response.content[0].text).toContain("IP/CIDR ranges added to access list");
80+
});
81+
});
82+
83+
describe("atlas-inspect-access-list", () => {
84+
it("should have correct metadata", async () => {
85+
const { tools } = await integration.mcpClient().listTools();
86+
const inspectAccessList = tools.find((tool) => tool.name === "atlas-inspect-access-list")!;
87+
expect(inspectAccessList).toBeDefined();
88+
expect(inspectAccessList.inputSchema.type).toBe("object");
89+
expect(inspectAccessList.inputSchema.properties).toBeDefined();
90+
expect(inspectAccessList.inputSchema.properties).toHaveProperty("projectId");
91+
});
92+
93+
it("returns access list data", async () => {
94+
const projectId = getProjectId();
95+
96+
const response = (await integration
97+
.mcpClient()
98+
.callTool({ name: "atlas-inspect-access-list", arguments: { projectId } })) as CallToolResult;
99+
expect(response.content).toBeArray();
100+
expect(response.content).toHaveLength(1);
101+
expect(response.content[0].text).toContain("8.8.8.8");
102+
expect(response.content[0].text).toContain("9.9.9.9/24");
103+
expect(response.content[0].text).toContain(ipInfo.currentIpv4Address);
104+
});
105+
});
106+
});
107+
});

0 commit comments

Comments
 (0)