@@ -57,6 +57,9 @@ describe("Connect tool", () => {
5757 } ) ;
5858 const content = getResponseContent ( response . content ) ;
5959 expect ( content ) . toContain ( "Error running connect" ) ;
60+
61+ // Should not suggest using the config connection string (because we don't have one)
62+ expect ( content ) . not . toContain ( "Your config lists a different connection string" ) ;
6063 } ) ;
6164 } ) ;
6265 } ) ;
@@ -83,5 +86,34 @@ describe("Connect tool", () => {
8386 expect ( content ) . toContain ( "Successfully connected" ) ;
8487 expect ( content ) . toContain ( newConnectionString ) ;
8588 } ) ;
89+
90+ describe ( "when the arugment connection string is invalid" , ( ) => {
91+ it ( "suggests the config connection string if set" , async ( ) => {
92+ const response = await client ( ) . callTool ( {
93+ name : "connect" ,
94+ arguments : { connectionStringOrClusterName : "mongodb://localhost:12345" } ,
95+ } ) ;
96+ const content = getResponseContent ( response . content ) ;
97+ expect ( content ) . toContain ( "Failed to connect to MongoDB at 'mongodb://localhost:12345'" ) ;
98+ expect ( content ) . toContain (
99+ `Your config lists a different connection string: '${ config . connectionString } ' - do you want to try connecting to it instead?`
100+ ) ;
101+ } ) ;
102+
103+ it ( "returns error message if the config connection string matches the argument" , async ( ) => {
104+ config . connectionString = "mongodb://localhost:12345" ;
105+ const response = await client ( ) . callTool ( {
106+ name : "connect" ,
107+ arguments : { connectionStringOrClusterName : "mongodb://localhost:12345" } ,
108+ } ) ;
109+
110+ const content = getResponseContent ( response . content ) ;
111+
112+ // Should be handled by default error handler and not suggest the config connection string
113+ // because it matches the argument connection string
114+ expect ( content ) . toContain ( "Error running connect" ) ;
115+ expect ( content ) . not . toContain ( "Your config lists a different connection string" ) ;
116+ } ) ;
117+ } ) ;
86118 } ) ;
87119} ) ;
0 commit comments