@@ -292,6 +292,116 @@ describe('#unit ConnectionHolder', () => {
292
292
293
293
expect ( connectionHolder . database ( ) ) . toBe ( 'testdb' )
294
294
} )
295
+
296
+ describe ( '.releaseConnection()' , ( ) => {
297
+ describe ( 'when the connection is initialized' , ( ) => {
298
+ describe ( 'and connection is open' , ( ) => {
299
+ let connection
300
+
301
+ beforeEach ( async ( ) => {
302
+ connection = new FakeConnection ( )
303
+ const connectionProvider = newSingleConnectionProvider ( connection )
304
+ const connectionHolder = new ConnectionHolder ( {
305
+ mode : READ ,
306
+ connectionProvider
307
+ } )
308
+
309
+ connectionHolder . initializeConnection ( )
310
+
311
+ await connectionHolder . releaseConnection ( )
312
+ } )
313
+
314
+ it ( 'should call connection.resetAndFlush' , ( ) => {
315
+ expect ( connection . resetInvoked ) . toBe ( 1 )
316
+ } )
317
+
318
+ it ( 'should call connection._release()' , ( ) => {
319
+ expect ( connection . releaseInvoked ) . toBe ( 1 )
320
+ } )
321
+ } )
322
+
323
+ describe ( 'and connection is not open' , ( ) => {
324
+ let connection
325
+
326
+ beforeEach ( async ( ) => {
327
+ connection = new FakeConnection ( )
328
+ connection . _open = false
329
+ const connectionProvider = newSingleConnectionProvider ( connection )
330
+ const connectionHolder = new ConnectionHolder ( {
331
+ mode : READ ,
332
+ connectionProvider
333
+ } )
334
+
335
+ connectionHolder . initializeConnection ( )
336
+
337
+ await connectionHolder . releaseConnection ( )
338
+ } )
339
+
340
+ it ( 'should call connection.resetAndFlush' , ( ) => {
341
+ expect ( connection . resetInvoked ) . toBe ( 0 )
342
+ } )
343
+
344
+ it ( 'should call connection._release()' , ( ) => {
345
+ expect ( connection . releaseInvoked ) . toBe ( 1 )
346
+ } )
347
+ } )
348
+ } )
349
+ } )
350
+
351
+ describe ( '.close()' , ( ) => {
352
+ describe ( 'when the connection is initialized' , ( ) => {
353
+ describe ( 'and connection is open' , ( ) => {
354
+ let connection
355
+
356
+ beforeEach ( async ( ) => {
357
+ connection = new FakeConnection ( )
358
+ const connectionProvider = newSingleConnectionProvider ( connection )
359
+ const connectionHolder = new ConnectionHolder ( {
360
+ mode : READ ,
361
+ connectionProvider
362
+ } )
363
+
364
+ connectionHolder . initializeConnection ( )
365
+
366
+ await connectionHolder . close ( )
367
+ } )
368
+
369
+ it ( 'should call connection.resetAndFlush' , ( ) => {
370
+ expect ( connection . resetInvoked ) . toBe ( 1 )
371
+ } )
372
+
373
+ it ( 'should call connection._release()' , ( ) => {
374
+ expect ( connection . releaseInvoked ) . toBe ( 1 )
375
+ } )
376
+ } )
377
+
378
+ describe ( 'and connection is not open' , ( ) => {
379
+ let connection
380
+
381
+ beforeEach ( async ( ) => {
382
+ connection = new FakeConnection ( )
383
+ connection . _open = false
384
+ const connectionProvider = newSingleConnectionProvider ( connection )
385
+ const connectionHolder = new ConnectionHolder ( {
386
+ mode : READ ,
387
+ connectionProvider
388
+ } )
389
+
390
+ connectionHolder . initializeConnection ( )
391
+
392
+ await connectionHolder . close ( )
393
+ } )
394
+
395
+ it ( 'should call connection.resetAndFlush' , ( ) => {
396
+ expect ( connection . resetInvoked ) . toBe ( 0 )
397
+ } )
398
+
399
+ it ( 'should call connection._release()' , ( ) => {
400
+ expect ( connection . releaseInvoked ) . toBe ( 1 )
401
+ } )
402
+ } )
403
+ } )
404
+ } )
295
405
} )
296
406
297
407
class RecordingConnectionProvider extends SingleConnectionProvider {
0 commit comments