|
| 1 | +import { beforeEach } from "vitest"; |
| 2 | +import { |
| 3 | + defaultDriverOptions, |
| 4 | + defaultTestConfig, |
| 5 | + expectDefined, |
| 6 | + getResponseElements, |
| 7 | + setupIntegrationTest, |
| 8 | + validateToolMetadata, |
| 9 | + waitUntilMcpClientIsSet, |
| 10 | +} from "../../helpers.js"; |
| 11 | +import { afterEach, describe, expect, it } from "vitest"; |
| 12 | + |
| 13 | +const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true"; |
| 14 | +const integration = setupIntegrationTest( |
| 15 | + () => defaultTestConfig, |
| 16 | + () => defaultDriverOptions |
| 17 | +); |
| 18 | + |
| 19 | +// Docker is not available on macOS in GitHub Actions |
| 20 | +// That's why we skip the tests on macOS in GitHub Actions |
| 21 | +describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment", () => { |
| 22 | + beforeEach(async ({ signal }) => { |
| 23 | + await waitUntilMcpClientIsSet(integration.mcpServer(), signal); |
| 24 | + }); |
| 25 | + |
| 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 | + ]); |
| 34 | + |
| 35 | + it("should have the atlas-local-connect-deployment tool", async () => { |
| 36 | + const { tools } = await integration.mcpClient().listTools(); |
| 37 | + const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment"); |
| 38 | + expectDefined(connectDeployment); |
| 39 | + }); |
| 40 | + |
| 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 | +}); |
| 54 | + |
| 55 | +describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with deployments", () => { |
| 56 | + let deploymentName: string = ""; |
| 57 | + let deploymentNamesToCleanup: string[] = []; |
| 58 | + |
| 59 | + beforeEach(async ({ signal }) => { |
| 60 | + await waitUntilMcpClientIsSet(integration.mcpServer(), signal); |
| 61 | + |
| 62 | + // Create deployments |
| 63 | + deploymentName = `test-deployment-1-${Date.now()}`; |
| 64 | + deploymentNamesToCleanup.push(deploymentName); |
| 65 | + await integration.mcpClient().callTool({ |
| 66 | + name: "atlas-local-create-deployment", |
| 67 | + arguments: { deploymentName }, |
| 68 | + }); |
| 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 | + // Connect to the deployment |
| 95 | + const response = await integration.mcpClient().callTool({ |
| 96 | + name: "atlas-local-connect-deployment", |
| 97 | + arguments: { deploymentName }, |
| 98 | + }); |
| 99 | + const elements = getResponseElements(response.content); |
| 100 | + expect(elements.length).toBeGreaterThanOrEqual(1); |
| 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(); |
| 113 | + }); |
| 114 | +}); |
0 commit comments