Skip to content

Commit aedcdfd

Browse files
committed
update tests
1 parent 2d00859 commit aedcdfd

File tree

5 files changed

+110
-8
lines changed

5 files changed

+110
-8
lines changed

tests/integration/helpers.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ export const projectIdParameters: ParameterInfo[] = [
249249
];
250250

251251
export const createClusterParameters: ParameterInfo[] = [
252-
{ name: "name", type: "string", description: "Name of the cluster", required: true },
253-
{ name: "projectId", type: "string", description: "Atlas project ID to create the cluster in", required: true },
252+
{ name: "projectId", type: "string", description: "Atlas project ID", required: true },
253+
{ name: "clusterName", type: "string", description: "Atlas cluster name", required: true },
254254
{ name: "region", type: "string", description: "Region of the cluster", required: false },
255255
];
256256

@@ -272,6 +272,45 @@ export const projectIdInvalidArgs = [
272272
{ projectId: "invalid-test-project-id" },
273273
];
274274

275+
export const clusterNameInvalidArgs = [
276+
{ clusterName: 123 },
277+
{ clusterName: [] },
278+
{ clusterName: "!✅invalid" },
279+
{ clusterName: "a".repeat(65) }, // too long
280+
];
281+
282+
export const projectAndClusterInvalidArgs = [
283+
{},
284+
{ projectId: "507f1f77bcf86cd799439011" }, // missing clusterName
285+
{ clusterName: "testCluster" }, // missing projectId
286+
{ projectId: 123, clusterName: "testCluster" },
287+
{ projectId: "507f1f77bcf86cd799439011", clusterName: 123 },
288+
{ projectId: "invalid", clusterName: "testCluster" },
289+
{ projectId: "507f1f77bcf86cd799439011", clusterName: "!✅invalid" },
290+
];
291+
292+
export const organizationIdInvalidArgs = [
293+
{ organizationId: 123 },
294+
{ organizationId: [] },
295+
{ organizationId: "!✅invalid" },
296+
{ organizationId: "invalid-test-org-id" },
297+
];
298+
299+
export const orgIdInvalidArgs = [
300+
{ orgId: 123 },
301+
{ orgId: [] },
302+
{ orgId: "!✅invalid" },
303+
{ orgId: "invalid-test-org-id" },
304+
];
305+
306+
export const usernameInvalidArgs = [
307+
{},
308+
{ username: 123 },
309+
{ username: [] },
310+
{ username: "!✅invalid" },
311+
{ username: "a".repeat(101) }, // too long
312+
];
313+
275314
export const databaseInvalidArgs = [{}, { database: 123 }, { database: [] }];
276315

