Skip to content

Commit 5ae9405

Browse files
addressed test comments
1 parent 04e505c commit 5ae9405

File tree

5 files changed

+166
-135
lines changed

5 files changed

+166
-135
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
defaultDriverOptions,
3+
defaultTestConfig,
4+
setupIntegrationTest,
5+
type IntegrationTest,
6+
} from "../../helpers.js";
7+
import { describe } from "vitest";
8+
9+
const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true";
10+
11+
export type IntegrationTestFunction = (integration: IntegrationTest) => void;
12+
13+
/**
14+
* Helper function to setup integration tests for Atlas Local tools.
15+
* Automatically skips tests on macOS in GitHub Actions where Docker is not available.
16+
*/
17+
export function describeWithAtlasLocal(name: string, fn: IntegrationTestFunction): void {
18+
describe.skipIf(isMacOSInGitHubActions)(name, () => {
19+
const integration = setupIntegrationTest(
20+
() => defaultTestConfig,
21+
() => defaultDriverOptions
22+
);
23+
fn(integration);
24+
});
25+
}
26+
27+
/**
28+
* Helper function to describe tests that should only run on macOS in GitHub Actions.
29+
* Used for testing that Atlas Local tools are properly disabled on unsupported platforms.
30+
*/
31+
export function describeWithAtlasLocalDisabled(name: string, fn: IntegrationTestFunction): void {
32+
describe.skipIf(!isMacOSInGitHubActions)(name, () => {
33+
const integration = setupIntegrationTest(
34+
() => defaultTestConfig,
35+
() => defaultDriverOptions
36+
);
37+
fn(integration);
38+
});
39+
}
40+

tests/integration/tools/atlas-local/connectDeployment.test.ts

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
import { beforeEach } from "vitest";
1+
import { expect, it, beforeAll, afterAll } from "vitest";
22
import {
3-
defaultDriverOptions,
4-
defaultTestConfig,
53
expectDefined,
64
getResponseElements,
7-
setupIntegrationTest,
85
validateToolMetadata,
96
} from "../../helpers.js";
10-
import { afterEach, describe, expect, it } from "vitest";
7+
import { describeWithAtlasLocal, describeWithAtlasLocalDisabled } from "./atlasLocalHelpers.js";
118

