@@ -316,6 +316,77 @@ describe('CloudantClient', function() {
316316 } ) ;
317317 } ) ;
318318
319+ describe ( 'disables a plugin' , function ( ) {
320+ it ( 'skips all plugin hooks on good response' , function ( done ) {
321+ var mocks = nock ( SERVER )
322+ . get ( DBNAME )
323+ . reply ( 200 , { doc_count : 1 } ) ;
324+
325+ var cloudantClient = new Client ( { plugins : [ ] } ) ;
326+ cloudantClient . _addPlugins ( testPlugin . NoopPlugin ) ;
327+ assert . equal ( cloudantClient . _plugins . length , 1 ) ;
328+
329+ var options = {
330+ url : SERVER + DBNAME ,
331+ auth : { username : ME , password : PASSWORD } ,
332+ method : 'GET'
333+ } ;
334+
335+ // disable the plugin
336+ cloudantClient . getPlugin ( 'noop' ) . disabled = true ;
337+
338+ cloudantClient . request ( options , function ( err , resp , data ) {
339+ assert . equal ( err , null ) ;
340+ assert . equal ( resp . statusCode , 200 ) ;
341+ assert . ok ( data . indexOf ( '"doc_count":1' ) > - 1 ) ;
342+
343+ // assert hooks are _not_ executed
344+ assert . equal ( cloudantClient . _plugins [ 0 ] . onRequestCallCount , 0 ) ;
345+ assert . equal ( cloudantClient . _plugins [ 0 ] . onErrorCallCount , 0 ) ;
346+ assert . equal ( cloudantClient . _plugins [ 0 ] . onResponseCallCount , 0 ) ;
347+
348+ mocks . done ( ) ;
349+ done ( ) ;
350+ } ) ;
351+ } ) ;
352+
353+ it ( 'skips all plugin hooks on error response' , function ( done ) {
354+ if ( process . env . NOCK_OFF ) {
355+ this . skip ( ) ;
356+ }
357+
358+ var mocks = nock ( SERVER )
359+ . get ( DBNAME )
360+ . replyWithError ( { code : 'ECONNRESET' , message : 'socket hang up' } ) ;
361+
362+ var cloudantClient = new Client ( { plugins : [ ] } ) ;
363+ cloudantClient . _addPlugins ( testPlugin . NoopPlugin ) ;
364+ assert . equal ( cloudantClient . _plugins . length , 1 ) ;
365+
366+ var options = {
367+ url : SERVER + DBNAME ,
368+ auth : { username : ME , password : PASSWORD } ,
369+ method : 'GET'
370+ } ;
371+
372+ // disable the plugin
373+ cloudantClient . getPlugin ( 'noop' ) . disabled = true ;
374+
375+ cloudantClient . request ( options , function ( err , resp , data ) {
376+ assert . equal ( err . code , 'ECONNRESET' ) ;
377+ assert . equal ( err . message , 'socket hang up' ) ;
378+
379+ // assert hooks are _not_ executed
380+ assert . equal ( cloudantClient . _plugins [ 0 ] . onRequestCallCount , 0 ) ;
381+ assert . equal ( cloudantClient . _plugins [ 0 ] . onErrorCallCount , 0 ) ;
382+ assert . equal ( cloudantClient . _plugins [ 0 ] . onResponseCallCount , 0 ) ;
383+
384+ mocks . done ( ) ;
385+ done ( ) ;
386+ } ) ;
387+ } ) ;
388+ } ) ;
389+
319390 describe ( '#db using callbacks' , function ( ) {
320391 describe ( 'with no plugins' , function ( ) {
321392 it ( 'performs request and returns response' , function ( done ) {
0 commit comments