@@ -77,6 +77,9 @@ describe("Connect tool", () => {
7777 } ) ;
7878 const content = getResponseContent ( response . content ) ;
7979 expect ( content ) . toContain ( "Error running connect" ) ;
80+
81+ // Should not suggest using the config connection string (because we don't have one)
82+ expect ( content ) . not . toContain ( "Your config lists a different connection string" ) ;
8083 } ) ;
8184 } ) ;
8285 } ) ;
@@ -103,5 +106,34 @@ describe("Connect tool", () => {
103106 expect ( content ) . toContain ( "Successfully connected" ) ;
104107 expect ( content ) . toContain ( newConnectionString ) ;
105108 } ) ;
109+
110+ describe ( "when the arugment connection string is invalid" , ( ) => {
111+ it ( "suggests the config connection string if set" , async ( ) => {
112+ const response = await client . callTool ( {
113+ name : "connect" ,
114+ arguments : { connectionStringOrClusterName : "mongodb://localhost:12345" } ,
115+ } ) ;
116+ const content = getResponseContent ( response . content ) ;
117+ expect ( content ) . toContain ( "Failed to connect to MongoDB at 'mongodb://localhost:12345'" ) ;
118+ expect ( content ) . toContain (
119+ `Your config lists a different connection string: '${ config . connectionString } ' - do you want to try connecting to it instead?`
120+ ) ;
121+ } ) ;
122+
123+ it ( "returns error message if the config connection string matches the argument" , async ( ) => {
124+ config . connectionString = "mongodb://localhost:12345" ;
125+ const response = await client . callTool ( {
126+ name : "connect" ,
127+ arguments : { connectionStringOrClusterName : "mongodb://localhost:12345" } ,
128+ } ) ;
129+
130+ const content = getResponseContent ( response . content ) ;
131+
132+ // Should be handled by default error handler and not suggest the config connection string
133+ // because it matches the argument connection string
134+ expect ( content ) . toContain ( "Error running connect" ) ;
135+ expect ( content ) . not . toContain ( "Your config lists a different connection string" ) ;
136+ } ) ;
137+ } ) ;
106138 } ) ;
107139} ) ;
0 commit comments