@@ -15,8 +15,7 @@ import { TelemetryService } from '../../../telemetry';
1515import { TEST_DATABASE_URI } from '../dbTestHelper' ;
1616
1717const sandbox = sinon . createSandbox ( ) ;
18- suite ( 'MCPController test suite' , function ( ) {
19- this . timeout ( 300000 ) ;
18+ suite . only ( 'MCPController test suite' , function ( ) {
2019 let extensionContext : ExtensionContext ;
2120 let connectionController : ConnectionController ;
2221 let mcpController : MCPController ;
@@ -207,4 +206,56 @@ suite('MCPController test suite', function () {
207206 expect ( connectionChangedSpy ) . to . be . calledOnce ;
208207 } ) ;
209208 } ) ;
209+
210+ suite ( '#openServerConfig' , function ( ) {
211+ suite ( 'when the server is not running' , function ( ) {
212+ test ( 'should notify that server is not running' , async function ( ) {
213+ const showErrorMessageSpy = sandbox . spy (
214+ vscode . window ,
215+ 'showErrorMessage' ,
216+ ) ;
217+ expect ( await mcpController . openServerConfig ( ) ) . to . equal ( false ) ;
218+ expect ( showErrorMessageSpy ) . to . be . calledWith (
219+ 'MongoDB MCP Server is not running. Start the server by running "MDB: Start MCP Server" in the command palette.' ,
220+ ) ;
221+ } ) ;
222+ } ) ;
223+
224+ suite ( 'when the server is running' , function ( ) {
225+ test ( 'should open the document with the server config' , async function ( ) {
226+ const startServer = mcpController . startServer . bind ( mcpController ) ;
227+ let notifyStartServerCalled : ( ) => void = ( ) => { } ;
228+ const startServerCalled : Promise < void > = new Promise < void > (
229+ ( resolve ) => {
230+ notifyStartServerCalled = resolve ;
231+ } ,
232+ ) ;
233+ sandbox . replace ( mcpController , 'startServer' , async ( ) => {
234+ await startServer ( ) ;
235+ notifyStartServerCalled ( ) ;
236+ } ) ;
237+
238+ const showTextDocumentStub = sandbox . spy (
239+ vscode . window ,
240+ 'showTextDocument' ,
241+ ) ;
242+
243+ // We want to connect as soon as connection changes
244+ await vscode . workspace
245+ . getConfiguration ( 'mdb' )
246+ . update ( 'mcp.server' , 'enabled' ) ;
247+
248+ // Start the controller and list to events
249+ await mcpController . activate ( ) ;
250+
251+ // Add a connection
252+ await connectionController . addNewConnectionStringAndConnect ( {
253+ connectionString : TEST_DATABASE_URI ,
254+ } ) ;
255+ await startServerCalled ;
256+ expect ( await mcpController . openServerConfig ( ) ) . to . equal ( true ) ;
257+ expect ( showTextDocumentStub ) . to . be . called ;
258+ } ) ;
259+ } ) ;
260+ } ) ;
210261} ) ;
0 commit comments