Skip to content

Commit 6bf04ce

Browse files
committed
restructures test
1 parent a169d63 commit 6bf04ce

File tree

1 file changed

+74
-65
lines changed

1 file changed

+74
-65
lines changed
Lines changed: 74 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,114 @@
1+
import { beforeEach } from "vitest";
12
import {
23
defaultDriverOptions,
34
defaultTestConfig,
45
expectDefined,
56
getResponseElements,
67
setupIntegrationTest,
8+
validateToolMetadata,
79
waitUntilMcpClientIsSet,
810
} from "../../helpers.js";
911
import { afterEach, describe, expect, it } from "vitest";
1012

1113
const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true";
14+
const integration = setupIntegrationTest(
15+
() => defaultTestConfig,
16+
() => defaultDriverOptions
17+
);
1218

1319
// Docker is not available on macOS in GitHub Actions
1420
// That's why we skip the tests on macOS in GitHub Actions
15-
describe("atlas-local-connect-deployment", () => {
16-
let deploymentNamesToCleanup: string[] = [];
17-
18-
afterEach(async () => {
19-
// Clean up any deployments created during the test
20-
for (const deploymentName of deploymentNamesToCleanup) {
21-
try {
22-
await integration.mcpClient().callTool({
23-
name: "atlas-local-delete-deployment",
24-
arguments: { deploymentName },
25-
});
26-
} catch (error) {
27-
console.warn(`Failed to delete deployment ${deploymentName}:`, error);
28-
}
29-
}
30-
deploymentNamesToCleanup = [];
31-
});
32-
const integration = setupIntegrationTest(
33-
() => defaultTestConfig,
34-
() => defaultDriverOptions
35-
);
36-
37-
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-connect-deployment tool", async ({ signal }) => {
21+
describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment", () => {
22+
beforeEach(async ({ signal }) => {
3823
await waitUntilMcpClientIsSet(integration.mcpServer(), signal);
39-
40-
const { tools } = await integration.mcpClient().listTools();
41-
const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment");
42-
expectDefined(connectDeployment);
4324
});
4425

45-
it.skipIf(!isMacOSInGitHubActions)(
46-
"[MacOS in GitHub Actions] should not have the atlas-local-connect-deployment tool",
47-
async ({ signal }) => {
48-
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
49-
await expect(waitUntilMcpClientIsSet(integration.mcpServer(), signal)).rejects.toThrow();
50-
51-
const { tools } = await integration.mcpClient().listTools();
52-
const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment");
53-
expect(connectDeployment).toBeUndefined();
54-
}
55-
);
26+
validateToolMetadata(integration, "atlas-local-connect-deployment", "Connect to a MongoDB Atlas Local deployment", [
27+
{
28+
name: "deploymentName",
29+
type: "string",
30+
description: "Name of the deployment to connect to",
31+
required: true,
32+
},
33+
]);
5634

57-
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async ({ signal }) => {
58-
await waitUntilMcpClientIsSet(integration.mcpServer(), signal);
35+
it("should have the atlas-local-connect-deployment tool", async () => {
5936
const { tools } = await integration.mcpClient().listTools();
6037
const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment");
6138
expectDefined(connectDeployment);
62-
expect(connectDeployment.inputSchema.type).toBe("object");
63-
expectDefined(connectDeployment.inputSchema.properties);
64-
expect(connectDeployment.inputSchema.properties).toHaveProperty("deploymentIdOrName");
6539
});
6640

67-
it.skipIf(isMacOSInGitHubActions)(
68-
"should return 'no such container' error when connecting to non-existent deployment",
69-
async ({ signal }) => {
70-
await waitUntilMcpClientIsSet(integration.mcpServer(), signal);
41+
it("should return 'no such container' error when connecting to non-existent deployment", async () => {
42+
const deploymentName = "non-existent";
43+
const response = await integration.mcpClient().callTool({
44+
name: "atlas-local-connect-deployment",
45+
arguments: { deploymentName },
46+
});
47+
const elements = getResponseElements(response.content);
48+
expect(elements.length).toBeGreaterThanOrEqual(1);
49+
expect(elements[0]?.text).toContain(
50+
`The Atlas Local deployment "${deploymentName}" was not found. Please check the deployment name or use "atlas-local-list-deployments" to see available deployments.`
51+
);
52+
});
53+
});
7154

72-
const response = await integration.mcpClient().callTool({
73-
name: "atlas-local-connect-deployment",
74-
arguments: { deploymentIdOrName: "non-existent" },
75-
});
76-
const elements = getResponseElements(response.content);
77-
expect(elements.length).toBeGreaterThanOrEqual(1);
78-
expect(elements[0]?.text).toContain(
79-
"Docker responded with status code 404: No such container: non-existent"
80-
);
81-
}
82-
);
55+
describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with deployments", () => {
56+
let deploymentName: string = "";
57+
let deploymentNamesToCleanup: string[] = [];
8358

84-
it.skipIf(isMacOSInGitHubActions)("should connect to a deployment when calling the tool", async ({ signal }) => {
59+
beforeEach(async ({ signal }) => {
8560
await waitUntilMcpClientIsSet(integration.mcpServer(), signal);
86-
// Create a deployment
87-
const deploymentName = `test-deployment-${Date.now()}`;
61+
62+
// Create deployments
63+
deploymentName = `test-deployment-1-${Date.now()}`;
8864
deploymentNamesToCleanup.push(deploymentName);
8965
await integration.mcpClient().callTool({
9066
name: "atlas-local-create-deployment",
9167
arguments: { deploymentName },
9268
});
9369

70+
const anotherDeploymentName = `test-deployment-2-${Date.now()}`;
71+
deploymentNamesToCleanup.push(anotherDeploymentName);
72+
await integration.mcpClient().callTool({
73+
name: "atlas-local-create-deployment",
74+
arguments: { deploymentName: anotherDeploymentName },
75+
});
76+
});
77+
78+
afterEach(async () => {
79+
// Delete all created deployments
80+
for (const deploymentNameToCleanup of deploymentNamesToCleanup) {
81+
try {
82+
await integration.mcpClient().callTool({
83+
name: "atlas-local-delete-deployment",
84+
arguments: { deploymentName: deploymentNameToCleanup },
85+
});
86+
} catch (error) {
87+
console.warn(`Failed to delete deployment ${deploymentNameToCleanup}:`, error);
88+
}
89+
}
90+
deploymentNamesToCleanup = [];
91+
});
92+
93+
it("should connect to correct deployment when calling the tool", async () => {
9494
// Connect to the deployment
9595
const response = await integration.mcpClient().callTool({
9696
name: "atlas-local-connect-deployment",
97-
arguments: { deploymentIdOrName: deploymentName },
97+
arguments: { deploymentName },
9898
});
9999
const elements = getResponseElements(response.content);
100100
expect(elements.length).toBeGreaterThanOrEqual(1);
101-
expect(elements[0]?.text).toContain(
102-
'Successfully connected to Atlas Local deployment "' + deploymentName + '".'
103-
);
101+
expect(elements[0]?.text).toContain(`Successfully connected to Atlas Local deployment "${deploymentName}".`);
102+
});
103+
});
104+
105+
describe.skipIf(!isMacOSInGitHubActions)("atlas-local-connect-deployment [MacOS in GitHub Actions]", () => {
106+
it("should not have the atlas-local-connect-deployment tool", async ({ signal }) => {
107+
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
108+
await expect(waitUntilMcpClientIsSet(integration.mcpServer(), signal)).rejects.toThrow();
109+
110+
const { tools } = await integration.mcpClient().listTools();
111+
const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment");
112+
expect(connectDeployment).toBeUndefined();
104113
});
105114
});

0 commit comments

Comments
 (0)