11import { ObjectId } from "mongodb" ;
2- import { parseTable , describeWithAtlas } from "./atlasHelpers.js" ;
2+ import { describeWithAtlas } from "./atlasHelpers.js" ;
33import { expectDefined , getDataFromUntrustedContent , getResponseElements } from "../../helpers.js" ;
4- import { afterAll , describe , expect , it } from "vitest" ;
5-
6- const randomId = new ObjectId ( ) . toString ( ) ;
4+ import { afterAll , beforeAll , describe , expect , it } from "vitest" ;
75
86describeWithAtlas ( "projects" , ( integration ) => {
9- const projName = "testProj-" + randomId ;
7+ const projectsToCleanup : string [ ] = [ ] ;
108
119 afterAll ( async ( ) => {
1210 const session = integration . mcpServer ( ) . session ;
11+ const projects =
12+ ( await session . apiClient . listProjects ( ) ) . results ?. filter ( ( project ) =>
13+ projectsToCleanup . includes ( project . name )
14+ ) || [ ] ;
1315
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 || "" ,
21- } ,
16+ for ( const project of projects ) {
17+ await session . apiClient . deleteProject ( {
18+ params : {
19+ path : {
20+ groupId : project . id || "" ,
2221 } ,
23- } ) ;
24- break ;
25- }
22+ } ,
23+ } ) ;
2624 }
2725 } ) ;
2826
@@ -36,7 +34,11 @@ describeWithAtlas("projects", (integration) => {
3634 expect ( createProject . inputSchema . properties ) . toHaveProperty ( "projectName" ) ;
3735 expect ( createProject . inputSchema . properties ) . toHaveProperty ( "organizationId" ) ;
3836 } ) ;
37+
3938 it ( "should create a project" , async ( ) => {
39+ const projName = `testProj-${ new ObjectId ( ) . toString ( ) } ` ;
40+ projectsToCleanup . push ( projName ) ;
41+
4042 const response = await integration . mcpClient ( ) . callTool ( {
4143 name : "atlas-create-project" ,
4244 arguments : { projectName : projName } ,
@@ -47,7 +49,23 @@ describeWithAtlas("projects", (integration) => {
4749 expect ( elements [ 0 ] ?. text ) . toContain ( projName ) ;
4850 } ) ;
4951 } ) ;
52+
5053 describe ( "atlas-list-projects" , ( ) => {
54+ let projName : string ;
55+ let orgId : string ;
56+ beforeAll ( async ( ) => {
57+ projName = `testProj-${ new ObjectId ( ) . toString ( ) } ` ;
58+ projectsToCleanup . push ( projName ) ;
59+
60+ const orgs = await integration . mcpServer ( ) . session . apiClient . listOrganizations ( ) ;
61+ orgId = ( orgs . results && orgs . results [ 0 ] ?. id ) ?? "" ;
62+
63+ await integration . mcpClient ( ) . callTool ( {
64+ name : "atlas-create-project" ,
65+ arguments : { projectName : projName , organizationId : orgId } ,
66+ } ) ;
67+ } ) ;
68+
5169 it ( "should have correct metadata" , async ( ) => {
5270 const { tools } = await integration . mcpClient ( ) . listTools ( ) ;
5371 const listProjects = tools . find ( ( tool ) => tool . name === "atlas-list-projects" ) ;
@@ -57,23 +75,51 @@ describeWithAtlas("projects", (integration) => {
5775 expect ( listProjects . inputSchema . properties ) . toHaveProperty ( "orgId" ) ;
5876 } ) ;
5977
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 ;
72- }
73- }
74- expect ( found ) . toBe ( true ) ;
75-
76- expect ( elements [ 0 ] ?. text ) . toBe ( `Found ${ data . length } projects` ) ;
78+ describe ( "with orgId filter" , ( ) => {
79+ it ( "returns projects only for that org" , async ( ) => {
80+ const response = await integration . mcpClient ( ) . callTool ( {
81+ name : "atlas-list-projects" ,
82+ arguments : {
83+ orgId,
84+ } ,
85+ } ) ;
86+
87+ const elements = getResponseElements ( response ) ;
88+ expect ( elements ) . toHaveLength ( 2 ) ;
89+ expect ( elements [ 1 ] ?. text ) . toContain ( "<untrusted-user-data-" ) ;
90+ expect ( elements [ 1 ] ?. text ) . toContain ( projName ) ;
91+ const data = JSON . parse ( getDataFromUntrustedContent ( elements [ 1 ] ?. text ?? "" ) ) as {
92+ name : string ;
93+ orgId : string ;
94+ } [ ] ;
95+ expect ( data . length ) . toBeGreaterThan ( 0 ) ;
96+ expect ( data . every ( ( proj ) => proj . orgId === orgId ) ) . toBe ( true ) ;
97+ expect ( data . find ( ( proj ) => proj . name === projName ) ) . toBeDefined ( ) ;
98+
99+ expect ( elements [ 0 ] ?. text ) . toBe ( `Found ${ data . length } projects` ) ;
100+ } ) ;
101+ } ) ;
102+
103+ describe ( "without orgId filter" , ( ) => {
104+ it ( "returns projects for all orgs" , async ( ) => {
105+ const response = await integration . mcpClient ( ) . callTool ( {
106+ name : "atlas-list-projects" ,
107+ arguments : { } ,
108+ } ) ;
109+
110+ const elements = getResponseElements ( response ) ;
111+ expect ( elements ) . toHaveLength ( 2 ) ;
112+ expect ( elements [ 1 ] ?. text ) . toContain ( "<untrusted-user-data-" ) ;
113+ expect ( elements [ 1 ] ?. text ) . toContain ( projName ) ;
114+ const data = JSON . parse ( getDataFromUntrustedContent ( elements [ 1 ] ?. text ?? "" ) ) as {
115+ name : string ;
116+ orgId : string ;
117+ } [ ] ;
118+ expect ( data . length ) . toBeGreaterThan ( 0 ) ;
119+ expect ( data . find ( ( proj ) => proj . name === projName && proj . orgId === orgId ) ) . toBeDefined ( ) ;
120+
121+ expect ( elements [ 0 ] ?. text ) . toBe ( `Found ${ data . length } projects` ) ;
122+ } ) ;
77123 } ) ;
78124 } ) ;
79125} ) ;
0 commit comments