@@ -324,6 +324,12 @@ suite('Connection Storage Test Suite', function () {
324324
325325 suite ( 'when there are preset connections' , ( ) => {
326326 const presetConnections = {
327+ globalValue : [
328+ {
329+ name : 'Global Connection 1' ,
330+ connectionString : 'mongodb://localhost:27017/' ,
331+ } ,
332+ ] ,
327333 workspaceValue : [
328334 {
329335 name : 'Preset Connection 1' ,
@@ -343,11 +349,11 @@ suite('Connection Storage Test Suite', function () {
343349 ] ,
344350 vscode . WorkspaceConfiguration
345351 > ;
346- let getPresetSavedConnectionsStub : sinon . SinonStub ;
352+ let inspectPresetSavedConnectionsStub : sinon . SinonStub ;
347353
348354 beforeEach ( ( ) => {
349355 testSandbox . restore ( ) ;
350- getPresetSavedConnectionsStub = testSandbox . stub ( ) ;
356+ inspectPresetSavedConnectionsStub = testSandbox . stub ( ) ;
351357 } ) ;
352358
353359 test ( 'loads the preset connections' , async ( ) => {
@@ -356,25 +362,39 @@ suite('Connection Storage Test Suite', function () {
356362 'getConfiguration'
357363 ) ;
358364 getConfigurationStub . returns ( {
359- inspect : getPresetSavedConnectionsStub ,
365+ inspect : inspectPresetSavedConnectionsStub ,
366+ get : ( ) => undefined ,
360367 } as any ) ;
361368
362- getPresetSavedConnectionsStub
369+ inspectPresetSavedConnectionsStub
363370 . withArgs ( 'presetSavedConnections' )
364371 . returns ( presetConnections ) ;
365372
366- const connections = await testConnectionStorage . loadConnections ( ) ;
373+ const loadedConnections = await testConnectionStorage . loadConnections ( ) ;
367374
368- expect ( connections . length ) . to . equal ( 2 ) ;
375+ const expectedConnectionValues = [
376+ ...presetConnections . globalValue . map ( ( connection ) => ( {
377+ ...connection ,
378+ source : 'globalSettings' ,
379+ } ) ) ,
380+ ...presetConnections . workspaceValue . map ( ( connection ) => ( {
381+ ...connection ,
382+ source : 'workspaceSettings' ,
383+ } ) ) ,
384+ ] ;
385+
386+ expect ( loadedConnections . length ) . equals (
387+ expectedConnectionValues . length
388+ ) ;
369389
370- for ( let i = 0 ; i < connections . length ; i ++ ) {
371- const connection = connections [ i ] ;
372- const presetConnection = presetConnections [ i ] ;
373- expect ( connection . name ) . equals ( presetConnection . name ) ;
374- expect ( connection . connectionOptions . connectionString ) . equals (
375- presetConnection . connectionString
390+ for ( let i = 0 ; i < expectedConnectionValues . length ; i ++ ) {
391+ const connection = loadedConnections [ i ] ;
392+ const expected = expectedConnectionValues [ i ] ;
393+ expect ( connection . name ) . equals ( expected . name ) ;
394+ expect ( connection . connectionOptions . connectionString ) . contains (
395+ expected . connectionString
376396 ) ;
377- expect ( connection . source ) . equals ( 'workspaceSettings' ) ;
397+ expect ( connection . source ) . equals ( expected . source ) ;
378398 }
379399 } ) ;
380400
@@ -387,34 +407,46 @@ suite('Connection Storage Test Suite', function () {
387407 'getConfiguration'
388408 ) ;
389409 getConfigurationStub . returns ( {
390- get : getPresetSavedConnectionsStub ,
410+ inspect : inspectPresetSavedConnectionsStub ,
411+ get : ( ) => undefined ,
391412 } as any ) ;
392413
393- getPresetSavedConnectionsStub
414+ inspectPresetSavedConnectionsStub
394415 . withArgs ( 'presetSavedConnections' )
395416 . returns ( presetConnections ) ;
396417
397418 const loadedConnections = await testConnectionStorage . loadConnections ( ) ;
398419
399- expect ( loadedConnections . length ) . equals ( 3 ) ;
420+ const expectedConnectionValues = [
421+ {
422+ name : savedConnection . name ,
423+ source : 'user' ,
424+ connectionString :
425+ savedConnection . connectionOptions . connectionString ,
426+ } ,
427+ ...presetConnections . globalValue . map ( ( connection ) => ( {
428+ ...connection ,
429+ source : 'globalSettings' ,
430+ } ) ) ,
431+ ...presetConnections . workspaceValue . map ( ( connection ) => ( {
432+ ...connection ,
433+ source : 'workspaceSettings' ,
434+ } ) ) ,
435+ ] ;
436+
437+ expect ( loadedConnections . length ) . equals (
438+ expectedConnectionValues . length
439+ ) ;
400440
401- for ( let i = 0 ; i < presetConnections . workspaceValue . length ; i ++ ) {
441+ for ( let i = 0 ; i < expectedConnectionValues . length ; i ++ ) {
402442 const connection = loadedConnections [ i ] ;
403- const presetConnection = presetConnections [ i ] ;
404- expect ( connection . name ) . equals ( presetConnection . name ) ;
405- expect ( connection . connectionOptions . connectionString ) . equals (
406- presetConnection . connectionString
443+ const expected = expectedConnectionValues [ i ] ;
444+ expect ( connection . name ) . equals ( expected . name ) ;
445+ expect ( connection . connectionOptions . connectionString ) . contains (
446+ expected . connectionString
407447 ) ;
408- expect ( connection . source ) . equals ( 'workspaceSettings' ) ;
448+ expect ( connection . source ) . equals ( expected . source ) ;
409449 }
410-
411- const savedLoadedConnection = loadedConnections [ 2 ] ;
412-
413- expect ( savedLoadedConnection . name ) . equals ( savedConnection . name ) ;
414- expect (
415- savedLoadedConnection . connectionOptions . connectionString
416- ) . contains ( savedConnection . connectionOptions . connectionString ) ;
417- expect ( savedLoadedConnection . source ) . equals ( 'workspaceSettings' ) ;
418450 } ) ;
419451 } ) ;
420452
0 commit comments