12-
const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true";
13-
const integration = setupIntegrationTest(
14-
() => defaultTestConfig,
15-
() => defaultDriverOptions
16-
);
17-
18-
// Docker is not available on macOS in GitHub Actions
19-
// That's why we skip the tests on macOS in GitHub Actions
20-
describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment", () => {
9+
describeWithAtlasLocal("atlas-local-connect-deployment", (integration) => {
2110
validateToolMetadata(integration, "atlas-local-connect-deployment", "Connect to a MongoDB Atlas Local deployment", [
2211
{
2312
name: "deploymentName",
@@ -47,11 +36,11 @@ describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment", () =>
4736
});
4837
});
4938

50-
describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with deployments", () => {
39+
describeWithAtlasLocal("atlas-local-connect-deployment with deployments", (integration) => {
5140
let deploymentName: string = "";
5241
let deploymentNamesToCleanup: string[] = [];
5342

54-
beforeEach(async () => {
43+
beforeAll(async () => {
5544
// Create deployments
5645
deploymentName = `test-deployment-1-${Date.now()}`;
5746
deploymentNamesToCleanup.push(deploymentName);
@@ -68,7 +57,7 @@ describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with dep
6857
});
6958
});
7059

71-
afterEach(async () => {
60+
afterAll(async () => {
7261
// Delete all created deployments
7362
for (const deploymentNameToCleanup of deploymentNamesToCleanup) {
7463
try {
@@ -93,9 +82,51 @@ describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with dep
9382
expect(elements.length).toBeGreaterThanOrEqual(1);
9483
expect(elements[0]?.text).toContain(`Successfully connected to Atlas Local deployment "${deploymentName}".`);
9584
});
85+
86+
it("should be able to insert and read data after connecting", async () => {
87+
// Connect to the deployment
88+
await integration.mcpClient().callTool({
89+
name: "atlas-local-connect-deployment",
90+
arguments: { deploymentName },
91+
});
92+
93+
const testDatabase = "test-db";
94+
const testCollection = "test-collection";
95+
const testData = [
96+
{ name: "document1", value: 1 },
97+
{ name: "document2", value: 2 },
98+
];
99+
100+
// Insert data using insert-many tool
101+
const insertResponse = await integration.mcpClient().callTool({
102+
name: "insert-many",
103+
arguments: {
104+
database: testDatabase,
105+
collection: testCollection,
106+
documents: testData,
107+
},
108+
});
109+
const insertElements = getResponseElements(insertResponse.content);
110+
expect(insertElements.length).toBeGreaterThanOrEqual(1);
111+
expect(insertElements[0]?.text).toContain("Documents were inserted successfully.");
112+
113+
// Read data using find tool
114+
const findResponse = await integration.mcpClient().callTool({
115+
name: "find",
116+
arguments: {
117+
database: testDatabase,
118+
collection: testCollection,
119+
},
120+
});
121+
const findElements = getResponseElements(findResponse.content);
122+
expect(findElements.length).toBe(2);
123+
expect(findElements[0]?.text).toBe("Query on collection \"test-collection\" resulted in 2 documents. Returning 2 documents.");
124+
expect(findElements[1]?.text).toContain("document1");
125+
expect(findElements[1]?.text).toContain("document2");
126+
});
96127
});
97128

98-
describe.skipIf(!isMacOSInGitHubActions)("atlas-local-connect-deployment [MacOS in GitHub Actions]", () => {
129+
describeWithAtlasLocalDisabled("atlas-local-connect-deployment [MacOS in GitHub Actions]", (integration) => {
99130
it("should not have the atlas-local-connect-deployment tool", async () => {
100131
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
101132
const { tools } = await integration.mcpClient().listTools();

tests/integration/tools/atlas-local/createDeployment.test.ts

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import {
2-
defaultDriverOptions,
3-
defaultTestConfig,
42
expectDefined,
53
getResponseElements,
6-
setupIntegrationTest,
74
} from "../../helpers.js";
8-
import { afterEach, describe, expect, it } from "vitest";
5+
import { afterEach, expect, it } from "vitest";
6+
import { describeWithAtlasLocal, describeWithAtlasLocalDisabled } from "./atlasLocalHelpers.js";
97

10-
const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true";
11-
12-
// Docker is not available on macOS in GitHub Actions
13-
// That's why we skip the tests on macOS in GitHub Actions
14-
describe("atlas-local-create-deployment", () => {
8+
describeWithAtlasLocal("atlas-local-create-deployment", (integration) => {
159
let deploymentNamesToCleanup: string[] = [];
1610

1711
afterEach(async () => {
@@ -28,27 +22,14 @@ describe("atlas-local-create-deployment", () => {
2822
}
2923
deploymentNamesToCleanup = [];
3024
});
31-
const integration = setupIntegrationTest(
32-
() => defaultTestConfig,
33-
() => defaultDriverOptions
34-
);
3525

36-
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-create-deployment tool", async () => {
26+
it("should have the atlas-local-create-deployment tool", async () => {
3727
const { tools } = await integration.mcpClient().listTools();
3828
const createDeployment = tools.find((tool) => tool.name === "atlas-local-create-deployment");
3929
expectDefined(createDeployment);
4030
});
4131

42-
it.skipIf(!isMacOSInGitHubActions)(
43-
"[MacOS in GitHub Actions] should not have the atlas-local-create-deployment tool",
44-
async () => {
45-
const { tools } = await integration.mcpClient().listTools();
46-
const createDeployment = tools.find((tool) => tool.name === "atlas-local-create-deployment");
47-
expect(createDeployment).toBeUndefined();
48-
}
49-
);
50-
51-
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async () => {
32+
it("should have correct metadata", async () => {
5233
const { tools } = await integration.mcpClient().listTools();
5334
const createDeployment = tools.find((tool) => tool.name === "atlas-local-create-deployment");
5435
expectDefined(createDeployment);
@@ -57,7 +38,7 @@ describe("atlas-local-create-deployment", () => {
5738
expect(createDeployment.inputSchema.properties).toHaveProperty("deploymentName");
5839
});
5940

60-
it.skipIf(isMacOSInGitHubActions)("should create a deployment when calling the tool", async () => {
41+
it("should create a deployment when calling the tool", async () => {
6142
const deploymentName = `test-deployment-${Date.now()}`;
6243

6344
// Check that deployment doesn't exist before creation
@@ -83,33 +64,31 @@ describe("atlas-local-create-deployment", () => {
8364
});
8465

8566
const afterElements = getResponseElements(afterResponse.content);
86-
expect(afterElements.length).toBeGreaterThanOrEqual(1);
67+
expect(afterElements).toHaveLength(2);
8768
expect(afterElements[1]?.text ?? "").toContain(deploymentName);
8869
});
8970

90-
it.skipIf(isMacOSInGitHubActions)(
91-
"should return an error when creating a deployment that already exists",
92-
async () => {
93-
// Create a deployment
94-
const deploymentName = `test-deployment-${Date.now()}`;
95-
deploymentNamesToCleanup.push(deploymentName);
96-
await integration.mcpClient().callTool({
97-
name: "atlas-local-create-deployment",
98-
arguments: { deploymentName },
99-
});
100-
101-
// Try to create the same deployment again
102-
const response = await integration.mcpClient().callTool({
103-
name: "atlas-local-create-deployment",
104-
arguments: { deploymentName },
105-
});
106-
const elements = getResponseElements(response.content);
107-
expect(elements.length).toBeGreaterThanOrEqual(1);
108-
expect(elements[0]?.text).toContain("Container already exists: " + deploymentName);
109-
}
110-
);
71+
it("should return an error when creating a deployment that already exists", async () => {
72+
// Create a deployment
73+
const deploymentName = `test-deployment-${Date.now()}`;
74+
deploymentNamesToCleanup.push(deploymentName);
75+
await integration.mcpClient().callTool({
76+
name: "atlas-local-create-deployment",
77+
arguments: { deploymentName },
78+
});
11179

112-
it.skipIf(isMacOSInGitHubActions)("should create a deployment with the correct name", async () => {
80+
// Try to create the same deployment again
81+
const response = await integration.mcpClient().callTool({
82+
name: "atlas-local-create-deployment",
83+
arguments: { deploymentName },
84+
});
85+
expect(response.isError).toBe(true);
86+
const elements = getResponseElements(response.content);
87+
expect(elements).toHaveLength(1);
88+
expect(elements[0]?.text).toContain("Container already exists: " + deploymentName);
89+
});
90+
91+
it("should create a deployment with the correct name", async () => {
11392
// Create a deployment
11493
const deploymentName = `test-deployment-${Date.now()}`;
11594
deploymentNamesToCleanup.push(deploymentName);
@@ -135,7 +114,7 @@ describe("atlas-local-create-deployment", () => {
135114
expect(elements[1]?.text ?? "").toContain("Running");
136115
});
137116

138-
it.skipIf(isMacOSInGitHubActions)("should create a deployment when name is not provided", async () => {
117+
it("should create a deployment when name is not provided", async () => {
139118
// Create a deployment
140119
const createResponse = await integration.mcpClient().callTool({
141120
name: "atlas-local-create-deployment",
@@ -165,3 +144,11 @@ describe("atlas-local-create-deployment", () => {
165144
expect(elements[1]?.text ?? "").toContain("Running");
166145
});
167146
});
147+
148+
describeWithAtlasLocalDisabled("[MacOS in GitHub Actions] atlas-local-create-deployment", (integration) => {
149+
it("should not have the atlas-local-create-deployment tool", async () => {
150+
const { tools } = await integration.mcpClient().listTools();
151+
const createDeployment = tools.find((tool) => tool.name === "atlas-local-create-deployment");
152+
expect(createDeployment).toBeUndefined();
153+
});
154+
});
Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
11
import {
2-
defaultDriverOptions,
3-
defaultTestConfig,
42
expectDefined,
53
getResponseElements,
6-
setupIntegrationTest,
74
} from "../../helpers.js";
8-
import { describe, expect, it } from "vitest";
5+
import { expect, it } from "vitest";
6+
import { describeWithAtlasLocal, describeWithAtlasLocalDisabled } from "./atlasLocalHelpers.js";
97

10-
const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true";
11-
12-
// Docker is not available on macOS in GitHub Actions
13-
// That's why we skip the tests on macOS in GitHub Actions
14-
describe("atlas-local-delete-deployment", () => {
15-
const integration = setupIntegrationTest(
16-
() => defaultTestConfig,
17-
() => defaultDriverOptions
18-
);
19-
20-
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-delete-deployment tool", async () => {
8+
describeWithAtlasLocal("atlas-local-delete-deployment", (integration) => {
9+
it("should have the atlas-local-delete-deployment tool", async () => {
2110
const { tools } = await integration.mcpClient().listTools();
2211
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
2312
expectDefined(deleteDeployment);
2413
});
2514

26-
it.skipIf(!isMacOSInGitHubActions)(
27-
"[MacOS in GitHub Actions] should not have the atlas-local-delete-deployment tool",
28-
async () => {
29-
const { tools } = await integration.mcpClient().listTools();
30-
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
31-
expect(deleteDeployment).toBeUndefined();
32-
}
33-
);
34-
35-
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async () => {
15+
it("should have correct metadata", async () => {
3616
const { tools } = await integration.mcpClient().listTools();
3717
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
3818
expectDefined(deleteDeployment);
@@ -41,24 +21,21 @@ describe("atlas-local-delete-deployment", () => {
4121
expect(deleteDeployment.inputSchema.properties).toHaveProperty("deploymentName");
4222
});
4323

44-
it.skipIf(isMacOSInGitHubActions)(
45-
"should return 'no such container' error when deployment to delete does not exist",
46-
async () => {
47-
const deploymentName = "non-existent";
24+
it("should return 'no such container' error when deployment to delete does not exist", async () => {
25+
const deploymentName = "non-existent";
4826

49-
const response = await integration.mcpClient().callTool({
50-
name: "atlas-local-delete-deployment",
51-
arguments: { deploymentName },
52-
});
53-
const elements = getResponseElements(response.content);
54-
expect(elements.length).toBeGreaterThanOrEqual(1);
55-
expect(elements[0]?.text).toContain(
56-
`The Atlas Local deployment "${deploymentName}" was not found. Please check the deployment name or use "atlas-local-list-deployments" to see available deployments.`
57-
);
58-
}
59-
);
27+
const response = await integration.mcpClient().callTool({
28+
name: "atlas-local-delete-deployment",
29+
arguments: { deploymentName },
30+
});
31+
const elements = getResponseElements(response.content);
32+
expect(elements.length).toBeGreaterThanOrEqual(1);
33+
expect(elements[0]?.text).toContain(
34+
`The Atlas Local deployment "${deploymentName}" was not found. Please check the deployment name or use "atlas-local-list-deployments" to see available deployments.`
35+
);
36+
});
6037

61-
it.skipIf(isMacOSInGitHubActions)("should delete a deployment when calling the tool", async () => {
38+
it("should delete a deployment when calling the tool", async () => {
6239
// Create a deployment
6340
const deploymentName = `test-deployment-${Date.now()}`;
6441
await integration.mcpClient().callTool({
@@ -81,7 +58,7 @@ describe("atlas-local-delete-deployment", () => {
8158
arguments: { deploymentName },
8259
});
8360

84-
// Count the number of deployments after deleting the deployment
61+
// Check that deployment doesn't exist after deletion
8562
const afterResponse = await integration.mcpClient().callTool({
8663
name: "atlas-local-list-deployments",
8764
arguments: {},
@@ -90,3 +67,11 @@ describe("atlas-local-delete-deployment", () => {
9067
expect(afterElements[1]?.text ?? "").not.toContain(deploymentName);
9168
});
9269
});
70+
71+
describeWithAtlasLocalDisabled("[MacOS in GitHub Actions] atlas-local-delete-deployment", (integration) => {
72+
it("should not have the atlas-local-delete-deployment tool", async () => {
73+
const { tools } = await integration.mcpClient().listTools();
74+
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
75+
expect(deleteDeployment).toBeUndefined();
76+
});
77+
});

0 commit comments

Comments
 (0)