@@ -69,8 +69,8 @@ describe('Kuzzle constructor', () => {
6969 should ( kuzzle ) . have . propertyWithDescriptor ( 'reconnectionDelay' , { enumerable : true , writable : false , configurable : false } ) ;
7070 should ( kuzzle ) . have . propertyWithDescriptor ( 'jwtToken' , { enumerable : true , writable : true , configurable : false } ) ;
7171 should ( kuzzle ) . have . propertyWithDescriptor ( 'offlineQueueLoader' , { enumerable : true , writable : true , configurable : false } ) ;
72- should ( kuzzle ) . have . propertyWithDescriptor ( 'wsPort' , { enumerable : true , writable : false , configurable : false } ) ;
73- should ( kuzzle ) . have . propertyWithDescriptor ( 'ioPort' , { enumerable : true , writable : false , configurable : false } ) ;
72+ should ( kuzzle ) . have . propertyWithDescriptor ( 'wsPort' , { enumerable : true , writable : true , configurable : false } ) ;
73+ should ( kuzzle ) . have . propertyWithDescriptor ( 'ioPort' , { enumerable : true , writable : true , configurable : false } ) ;
7474 should ( kuzzle ) . have . propertyWithDescriptor ( 'sslConnection' , { enumerable : true , writable : false , configurable : false } ) ;
7575 } ) ;
7676
@@ -291,6 +291,20 @@ describe('Kuzzle constructor', () => {
291291 } , 10 ) ;
292292 } ) ;
293293
294+ it ( 'should first disconnect if it was connected' , function ( ) {
295+ var
296+ kuzzle = new Kuzzle ( 'nowhere' , { connect : 'manual' } ) ,
297+ disconnectStub = sinon . stub ( ) ;
298+
299+ kuzzle . disconnect = disconnectStub ;
300+ kuzzle . connect ( ) ;
301+
302+ should ( kuzzle . disconnect . called ) . be . false ( ) ;
303+
304+ kuzzle . connect ( ) ;
305+ should ( kuzzle . disconnect . called ) . be . true ( ) ;
306+ } ) ;
307+
294308 describe ( '=> on connection error' , ( ) => {
295309 beforeEach ( function ( ) {
296310 networkStub . onConnectError = function ( cb ) {
@@ -382,22 +396,25 @@ describe('Kuzzle constructor', () => {
382396
383397 it ( 'should dequeue requests automatically on a connection success' , function ( done ) {
384398 var
385- dequeued = false ,
386- kuzzle ,
387- KuzzleRewired = rewire ( kuzzleSource ) ,
388- revert = KuzzleRewired . __set__ ( 'dequeue' , function ( ) { dequeued = true ; } ) ;
399+ dequeueStub = sinon . stub ( ) ,
400+ kuzzle ;
389401
390402 this . timeout ( 500 ) ;
391403
392- kuzzle = new KuzzleRewired ( 'nowhere' , { connect : 'manual' , autoReplay : false , autoQueue : false } , ( ) => {
393- should ( kuzzle . state ) . be . exactly ( 'connected' ) ;
394- should ( dequeued ) . be . true ( ) ;
395- revert ( ) ;
396- done ( ) ;
397- } ) ;
404+ kuzzle = new Kuzzle ( 'nowhere' , { connect : 'manual' , autoReplay : false , autoQueue : false } ) ;
398405
399- kuzzle . network = networkStub ;
406+ kuzzle . queuing = true ;
407+ kuzzle . offlineQueue . push ( { query : 'foo' } ) ;
408+ kuzzle . addListener ( 'offlineQueuePop' , dequeueStub ) ;
400409 kuzzle . connect ( ) ;
410+
411+ setTimeout ( function ( ) {
412+ should ( dequeueStub . called ) . be . true ( ) ;
413+ should ( kuzzle . state ) . be . exactly ( 'connected' ) ;
414+ should ( kuzzle . queuing ) . be . false ( ) ;
415+ should ( kuzzle . offlineQueue ) . be . empty ( ) ;
416+ done ( ) ;
417+ } , 20 ) ;
401418 } ) ;
402419 } ) ;
403420
0 commit comments