11import type { Session } from "../../../../src/common/session.js" ;
2- import { expectDefined , getDataFromUntrustedContent , getResponseElements } from "../../helpers.js" ;
3- import {
4- describeWithAtlas ,
5- withProject ,
6- randomId ,
7- parseTable ,
8- deleteCluster ,
9- waitCluster ,
10- sleep ,
11- } from "./atlasHelpers.js" ;
2+ import { expectDefined , getResponseContent } from "../../helpers.js" ;
3+ import { describeWithAtlas , withProject , randomId , deleteCluster , waitCluster , sleep } from "./atlasHelpers.js" ;
124import { afterAll , beforeAll , describe , expect , it } from "vitest" ;
135
146describeWithAtlas ( "clusters" , ( integration ) => {
@@ -48,9 +40,11 @@ describeWithAtlas("clusters", (integration) => {
4840 region : "US_EAST_1" ,
4941 } ,
5042 } ) ;
51- const elements = getResponseElements ( response . content ) ;
52- expect ( elements ) . toHaveLength ( 2 ) ;
53- expect ( elements [ 0 ] ?. text ) . toContain ( "has been created" ) ;
43+ const content = getResponseContent ( response . content ) ;
44+ expect ( content ) . toContain ( "Cluster" ) ;
45+ expect ( content ) . toContain ( clusterName ) ;
46+ expect ( content ) . toContain ( "has been created" ) ;
47+ expect ( content ) . toContain ( "US_EAST_1" ) ;
5448
5549 // Check that the current IP is present in the access list
5650 const accessList = await session . apiClient . listProjectIpAccessLists ( {
@@ -80,11 +74,10 @@ describeWithAtlas("clusters", (integration) => {
8074 name : "atlas-inspect-cluster" ,
8175 arguments : { projectId, clusterName : clusterName } ,
8276 } ) ;
83- const elements = getResponseElements ( response . content ) ;
84- expect ( elements ) . toHaveLength ( 2 ) ;
85- expect ( elements [ 0 ] ?. text ) . toContain ( "Cluster details:" ) ;
86- expect ( elements [ 1 ] ?. text ) . toContain ( "<untrusted-user-data-" ) ;
87- expect ( elements [ 1 ] ?. text ) . toContain ( `${ clusterName } ` ) ;
77+ const content = getResponseContent ( response . content ) ;
78+ expect ( content ) . toContain ( "Cluster details:" ) ;
79+ expect ( content ) . toContain ( "<untrusted-user-data-" ) ;
80+ expect ( content ) . toContain ( clusterName ) ;
8881 } ) ;
8982 } ) ;
9083
@@ -105,14 +98,10 @@ describeWithAtlas("clusters", (integration) => {
10598 . mcpClient ( )
10699 . callTool ( { name : "atlas-list-clusters" , arguments : { projectId } } ) ;
107100
108- const elements = getResponseElements ( response ) ;
109- expect ( elements ) . toHaveLength ( 2 ) ;
110-
111- expect ( elements [ 1 ] ?. text ) . toContain ( "<untrusted-user-data-" ) ;
112- expect ( elements [ 1 ] ?. text ) . toContain ( `${ clusterName } | ` ) ;
113- const data = parseTable ( getDataFromUntrustedContent ( elements [ 1 ] ?. text ?? "" ) ) ;
114- expect ( data . length ) . toBeGreaterThanOrEqual ( 1 ) ;
115- expect ( elements [ 0 ] ?. text ) . toMatch ( `Found ${ data . length } clusters in project` ) ;
101+ const content = getResponseContent ( response . content ) ;
102+ expect ( content ) . toContain ( "<untrusted-user-data-" ) ;
103+ expect ( content ) . toMatch ( `Found clusters in project` ) ;
104+ expect ( content ) . toContain ( projectId ) ;
116105 } ) ;
117106 } ) ;
118107
@@ -164,23 +153,20 @@ describeWithAtlas("clusters", (integration) => {
164153 arguments : { projectId, clusterName, connectionType } ,
165154 } ) ;
166155
167- const elements = getResponseElements ( response . content ) ;
168- expect ( elements . length ) . toBeGreaterThanOrEqual ( 1 ) ;
169- if ( elements [ 0 ] ?. text . includes ( `Connected to cluster "${ clusterName } "` ) ) {
156+ const content = getResponseContent ( response . content ) ;
157+ expect ( content ) . toContain ( "Connected to cluster" ) ;
158+ expect ( content ) . toContain ( clusterName ) ;
159+ if ( content . includes ( `Connected to cluster "${ clusterName } "` ) ) {
170160 connected = true ;
171161
172162 // assert that some of the element s have the message
173- expect (
174- elements . some ( ( element ) =>
175- element . text . includes (
176- "Note: A temporary user has been created to enable secure connection to the cluster. For more information, see https://dochub.mongodb.org/core/mongodb-mcp-server-tools-considerations"
177- )
178- )
179- ) . toBe ( true ) ;
163+ expect ( content ) . toContain (
164+ "Note: A temporary user has been created to enable secure connection to the cluster. For more information, see https://dochub.mongodb.org/core/mongodb-mcp-server-tools-considerations"
165+ ) ;
180166
181167 break ;
182168 } else {
183- expect ( elements [ 0 ] ?. text ) . toContain ( `Attempting to connect to cluster "${ clusterName } "...` ) ;
169+ expect ( content ) . toContain ( `Attempting to connect to cluster "${ clusterName } "...` ) ;
184170 }
185171 await sleep ( 500 ) ;
186172 }
@@ -193,19 +179,18 @@ describeWithAtlas("clusters", (integration) => {
193179 name : "find" ,
194180 arguments : { database : "some-db" , collection : "some-collection" } ,
195181 } ) ;
196- const elements = getResponseElements ( response . content ) ;
197- expect ( elements ) . toHaveLength ( 2 ) ;
198- expect ( elements [ 0 ] ?. text ) . toContain (
182+ const content = getResponseContent ( response . content ) ;
183+ expect ( content ) . toContain (
199184 "You need to connect to a MongoDB instance before you can access its data."
200185 ) ;
201186 // Check if the response contains all available test tools.
202187 if ( process . platform === "darwin" && process . env . GITHUB_ACTIONS === "true" ) {
203188 // The tool atlas-local-connect-deployment may be disabled in some test environments if Docker is not available.
204- expect ( elements [ 1 ] ?. text ) . toContain (
189+ expect ( content ) . toContain (
205190 'Please use one of the following tools: "atlas-connect-cluster", "connect" to connect to a MongoDB instance'
206191 ) ;
207192 } else {
208- expect ( elements [ 1 ] ?. text ) . toContain (
193+ expect ( content ) . toContain (
209194 'Please use one of the following tools: "atlas-connect-cluster", "atlas-local-connect-deployment", "connect" to connect to a MongoDB instance'
210195 ) ;
211196 }
0 commit comments