|
| 1 | +import { beforeEach } from "vitest"; |
1 | 2 | import { |
2 | 3 | defaultDriverOptions, |
3 | 4 | defaultTestConfig, |
4 | 5 | expectDefined, |
5 | 6 | getResponseElements, |
6 | 7 | setupIntegrationTest, |
| 8 | + validateToolMetadata, |
7 | 9 | waitUntilMcpClientIsSet, |
8 | 10 | } from "../../helpers.js"; |
9 | 11 | import { afterEach, describe, expect, it } from "vitest"; |
10 | 12 |
|
11 | 13 | const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true"; |
| 14 | +const integration = setupIntegrationTest( |
| 15 | + () => defaultTestConfig, |
| 16 | + () => defaultDriverOptions |
| 17 | +); |
12 | 18 |
|
13 | 19 | // Docker is not available on macOS in GitHub Actions |
14 | 20 | // 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 }) => { |
38 | 23 | 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); |
43 | 24 | }); |
44 | 25 |
|
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 | + ]); |
56 | 34 |
|
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 () => { |
59 | 36 | const { tools } = await integration.mcpClient().listTools(); |
60 | 37 | const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment"); |
61 | 38 | expectDefined(connectDeployment); |
62 | | - expect(connectDeployment.inputSchema.type).toBe("object"); |
63 | | - expectDefined(connectDeployment.inputSchema.properties); |
64 | | - expect(connectDeployment.inputSchema.properties).toHaveProperty("deploymentIdOrName"); |
65 | 39 | }); |
66 | 40 |
|
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 | +}); |
71 | 54 |
|
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[] = []; |
83 | 58 |
|
84 | | - it.skipIf(isMacOSInGitHubActions)("should connect to a deployment when calling the tool", async ({ signal }) => { |
| 59 | + beforeEach(async ({ signal }) => { |
85 | 60 | 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()}`; |
88 | 64 | deploymentNamesToCleanup.push(deploymentName); |
89 | 65 | await integration.mcpClient().callTool({ |
90 | 66 | name: "atlas-local-create-deployment", |
91 | 67 | arguments: { deploymentName }, |
92 | 68 | }); |
93 | 69 |
|
| 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 () => { |
94 | 94 | // Connect to the deployment |
95 | 95 | const response = await integration.mcpClient().callTool({ |
96 | 96 | name: "atlas-local-connect-deployment", |
97 | | - arguments: { deploymentIdOrName: deploymentName }, |
| 97 | + arguments: { deploymentName }, |
98 | 98 | }); |
99 | 99 | const elements = getResponseElements(response.content); |
100 | 100 | 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(); |
104 | 113 | }); |
105 | 114 | }); |
0 commit comments