@@ -57,6 +57,9 @@ describe("Connect tool", () => {
57
57
} ) ;
58
58
const content = getResponseContent ( response . content ) ;
59
59
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" ) ;
60
63
} ) ;
61
64
} ) ;
62
65
} ) ;
@@ -83,5 +86,34 @@ describe("Connect tool", () => {
83
86
expect ( content ) . toContain ( "Successfully connected" ) ;
84
87
expect ( content ) . toContain ( newConnectionString ) ;
85
88
} ) ;
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
+ } ) ;
86
118
} ) ;
87
119
} ) ;
0 commit comments