Skip to content

Commit 18fe549

Browse files
authored
chore: reduce cleanup time (#652)
1 parent a7720fe commit 18fe549

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

scripts/cleanupAtlasTestLeftovers.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { ConsoleLogger } from "../src/common/logger.js";
44
import { Keychain } from "../src/lib.js";
55
import { describe, it } from "vitest";
66

7-
function isOlderThanADay(date: string): boolean {
8-
const oneDayInMs = 24 * 60 * 60 * 1000;
7+
function isOlderThanTwoHours(date: string): boolean {
8+
const twoHoursInMs = 2 * 60 * 60 * 1000;
99
const projectDate = new Date(date);
1010
const currentDate = new Date();
11-
return currentDate.getTime() - projectDate.getTime() > oneDayInMs;
11+
return currentDate.getTime() - projectDate.getTime() > twoHoursInMs;
1212
}
1313

1414
async function findTestOrganization(client: ApiClient): Promise<AtlasOrganization> {
@@ -32,7 +32,7 @@ async function findAllTestProjects(client: ApiClient, orgId: string): Promise<Gr
3232
});
3333

3434
const testProjects = projects?.results?.filter((proj) => proj.name.startsWith("testProj-")) || [];
35-
return testProjects.filter((proj) => isOlderThanADay(proj.created));
35+
return testProjects.filter((proj) => isOlderThanTwoHours(proj.created));
3636
}
3737

3838
async function deleteAllClustersOnStaleProject(client: ApiClient, projectId: string): Promise<string[]> {
@@ -76,8 +76,11 @@ async function main(): Promise<void> {
7676
);
7777

7878
const testOrg = await findTestOrganization(apiClient);
79-
const testProjects = await findAllTestProjects(apiClient, testOrg.id || "");
79+
if (!testOrg.id) {
80+
throw new Error("Test organization ID not found.");
81+
}
8082

83+
const testProjects = await findAllTestProjects(apiClient, testOrg.id);
8184
if (testProjects.length === 0) {
8285
console.log("No stale test projects found for cleanup.");
8386
return;

tests/integration/tools/atlas/atlasHelpers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export function describeWithAtlas(name: string, fn: IntegrationTestFunction): vo
1818
const integration = setupIntegrationTest(
1919
() => ({
2020
...defaultTestConfig,
21-
apiClientId: process.env.MDB_MCP_API_CLIENT_ID,
22-
apiClientSecret: process.env.MDB_MCP_API_CLIENT_SECRET,
21+
apiClientId: process.env.MDB_MCP_API_CLIENT_ID || "test-client",
22+
apiClientSecret: process.env.MDB_MCP_API_CLIENT_SECRET || "test-secret",
2323
apiBaseUrl: process.env.MDB_MCP_API_BASE_URL ?? "https://cloud-dev.mongodb.com",
2424
}),
2525
() => defaultDriverOptions
@@ -35,6 +35,16 @@ interface ProjectTestArgs {
3535

3636
type ProjectTestFunction = (args: ProjectTestArgs) => void;
3737

38+
export function withCredentials(integration: IntegrationTest, fn: IntegrationTestFunction): SuiteCollector<object> {
39+
const describeFn =
40+
!process.env.MDB_MCP_API_CLIENT_ID?.length || !process.env.MDB_MCP_API_CLIENT_SECRET?.length
41+
? describe.skip
42+
: describe;
43+
return describeFn("with credentials", () => {
44+
fn(integration);
45+
});
46+
}
47+
3848
export function withProject(integration: IntegrationTest, fn: ProjectTestFunction): SuiteCollector<object> {
3949
return describe("with project", () => {
4050
let projectId: string = "";
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js";
2-
import { parseTable, describeWithAtlas } from "./atlasHelpers.js";
2+
import { parseTable, describeWithAtlas, withCredentials } from "./atlasHelpers.js";
33
import { describe, expect, it } from "vitest";
44

55
describeWithAtlas("orgs", (integration) => {
6-
describe("atlas-list-orgs", () => {
7-
it("should have correct metadata", async () => {
8-
const { tools } = await integration.mcpClient().listTools();
9-
const listOrgs = tools.find((tool) => tool.name === "atlas-list-orgs");
10-
expectDefined(listOrgs);
11-
});
6+
withCredentials(integration, () => {
7+
describe("atlas-list-orgs", () => {
8+
it("should have correct metadata", async () => {
9+
const { tools } = await integration.mcpClient().listTools();
10+
const listOrgs = tools.find((tool) => tool.name === "atlas-list-orgs");
11+
expectDefined(listOrgs);
12+
});
1213

13-
it("returns org names", async () => {
14-
const response = await integration.mcpClient().callTool({ name: "atlas-list-orgs", arguments: {} });
15-
const elements = getResponseElements(response);
16-
expect(elements[0]?.text).toContain("Found 1 organizations");
17-
expect(elements[1]?.text).toContain("<untrusted-user-data-");
18-
const data = parseTable(getDataFromUntrustedContent(elements[1]?.text ?? ""));
19-
expect(data).toHaveLength(1);
20-
expect(data[0]?.["Organization Name"]).toEqual("MongoDB MCP Test");
14+
it("returns org names", async () => {
15+
const response = await integration.mcpClient().callTool({ name: "atlas-list-orgs", arguments: {} });
16+
const elements = getResponseElements(response);
17+
expect(elements[0]?.text).toContain("Found 1 organizations");
18+
expect(elements[1]?.text).toContain("<untrusted-user-data-");
19+
const data = parseTable(getDataFromUntrustedContent(elements[1]?.text ?? ""));
20+
expect(data).toHaveLength(1);
21+
expect(data[0]?.["Organization Name"]).toEqual("MongoDB MCP Test");
22+
});
2123
});
2224
});
2325
});

0 commit comments

Comments
 (0)