|
1 | 1 | import { ObjectId } from "mongodb";
|
2 |
| -import { parseTable, describeWithAtlas } from "./atlasHelpers.js"; |
| 2 | +import { parseTable, describeWithAtlas, withCredentials } from "./atlasHelpers.js"; |
3 | 3 | import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js";
|
4 | 4 | import { afterAll, describe, expect, it } from "vitest";
|
5 | 5 |
|
6 | 6 | const randomId = new ObjectId().toString();
|
7 | 7 |
|
8 | 8 | describeWithAtlas("projects", (integration) => {
|
9 |
| - const projName = "testProj-" + randomId; |
| 9 | + withCredentials(integration, () => { |
| 10 | + const projName = "testProj-" + randomId; |
10 | 11 |
|
11 |
| - afterAll(async () => { |
12 |
| - const session = integration.mcpServer().session; |
| 12 | + afterAll(async () => { |
| 13 | + const session = integration.mcpServer().session; |
13 | 14 |
|
14 |
| - const projects = await session.apiClient.listProjects(); |
15 |
| - for (const project of projects?.results || []) { |
16 |
| - if (project.name === projName) { |
17 |
| - await session.apiClient.deleteProject({ |
18 |
| - params: { |
19 |
| - path: { |
20 |
| - groupId: project.id || "", |
| 15 | + const projects = await session.apiClient.listProjects(); |
| 16 | + for (const project of projects?.results || []) { |
| 17 | + if (project.name === projName) { |
| 18 | + await session.apiClient.deleteProject({ |
| 19 | + params: { |
| 20 | + path: { |
| 21 | + groupId: project.id || "", |
| 22 | + }, |
21 | 23 | },
|
22 |
| - }, |
23 |
| - }); |
24 |
| - break; |
| 24 | + }); |
| 25 | + break; |
| 26 | + } |
25 | 27 | }
|
26 |
| - } |
27 |
| - }); |
28 |
| - |
29 |
| - describe("atlas-create-project", () => { |
30 |
| - it("should have correct metadata", async () => { |
31 |
| - const { tools } = await integration.mcpClient().listTools(); |
32 |
| - const createProject = tools.find((tool) => tool.name === "atlas-create-project"); |
33 |
| - expectDefined(createProject); |
34 |
| - expect(createProject.inputSchema.type).toBe("object"); |
35 |
| - expectDefined(createProject.inputSchema.properties); |
36 |
| - expect(createProject.inputSchema.properties).toHaveProperty("projectName"); |
37 |
| - expect(createProject.inputSchema.properties).toHaveProperty("organizationId"); |
38 | 28 | });
|
39 |
| - it("should create a project", async () => { |
40 |
| - const response = await integration.mcpClient().callTool({ |
41 |
| - name: "atlas-create-project", |
42 |
| - arguments: { projectName: projName }, |
| 29 | + |
| 30 | + describe("atlas-create-project", () => { |
| 31 | + it("should have correct metadata", async () => { |
| 32 | + const { tools } = await integration.mcpClient().listTools(); |
| 33 | + const createProject = tools.find((tool) => tool.name === "atlas-create-project"); |
| 34 | + expectDefined(createProject); |
| 35 | + expect(createProject.inputSchema.type).toBe("object"); |
| 36 | + expectDefined(createProject.inputSchema.properties); |
| 37 | + expect(createProject.inputSchema.properties).toHaveProperty("projectName"); |
| 38 | + expect(createProject.inputSchema.properties).toHaveProperty("organizationId"); |
43 | 39 | });
|
| 40 | + it("should create a project", async () => { |
| 41 | + const response = await integration.mcpClient().callTool({ |
| 42 | + name: "atlas-create-project", |
| 43 | + arguments: { projectName: projName }, |
| 44 | + }); |
44 | 45 |
|
45 |
| - const elements = getResponseElements(response); |
46 |
| - expect(elements).toHaveLength(1); |
47 |
| - expect(elements[0]?.text).toContain(projName); |
48 |
| - }); |
49 |
| - }); |
50 |
| - describe("atlas-list-projects", () => { |
51 |
| - it("should have correct metadata", async () => { |
52 |
| - const { tools } = await integration.mcpClient().listTools(); |
53 |
| - const listProjects = tools.find((tool) => tool.name === "atlas-list-projects"); |
54 |
| - expectDefined(listProjects); |
55 |
| - expect(listProjects.inputSchema.type).toBe("object"); |
56 |
| - expectDefined(listProjects.inputSchema.properties); |
57 |
| - expect(listProjects.inputSchema.properties).toHaveProperty("orgId"); |
| 46 | + const elements = getResponseElements(response); |
| 47 | + expect(elements).toHaveLength(1); |
| 48 | + expect(elements[0]?.text).toContain(projName); |
| 49 | + }); |
58 | 50 | });
|
| 51 | + describe("atlas-list-projects", () => { |
| 52 | + it("should have correct metadata", async () => { |
| 53 | + const { tools } = await integration.mcpClient().listTools(); |
| 54 | + const listProjects = tools.find((tool) => tool.name === "atlas-list-projects"); |
| 55 | + expectDefined(listProjects); |
| 56 | + expect(listProjects.inputSchema.type).toBe("object"); |
| 57 | + expectDefined(listProjects.inputSchema.properties); |
| 58 | + expect(listProjects.inputSchema.properties).toHaveProperty("orgId"); |
| 59 | + }); |
59 | 60 |
|
60 |
| - it("returns project names", async () => { |
61 |
| - const response = await integration.mcpClient().callTool({ name: "atlas-list-projects", arguments: {} }); |
62 |
| - const elements = getResponseElements(response); |
63 |
| - expect(elements).toHaveLength(2); |
64 |
| - expect(elements[1]?.text).toContain("<untrusted-user-data-"); |
65 |
| - expect(elements[1]?.text).toContain(projName); |
66 |
| - const data = parseTable(getDataFromUntrustedContent(elements[1]?.text ?? "")); |
67 |
| - expect(data.length).toBeGreaterThan(0); |
68 |
| - let found = false; |
69 |
| - for (const project of data) { |
70 |
| - if (project["Project Name"] === projName) { |
71 |
| - found = true; |
| 61 | + it("returns project names", async () => { |
| 62 | + const response = await integration.mcpClient().callTool({ name: "atlas-list-projects", arguments: {} }); |
| 63 | + const elements = getResponseElements(response); |
| 64 | + expect(elements).toHaveLength(2); |
| 65 | + expect(elements[1]?.text).toContain("<untrusted-user-data-"); |
| 66 | + expect(elements[1]?.text).toContain(projName); |
| 67 | + const data = parseTable(getDataFromUntrustedContent(elements[1]?.text ?? "")); |
| 68 | + expect(data.length).toBeGreaterThan(0); |
| 69 | + let found = false; |
| 70 | + for (const project of data) { |
| 71 | + if (project["Project Name"] === projName) { |
| 72 | + found = true; |
| 73 | + } |
72 | 74 | }
|
73 |
| - } |
74 |
| - expect(found).toBe(true); |
| 75 | + expect(found).toBe(true); |
75 | 76 |
|
76 |
| - expect(elements[0]?.text).toBe(`Found ${data.length} projects`); |
| 77 | + expect(elements[0]?.text).toBe(`Found ${data.length} projects`); |
| 78 | + }); |
77 | 79 | });
|
78 | 80 | });
|
79 | 81 | });
|
0 commit comments