@@ -304,95 +304,55 @@ describe('useConnections', function () {
304304 } ) ;
305305 } ) ;
306306
307- describe ( 'saving connections during connect in single connection mode' , function ( ) {
308- it ( 'should NOT update existing connection with new props when existing connection is successfull' , async function ( ) {
309- await preferences . savePreferences ( {
310- // We're testing multiple connections by default
311- enableNewMultipleConnectionSystem : false ,
307+ for ( const multipleConnectionsEnabled of [ true , false ] ) {
308+ describe ( `when multiple connections ${
309+ multipleConnectionsEnabled ? 'enabled' : 'disabled'
310+ } `, function ( ) {
311+ it ( 'should NOT update existing connection with new props when existing connection is successfull' , async function ( ) {
312+ await preferences . savePreferences ( {
313+ enableNewMultipleConnectionSystem : multipleConnectionsEnabled ,
314+ } ) ;
315+
316+ const connections = renderHookWithContext ( ) ;
317+ const saveSpy = sinon . spy ( mockConnectionStorage , 'save' ) ;
318+
319+ await connections . current . connect ( {
320+ ...mockConnections [ 0 ] ,
321+ favorite : { name : 'foobar' } ,
322+ } ) ;
323+
324+ // Only once on success so that we're not updating existing connections if
325+ // they failed
326+ expect ( saveSpy ) . to . have . been . calledOnce ;
327+ expect ( saveSpy . getCall ( 0 ) ) . to . have . nested . property (
328+ 'args[0].connectionInfo.favorite.name' ,
329+ 'turtles'
330+ ) ;
312331 } ) ;
313332
314- const connections = renderHookWithContext ( ) ;
315- const saveSpy = sinon . spy ( mockConnectionStorage , 'save' ) ;
333+ it ( 'should not update existing connection if connection failed' , async function ( ) {
334+ await preferences . savePreferences ( {
335+ enableNewMultipleConnectionSystem : multipleConnectionsEnabled ,
336+ } ) ;
316337
317- await connections . current . connect ( {
318- ...mockConnections [ 0 ] ,
319- favorite : { name : 'foobar' } ,
320- } ) ;
321-
322- // Only once on success so that we're not updating existing connections if
323- // they failed
324- expect ( saveSpy ) . to . have . been . calledOnce ;
325- expect ( saveSpy . getCall ( 0 ) ) . to . have . nested . property (
326- 'args[0].connectionInfo.favorite.name' ,
327- 'turtles'
328- ) ;
329- } ) ;
330-
331- it ( 'should not update existing connection if connection failed' , async function ( ) {
332- await preferences . savePreferences ( {
333- enableNewMultipleConnectionSystem : false ,
334- } ) ;
335-
336- const saveSpy = sinon . spy ( mockConnectionStorage , 'save' ) ;
337- const onConnectionFailed = sinon . spy ( ) ;
338- const connections = renderHookWithContext ( { onConnectionFailed } ) ;
339-
340- sinon
341- . stub ( connectionsManager , 'connect' )
342- . rejects ( new Error ( 'Failed to connect' ) ) ;
343-
344- await connections . current . connect ( {
345- ...mockConnections [ 0 ] ,
346- favorite : { name : 'foobar' } ,
347- } ) ;
348-
349- expect ( onConnectionFailed ) . to . have . been . calledOnce ;
350- expect ( saveSpy ) . to . not . have . been . called ;
351- } ) ;
352- } ) ;
338+ const saveSpy = sinon . spy ( mockConnectionStorage , 'save' ) ;
339+ const onConnectionFailed = sinon . spy ( ) ;
340+ const connections = renderHookWithContext ( { onConnectionFailed } ) ;
353341
354- describe ( 'saving connections during connect in multiple connections mode' , function ( ) {
355- it ( 'should update existing connection with new props when connection is successfull' , async function ( ) {
356- const connections = renderHookWithContext ( ) ;
357- const saveSpy = sinon . spy ( mockConnectionStorage , 'save' ) ;
342+ sinon
343+ . stub ( connectionsManager , 'connect' )
344+ . rejects ( new Error ( 'Failed to connect' ) ) ;
358345
359- await connections . current . connect ( {
360- ...mockConnections [ 0 ] ,
361- favorite : { name : 'foobar' } ,
362- } ) ;
346+ await connections . current . connect ( {
347+ ...mockConnections [ 0 ] ,
348+ favorite : { name : 'foobar' } ,
349+ } ) ;
363350
364- // Saved before and after in multiple connections mode
365- expect ( saveSpy ) . to . have . been . calledTwice ;
366- expect ( saveSpy . getCall ( 0 ) ) . to . have . nested . property (
367- 'args[0].connectionInfo.favorite.name' ,
368- 'foobar'
369- ) ;
370- expect ( saveSpy . getCall ( 1 ) ) . to . have . nested . property (
371- 'args[0].connectionInfo.favorite.name' ,
372- 'foobar'
373- ) ;
374- } ) ;
375-
376- it ( 'should always update existing connection even if conneciton will fail' , async function ( ) {
377- const saveSpy = sinon . spy ( mockConnectionStorage , 'save' ) ;
378- const onConnectionFailed = sinon . spy ( ) ;
379- const connections = renderHookWithContext ( { onConnectionFailed } ) ;
380-
381- sinon
382- . stub ( connectionsManager , 'connect' )
383- . rejects ( new Error ( 'Failed to connect' ) ) ;
384-
385- await connections . current . connect ( {
386- ...mockConnections [ 0 ] ,
387- connectionOptions : {
388- connectionString : 'mongodb://super-broken-new-url' ,
389- } ,
351+ expect ( onConnectionFailed ) . to . have . been . calledOnce ;
352+ expect ( saveSpy ) . to . not . have . been . called ;
390353 } ) ;
391-
392- expect ( onConnectionFailed ) . to . have . been . calledOnce ;
393- expect ( saveSpy ) . to . have . been . calledOnce ;
394354 } ) ;
395- } ) ;
355+ }
396356 } ) ;
397357
398358 describe ( '#disconnect' , function ( ) {
0 commit comments