277316
export function validateToolMetadata(

tests/integration/tools/atlas/accessLists.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { describeWithAtlas, withProject } from "./atlasHelpers.js";
2-
import { expectDefined, getResponseElements } from "../../helpers.js";
2+
import {
3+
expectDefined,
4+
getResponseElements,
5+
projectIdInvalidArgs,
6+
validateThrowsForInvalidArguments,
7+
validateToolMetadata,
8+
} from "../../helpers.js";
39
import { afterAll, beforeAll, describe, expect, it } from "vitest";
410
import { ensureCurrentIpInAccessList } from "../../../../src/common/atlas/accessListUtils.js";
511

@@ -12,6 +18,25 @@ function generateRandomIp(): string {
1218
}
1319

1420
describeWithAtlas("ip access lists", (integration) => {
21+
describe("should have correct metadata and validate invalid arguments", () => {
22+
validateToolMetadata(
23+
integration,
24+
"atlas-inspect-access-list",
25+
"Inspect Ip/CIDR ranges with access to your MongoDB Atlas clusters.",
26+
[
27+
{
28+
name: "projectId",
29+
type: "string",
30+
description: "Atlas project ID",
31+
required: true,
32+
},
33+
]
34+
);
35+
36+
validateThrowsForInvalidArguments(integration, "atlas-inspect-access-list", projectIdInvalidArgs);
37+
validateThrowsForInvalidArguments(integration, "atlas-create-access-list", projectIdInvalidArgs);
38+
});
39+
1540
withProject(integration, ({ getProjectId }) => {
1641
const ips = [generateRandomIp(), generateRandomIp()];
1742
const cidrBlocks = [generateRandomIp() + "/16", generateRandomIp() + "/24"];

tests/integration/tools/atlas/clusters.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getResponseElements,
55
getDataFromUntrustedContent,
66
createClusterParameters,
7-
projectIdInvalidArgs,
7+
projectAndClusterInvalidArgs,
88
validateThrowsForInvalidArguments,
99
validateToolMetadata,
1010
} from "../../helpers.js";
@@ -84,7 +84,7 @@ describeWithAtlas("clusters", (integration) => {
8484
);
8585

8686
expect(() => {
87-
validateThrowsForInvalidArguments(integration, "atlas-create-free-cluster", projectIdInvalidArgs);
87+
validateThrowsForInvalidArguments(integration, "atlas-create-free-cluster", projectAndClusterInvalidArgs);
8888
}).not.toThrow();
8989
});
9090

tests/integration/tools/atlas/dbUsers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describeWithAtlas, withProject, randomId } from "./atlasHelpers.js";
22
import {
33
expectDefined,
44
getResponseElements,
5-
projectIdInvalidArgs,
5+
usernameInvalidArgs,
66
validateThrowsForInvalidArguments,
77
} from "../../helpers.js";
88
import { ApiClientError } from "../../../../src/common/atlas/apiClientError.js";
@@ -11,7 +11,7 @@ import { Keychain } from "../../../../src/common/keychain.js";
1111

1212
describeWithAtlas("db users", (integration) => {
1313
describe("should have correct metadata and validate invalid arguments", () => {
14-
validateThrowsForInvalidArguments(integration, "atlas-create-db-user", projectIdInvalidArgs);
14+
validateThrowsForInvalidArguments(integration, "atlas-create-db-user", usernameInvalidArgs);
1515
});
1616

1717
withProject(integration, ({ getProjectId }) => {

tests/integration/tools/atlas/projects.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
11
import { ObjectId } from "mongodb";
22
import { parseTable, describeWithAtlas, withCredentials } from "./atlasHelpers.js";
3-
import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js";
3+
import {
4+
expectDefined,
5+
getDataFromUntrustedContent,
6+
getResponseElements,
7+
organizationIdInvalidArgs,
8+
orgIdInvalidArgs,
9+
validateThrowsForInvalidArguments,
10+
validateToolMetadata,
11+
} from "../../helpers.js";
412
import { afterAll, describe, expect, it } from "vitest";
513

614
const randomId = new ObjectId().toString();
715

816
describeWithAtlas("projects", (integration) => {
17+
describe("should have correct metadata and validate invalid arguments", () => {
18+
validateToolMetadata(integration, "atlas-create-project", "Create a MongoDB Atlas project", [
19+
{
20+
name: "projectName",
21+
type: "string",
22+
description: "Name for the new project",
23+
required: false,
24+
},
25+
{
26+
name: "organizationId",
27+
type: "string",
28+
description: "Organization ID for the new project",
29+
required: false,
30+
},
31+
]);
32+
33+
validateThrowsForInvalidArguments(integration, "atlas-create-project", organizationIdInvalidArgs);
34+
35+
validateToolMetadata(integration, "atlas-list-projects", "List MongoDB Atlas projects", [
36+
{
37+
name: "orgId",
38+
type: "string",
39+
description: "Atlas organization ID to filter projects",
40+
required: false,
41+
},
42+
]);
43+
44+
validateThrowsForInvalidArguments(integration, "atlas-list-projects", orgIdInvalidArgs);
45+
});
46+
947
withCredentials(integration, () => {
1048
const projName = "testProj-" + randomId;
1149

0 commit comments

Comments
 (0)