From eefd86e3d3c3770ce46c367641dfad673141b8c2 Mon Sep 17 00:00:00 2001 From: Bianca Lisle Date: Tue, 14 Oct 2025 12:58:19 +0100 Subject: [PATCH 1/2] update testS --- scripts/cleanupAtlasTestLeftovers.test.ts | 8 ++--- tests/integration/tools/atlas/atlasHelpers.ts | 14 ++++++-- tests/integration/tools/atlas/orgs.test.ts | 32 ++++++++++--------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/scripts/cleanupAtlasTestLeftovers.test.ts b/scripts/cleanupAtlasTestLeftovers.test.ts index e7e4ffefb..4a74526e7 100644 --- a/scripts/cleanupAtlasTestLeftovers.test.ts +++ b/scripts/cleanupAtlasTestLeftovers.test.ts @@ -4,11 +4,11 @@ import { ConsoleLogger } from "../src/common/logger.js"; import { Keychain } from "../src/lib.js"; import { describe, it } from "vitest"; -function isOlderThanADay(date: string): boolean { - const oneDayInMs = 24 * 60 * 60 * 1000; +function isOlderThanTwoHours(date: string): boolean { + const twoHoursInMs = 2 * 60 * 60 * 1000; const projectDate = new Date(date); const currentDate = new Date(); - return currentDate.getTime() - projectDate.getTime() > oneDayInMs; + return currentDate.getTime() - projectDate.getTime() > twoHoursInMs; } async function findTestOrganization(client: ApiClient): Promise { @@ -32,7 +32,7 @@ async function findAllTestProjects(client: ApiClient, orgId: string): Promise proj.name.startsWith("testProj-")) || []; - return testProjects.filter((proj) => isOlderThanADay(proj.created)); + return testProjects.filter((proj) => isOlderThanTwoHours(proj.created)); } async function deleteAllClustersOnStaleProject(client: ApiClient, projectId: string): Promise { diff --git a/tests/integration/tools/atlas/atlasHelpers.ts b/tests/integration/tools/atlas/atlasHelpers.ts index a9f24cb49..2a8fce123 100644 --- a/tests/integration/tools/atlas/atlasHelpers.ts +++ b/tests/integration/tools/atlas/atlasHelpers.ts @@ -18,8 +18,8 @@ export function describeWithAtlas(name: string, fn: IntegrationTestFunction): vo const integration = setupIntegrationTest( () => ({ ...defaultTestConfig, - apiClientId: process.env.MDB_MCP_API_CLIENT_ID, - apiClientSecret: process.env.MDB_MCP_API_CLIENT_SECRET, + apiClientId: process.env.MDB_MCP_API_CLIENT_ID || "test-client", + apiClientSecret: process.env.MDB_MCP_API_CLIENT_SECRET || "test-secret", apiBaseUrl: process.env.MDB_MCP_API_BASE_URL ?? "https://cloud-dev.mongodb.com", }), () => defaultDriverOptions @@ -35,6 +35,16 @@ interface ProjectTestArgs { type ProjectTestFunction = (args: ProjectTestArgs) => void; +export function withCredentials(integration: IntegrationTest, fn: IntegrationTestFunction): SuiteCollector { + const describeFn = + !process.env.MDB_MCP_API_CLIENT_ID?.length || !process.env.MDB_MCP_API_CLIENT_SECRET?.length + ? describe.skip + : describe; + return describeFn("with credentials", () => { + fn(integration); + }); +} + export function withProject(integration: IntegrationTest, fn: ProjectTestFunction): SuiteCollector { return describe("with project", () => { let projectId: string = ""; diff --git a/tests/integration/tools/atlas/orgs.test.ts b/tests/integration/tools/atlas/orgs.test.ts index 72e0182bf..baa4f96a9 100644 --- a/tests/integration/tools/atlas/orgs.test.ts +++ b/tests/integration/tools/atlas/orgs.test.ts @@ -1,23 +1,25 @@ import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js"; -import { parseTable, describeWithAtlas } from "./atlasHelpers.js"; +import { parseTable, describeWithAtlas, withCredentials } from "./atlasHelpers.js"; import { describe, expect, it } from "vitest"; describeWithAtlas("orgs", (integration) => { - describe("atlas-list-orgs", () => { - it("should have correct metadata", async () => { - const { tools } = await integration.mcpClient().listTools(); - const listOrgs = tools.find((tool) => tool.name === "atlas-list-orgs"); - expectDefined(listOrgs); - }); + withCredentials(integration, () => { + describe("atlas-list-orgs", () => { + it("should have correct metadata", async () => { + const { tools } = await integration.mcpClient().listTools(); + const listOrgs = tools.find((tool) => tool.name === "atlas-list-orgs"); + expectDefined(listOrgs); + }); - it("returns org names", async () => { - const response = await integration.mcpClient().callTool({ name: "atlas-list-orgs", arguments: {} }); - const elements = getResponseElements(response); - expect(elements[0]?.text).toContain("Found 1 organizations"); - expect(elements[1]?.text).toContain(" { + const response = await integration.mcpClient().callTool({ name: "atlas-list-orgs", arguments: {} }); + const elements = getResponseElements(response); + expect(elements[0]?.text).toContain("Found 1 organizations"); + expect(elements[1]?.text).toContain(" Date: Tue, 14 Oct 2025 15:22:28 +0100 Subject: [PATCH 2/2] update --- scripts/cleanupAtlasTestLeftovers.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/cleanupAtlasTestLeftovers.test.ts b/scripts/cleanupAtlasTestLeftovers.test.ts index 4a74526e7..7e195d5e2 100644 --- a/scripts/cleanupAtlasTestLeftovers.test.ts +++ b/scripts/cleanupAtlasTestLeftovers.test.ts @@ -76,8 +76,11 @@ async function main(): Promise { ); const testOrg = await findTestOrganization(apiClient); - const testProjects = await findAllTestProjects(apiClient, testOrg.id || ""); + if (!testOrg.id) { + throw new Error("Test organization ID not found."); + } + const testProjects = await findAllTestProjects(apiClient, testOrg.id); if (testProjects.length === 0) { console.log("No stale test projects found for cleanup."); return;