Skip to content

Commit fbb8e1e

Browse files
chore: a few more tests
1 parent 0b72e6a commit fbb8e1e

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

src/mcp/vsCodeMCPConnectionManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export class VSCodeMCPConnectionManager extends ConnectionManager {
6868
async disconnect(): Promise<ConnectionStateDisconnected> {
6969
try {
7070
await this.activeConnectionProvider?.close(true);
71+
return this.changeState('connection-close', {
72+
tag: 'disconnected',
73+
});
7174
} catch (error) {
7275
this.logger.error({
7376
id: MCPLogIds.DisconnectError,
@@ -78,9 +81,6 @@ export class VSCodeMCPConnectionManager extends ConnectionManager {
7881
} finally {
7982
this.activeConnectionId = null;
8083
this.activeConnectionProvider = null;
81-
return this.changeState('connection-close', {
82-
tag: 'disconnected',
83-
});
8484
}
8585
}
8686

src/test/suite/mcp/mcpController.test.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { TelemetryService } from '../../../telemetry';
1515
import { TEST_DATABASE_URI } from '../dbTestHelper';
1616

1717
const 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

Comments
 (0)