@@ -15,12 +15,15 @@ import {
1515 TEST_DATABASE_URI_USER ,
1616 TEST_USER_PASSWORD ,
1717} from '../dbTestHelper' ;
18- import type { StoreConnectionInfo } from '../../../storage/connectionStorage' ;
18+ import type { LoadedConnection } from '../../../storage/connectionStorage' ;
1919import { ConnectionStorage } from '../../../storage/connectionStorage' ;
2020
2121const testDatabaseConnectionName = 'localhost:27088' ;
2222
23- const newTestConnection = ( connectionStorage : ConnectionStorage , id : string ) =>
23+ const newTestConnection = (
24+ connectionStorage : ConnectionStorage ,
25+ id : string
26+ ) : LoadedConnection =>
2427 connectionStorage . createNewConnection ( {
2528 connectionId : id ,
2629 connectionOptions : {
@@ -305,9 +308,7 @@ suite('Connection Storage Test Suite', function () {
305308 expect ( connections . length ) . to . equal ( 1 ) ;
306309
307310 const newSavedConnectionInfoWithSecrets =
308- await testConnectionStorage . _getConnectionInfoWithSecrets (
309- connections [ 0 ] as StoreConnectionInfo
310- ) ;
311+ await testConnectionStorage . _getConnectionInfoWithSecrets ( connections [ 0 ] ) ;
311312
312313 expect ( newSavedConnectionInfoWithSecrets ) . to . deep . equal ( connectionInfo ) ;
313314 } ) ;
@@ -321,6 +322,104 @@ suite('Connection Storage Test Suite', function () {
321322 extensionSandbox . restore ( ) ;
322323 } ) ;
323324
325+ suite ( 'when there are preset connections' , ( ) => {
326+ const presetConnections = [
327+ {
328+ name : 'Preset Connection 1' ,
329+ connectionString : 'mongodb://localhost:27017/' ,
330+ } ,
331+ {
332+ name : 'Preset Connection 2' ,
333+ connectionString : 'mongodb://localhost:27018/' ,
334+ } ,
335+ ] ;
336+
337+ let getConfigurationStub : sinon . SinonStub <
338+ [
339+ section ?: string | undefined ,
340+ scope ?: vscode . ConfigurationScope | null | undefined
341+ ] ,
342+ vscode . WorkspaceConfiguration
343+ > ;
344+ let getPresetSavedConnectionsStub : sinon . SinonStub ;
345+
346+ beforeEach ( ( ) => {
347+ testSandbox . restore ( ) ;
348+ getPresetSavedConnectionsStub = testSandbox . stub ( ) ;
349+ } ) ;
350+
351+ test ( 'loads the preset connections' , async ( ) => {
352+ getConfigurationStub = testSandbox . stub (
353+ vscode . workspace ,
354+ 'getConfiguration'
355+ ) ;
356+ getConfigurationStub . returns ( {
357+ get : getPresetSavedConnectionsStub ,
358+ } as any ) ;
359+
360+ getPresetSavedConnectionsStub
361+ . withArgs ( 'presetSavedConnections' )
362+ . returns ( presetConnections ) ;
363+
364+ const connections = await testConnectionStorage . loadConnections ( ) ;
365+
366+ expect ( connections . length ) . to . equal ( 2 ) ;
367+
368+ for ( let i = 0 ; i < connections . length ; i ++ ) {
369+ const connection = connections [ i ] ;
370+ const presetConnection = presetConnections [ i ] ;
371+ expect ( connection . name ) . equals (
372+ `${ presetConnection . name } (From Configuration)`
373+ ) ;
374+ expect ( connection . connectionOptions . connectionString ) . equals (
375+ presetConnection . connectionString
376+ ) ;
377+ expect ( connection . isMutable ) . equals ( false ) ;
378+ }
379+ } ) ;
380+
381+ test ( 'loads both preset and other saved connections' , async ( ) => {
382+ const savedConnection = newTestConnection ( testConnectionStorage , '1' ) ;
383+ await testConnectionStorage . saveConnection ( savedConnection ) ;
384+
385+ getConfigurationStub = testSandbox . stub (
386+ vscode . workspace ,
387+ 'getConfiguration'
388+ ) ;
389+ getConfigurationStub . returns ( {
390+ get : getPresetSavedConnectionsStub ,
391+ } as any ) ;
392+
393+ getPresetSavedConnectionsStub
394+ . withArgs ( 'presetSavedConnections' )
395+ . returns ( presetConnections ) ;
396+
397+ const loadedConnections = await testConnectionStorage . loadConnections ( ) ;
398+
399+ expect ( loadedConnections . length ) . equals ( 3 ) ;
400+
401+ for ( let i = 0 ; i < presetConnections . length ; i ++ ) {
402+ const connection = loadedConnections [ i ] ;
403+ const presetConnection = presetConnections [ i ] ;
404+ expect ( connection . name ) . equals (
405+ `${ presetConnection . name } (From Configuration)`
406+ ) ;
407+ expect ( connection . connectionOptions . connectionString ) . equals (
408+ presetConnection . connectionString
409+ ) ;
410+ expect ( connection . isMutable ) . equals ( false ) ;
411+ }
412+
413+ const savedLoadedConnection = loadedConnections [ 2 ] ;
414+
415+ expect ( savedLoadedConnection . name ) . equals ( savedConnection . name ) ;
416+ expect (
417+ savedLoadedConnection . connectionOptions . connectionString
418+ ) . contains ( savedConnection . connectionOptions . connectionString ) ;
419+ expect ( savedLoadedConnection . isMutable ) . equals ( true ) ;
420+ } ) ;
421+ } ) ;
422+
324423 suite ( 'when connection secrets are already in SecretStorage' , ( ) => {
325424 afterEach ( ( ) => {
326425 testSandbox . restore ( ) ;
@@ -341,6 +440,8 @@ suite('Connection Storage Test Suite', function () {
341440
342441 // By default the connection secrets are already stored in SecretStorage
343442 const savedConnections = await testConnectionStorage . loadConnections ( ) ;
443+
444+ expect ( savedConnections . length ) . equals ( 2 ) ;
344445 expect (
345446 savedConnections . every (
346447 ( { secretStorageLocation } ) =>
0 commit comments