Skip to content

Commit b5c6345

Browse files
authored
Fix: missing appname when connecting with connectionId (#56)
1 parent db250e5 commit b5c6345

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

src/connectionController.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ export default class ConnectionController {
182182
return reject(new Error(`Unable to connect: ${error}`));
183183
}
184184

185-
// Override the default connection `appname`.
186-
newConnectionModel.appname = `${name} ${version}`;
187-
188185
this.connect(newConnection.id, newConnectionModel).then(
189186
(connectSuccess) => {
190187
if (!connectSuccess) {
@@ -233,6 +230,9 @@ export default class ConnectionController {
233230
this._statusView.showMessage('Connecting to MongoDB...');
234231

235232
return new Promise<boolean>((resolve, reject) => {
233+
// Override the default connection `appname`.
234+
connectionModel.appname = `${name} ${version}`;
235+
236236
const newDataService: DataServiceType = new DataService(connectionModel);
237237
newDataService.connect((err: Error | undefined) => {
238238
this._statusView.hideMessage();
@@ -430,13 +430,13 @@ export default class ConnectionController {
430430
const connectionNameToRemove:
431431
| string
432432
| undefined = await vscode.window.showQuickPick(
433-
connectionIds.map(
434-
(id, index) => `${index + 1}: ${this._savedConnections[id].name}`
435-
),
436-
{
437-
placeHolder: 'Choose a connection to remove...'
438-
}
439-
);
433+
connectionIds.map(
434+
(id, index) => `${index + 1}: ${this._savedConnections[id].name}`
435+
),
436+
{
437+
placeHolder: 'Choose a connection to remove...'
438+
}
439+
);
440440

441441
if (!connectionNameToRemove) {
442442
return Promise.resolve(false);

src/test/suite/connectionController.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ suite('Connection Controller Test Suite', () => {
6767
);
6868
const dataService = testConnectionController.getActiveDataService();
6969
assert(dataService !== null);
70+
assert(testConnectionController._activeConnectionModel?.appname.startsWith('mongodb-vscode'));
7071
assert(testConnectionController.isCurrentlyConnected());
7172
})
7273
.then(done, done);
@@ -477,7 +478,7 @@ suite('Connection Controller Test Suite', () => {
477478
assert(
478479
Object.keys(connections).length === 4,
479480
`Expected 4 connection configurations found ${
480-
Object.keys(connections).length
481+
Object.keys(connections).length
481482
}`
482483
);
483484
assert(
@@ -486,7 +487,7 @@ suite('Connection Controller Test Suite', () => {
486487
);
487488
assert(
488489
Object.keys(connections).includes('testWorkspaceConnectionModel2') ===
489-
true,
490+
true,
490491
"Expected connection configurations to include 'testWorkspaceConnectionModel2'"
491492
);
492493
assert(
@@ -495,7 +496,7 @@ suite('Connection Controller Test Suite', () => {
495496
);
496497
assert(
497498
connections.testGlobalConnectionModel2.driverUrl ===
498-
'testGlobalConnectionModel2DriverUrl',
499+
'testGlobalConnectionModel2DriverUrl',
499500
"Expected loaded connection to include driver url 'testGlobalConnectionModel2DriverUrl'"
500501
);
501502
});
@@ -525,7 +526,7 @@ suite('Connection Controller Test Suite', () => {
525526
assert(
526527
Object.keys(globalStoreConnections).length === 1,
527528
`Expected global store connections to have 1 connection found ${
528-
Object.keys(globalStoreConnections).length
529+
Object.keys(globalStoreConnections).length
529530
}`
530531
);
531532
const id = Object.keys(globalStoreConnections)[0];
@@ -573,7 +574,7 @@ suite('Connection Controller Test Suite', () => {
573574
assert(
574575
Object.keys(workspaceStoreConnections).length === 1,
575576
`Expected workspace store connections to have 1 connection found ${
576-
Object.keys(workspaceStoreConnections).length
577+
Object.keys(workspaceStoreConnections).length
577578
}`
578579
);
579580
const id = Object.keys(workspaceStoreConnections)[0];
@@ -619,7 +620,7 @@ suite('Connection Controller Test Suite', () => {
619620
assert(
620621
Object.keys(workspaceStoreConnections).length === 1,
621622
`Expected workspace store connections to have 1 connection found ${
622-
Object.keys(workspaceStoreConnections).length
623+
Object.keys(workspaceStoreConnections).length
623624
}`
624625
);
625626

@@ -635,7 +636,7 @@ suite('Connection Controller Test Suite', () => {
635636
assert(
636637
testConnectionController.getSavedConnections().length === 1,
637638
`Expected 1 connection config, found ${
638-
testConnectionController.getSavedConnections().length
639+
testConnectionController.getSavedConnections().length
639640
}.`
640641
);
641642
const id = testConnectionController.getSavedConnections()[0].id;
@@ -655,6 +656,7 @@ suite('Connection Controller Test Suite', () => {
655656
name === 'localhost:27018',
656657
`Expected the active connection name to be 'localhost:27018', found ${name}.`
657658
);
659+
assert(testConnectionController._activeConnectionModel?.appname.startsWith('mongodb-vscode'));
658660
})
659661
.then(done, done);
660662
});
@@ -778,7 +780,7 @@ suite('Connection Controller Test Suite', () => {
778780
assert(
779781
Object.keys(workspaceStoreConnections).length === 1,
780782
`Expected workspace store connections to have 1 connection found ${
781-
Object.keys(workspaceStoreConnections).length
783+
Object.keys(workspaceStoreConnections).length
782784
}`
783785
);
784786

@@ -793,7 +795,7 @@ suite('Connection Controller Test Suite', () => {
793795
assert(
794796
Object.keys(postWorkspaceStoreConnections).length === 0,
795797
`Expected workspace store connections to have 0 connections found ${
796-
Object.keys(postWorkspaceStoreConnections).length
798+
Object.keys(postWorkspaceStoreConnections).length
797799
}`
798800
);
799801
})
@@ -827,7 +829,7 @@ suite('Connection Controller Test Suite', () => {
827829
assert(
828830
Object.keys(globalStoreConnections).length === 1,
829831
`Expected workspace store connections to have 1 connection found ${
830-
Object.keys(globalStoreConnections).length
832+
Object.keys(globalStoreConnections).length
831833
}`
832834
);
833835

@@ -841,7 +843,7 @@ suite('Connection Controller Test Suite', () => {
841843
assert(
842844
Object.keys(postGlobalStoreConnections).length === 0,
843845
`Expected global store connections to have 0 connections found ${
844-
Object.keys(postGlobalStoreConnections).length
846+
Object.keys(postGlobalStoreConnections).length
845847
}`
846848
);
847849
});
@@ -877,7 +879,7 @@ suite('Connection Controller Test Suite', () => {
877879
assert(
878880
Object.keys(workspaceStoreConnections).length === 1,
879881
`Expected workspace store connections to have 1 connection found ${
880-
Object.keys(workspaceStoreConnections).length
882+
Object.keys(workspaceStoreConnections).length
881883
}`
882884
);
883885
const connectionId =
@@ -912,7 +914,7 @@ suite('Connection Controller Test Suite', () => {
912914
testConnectionController.getSavedConnections()
913915
.length === 1,
914916
`Expected 1 connection config, found ${
915-
testConnectionController.getSavedConnections().length
917+
testConnectionController.getSavedConnections().length
916918
}.`
917919
);
918920
const id = testConnectionController.getSavedConnections()[0]

0 commit comments

Comments
 (0)