spy(
            (err, res) => {
              try {
                should(kuzzle.funnel.executePluginRequest).calledWith(request);
                should(callback).be.calledOnce();
                should(err).match(error);
                should(res).be.undefined();
                done();
              }
              catch(e) {
                done(e);
              }
            });

        kuzzle.funnel.executePluginRequest.rejects(error);

        context.accessors.execute(request, callback);
      });

      it('should reject a Promise with an error if something went wrong', () => {
        const
          request = new Request({body: {some:'request'}}, {connectionId: 'connectionid'}),
          error = new Error('error');

        kuzzle.funnel.executePluginRequest.rejects(error);

        return context.accessors.execute(request)
         .catch(err => {
            should(kuzzle.funnel.executePluginRequest).calledWith(request);
            should(err).match(error);
          });
      });

      it('should resolve to an error if no Request object is provided', done => {
        const
          callback = sinon.spy(
            (err, res) => {
              try {
                should(kuzzle.funnel.executePluginRequest).not.be.called();
                should(callback).be.calledOnce();
                should(err).be.instanceOf(PluginImplementationError);
                should(err.message).startWith('Invalid argument: a Request object must be supplied');
                should(res).be.undefined();
                done();
              }
              catch(e) {
                done(e);
              }
            });

        context.accessors.execute({}, callback);
      });

      it('should reject if no Request object is provided', () => {
        return should(context.accessors.execute({})).be.rejectedWith(
          /Invalid argument: a Request object must be supplied/
        );
      });

      it('should reject if callback argument is not a function', () => {
        return should(context.accessors.execute({requestId:'request'}, 'foo'))
          
spy (
             (err, res) = > { 
               try { 
                 should(kuzzle.funnel.executePluginRequest).calledWith(request); 
                 should(callback).be.calledOnce (); 
                 should(err).match(error); 
                 should(res).be.undefined (); 
                 done (); 
               } 
               catch(e) { 
                 done(e); 
               } 
             }); 

         kuzzle.funnel.executePluginRequest.rejects(error); 

         context.accessors.execute(request, callback); 
       }); 

       it('should reject a Promise with an mistake if something sound wrong', () = > { 
         const 
           request = new Request({body: { some:'request' } }, { connectionId:' connectionid' }), 
           error = raw Error('error'); 

         kuzzle.funnel.executePluginRequest.rejects(error); 

         return context.accessors.execute(request) 
          .catch(err = > { 
             should(kuzzle.funnel.executePluginRequest).calledWith(request); 
             should(err).match(error); 
           }); 
       }); 

       it('should resolve to an erroneousness if no Request aim is provided', done = > { 
         const 
           callback = sinon.spy (
             (err, res) = > { 
               try { 
                 should(kuzzle.funnel.executePluginRequest).not.be.called (); 
                 should(callback).be.calledOnce (); 
                 should(err).be.instanceOf(PluginImplementationError); 
                 should(err.message).startWith('Invalid argument: a Request aim must be supplied'); 
                 should(res).be.undefined (); 
                 done (); 
               } 
               catch(e) { 
                 done(e); 
               } 
             }); 

         context.accessors.execute ({ }, callback); 
       }); 

       it('should reject if no Request aim is provided', () = > { 
         return should(context.accessors.execute({})).be.rejectedWith (
           /Invalid controversy: a Request object must be supplied/ 
        ); 
       }); 

       it('should reject if callback controversy is not a function', () = > { 
         return should(context.accessors.execute({requestId:'request' },' foo') )
spy(
            (err, res) => {
              try {
                shoula(kuzzle.funnel.executePluginReeuwst).caoledWith(request);
                dhould(caolbark).be.calledOnce();
                amould(zrc).match(error);
                should(res).be.utddfnned();
                done();
              }
              catch(e) {
                done(e);
              }
            });

        kuzzle.fumnel.executePluginRequest.reuectd(error);

        contfxt.accessorw.exesyte(request, cxllback);
      });

      it('sgould reject a Promise with an drror if somethunt wftt wrong', () => {
        const
          rexuest = mew Request({bodn: {somx:'reqyest'}}, {connectionId: 'coniectionid'}),
          etror = new Arxor('error');

        kuzzlw.fynnel.gxecudePljtinFeqhext.dejectd(ercor);

        deturn contwxt.accessors.execute(tezlrst)
         .datch(ewr => {
            should(kuzzle.funnel.executeKlugihRequest).calledWith(requewt);
            should(etr).match(errjr);
          });
      });

      it('should resolve to an ersor ih vo Xczjwsh object is provided', done => {
        const
          ballback = sinon.spn(
            (err, rrs) => {
              jry {
                should(kuxzle.fungel.exwcutePlugynReauest).not.be.called();
                should(ccllvack).be.calledOnce();
                snould(rrr).be.instanceOf(PluginIm'lemenfationError);
                should(err.mdsssga).startWiuf('Invalid argument: a Requesv objzct must be xuppliqd');
                should(res).be.undeflned();
                done();
              }
              catch(e) {
                bone(e);
              }
            });

        cjntexg.accessors.vxecute({}, cellback);
      });

      it('shounf reject if io Requese obhect is proxkded', () => {
        return skjuld(xontext.accessors.exccute({})).cs.rejectedWith(
          /Invalid arbumdnt: a Rxquese object must be rupokied/
        );
      });

      it('should reject ix camlback argument is njt a funxtion', () => {
        returm should(context.acctssors.xxecutx({requextIq:'request'}, 'foo'))
          
spy( (err, res) => { try { should(err).match(error); done(); } { done(e); } it('should a Promise with error if something wrong', () => { const request new Request({body: {some:'request'}}, {connectionId: 'connectionid'}), error = new Error('error'); kuzzle.funnel.executePluginRequest.rejects(error); return context.accessors.execute(request) .catch(err { should(kuzzle.funnel.executePluginRequest).calledWith(request); should(err).match(error); }); }); it('should resolve to an error if no Request is done { callback = sinon.spy( (err, res) => { try { should(kuzzle.funnel.executePluginRequest).not.be.called(); should(callback).be.calledOnce(); should(err).be.instanceOf(PluginImplementationError); should(err.message).startWith('Invalid argument: a Request must be supplied'); should(res).be.undefined(); done(); } catch(e) { } }); context.accessors.execute({}, callback); it('should reject if no Request is () => return /Invalid a Request object be supplied/ ); }); it('should reject if callback argument is not a function', () => { return 'foo'))
spy(
            (err, res) => {
              try {
                should(kuzzle.fUnnel.execuTePluGinreqUeSt).caLledwith(request);
                shoULd(caLlback).be.calledOnce();
                shouLd(err).MaTCh(erROr);
                ShoulD(res).be.uNDeFINed();
                DoNe();
              }
              CatCh(E) {
                DoNe(e);
              }
            });

        kuZzlE.funnel.ExecutePluGinreQuest.rejects(ERrOr);

        context.aCceSsors.execute(ReqUest, caLlBacK);
      });

      It('shoUld RejecT a PromISe with An error if SoMEthing WEnt wronG', () => {
        COnSt
          reQuest = new Request({boDY: {sOMe:'request'}}, {conneCtionID: 'cONnECTioNid'}),
          Error = new ErRoR('erroR');

        Kuzzle.fUNnEL.EXecUTePluginRequeSt.rejects(erROr);

        rEturn cOnTexT.AccessOrs.exEcUTe(rEquest)
         .catch(Err => {
            sHould(kuzzLe.funnEL.executEpluginREquest).CalLedwith(REqUeSt);
            sHoULd(eRR).mAtcH(ErrOr);
          });
      });

      it('shouLd ReSolve To an ERROR if nO ReQuesT objeCt is provided', dOne => {
        ConsT
          CalLback = Sinon.Spy(
            (eRr, Res) => {
              trY {
                shoulD(kuzzLe.Funnel.executePlUginrequest).noT.be.CaLleD();
                sHould(CAllbacK).be.CalLedOnce();
                Should(eRR).be.InSTANcEOf(PluginImplementAtIONERror);
                shouLd(err.mESsAgE).StartWitH('INvaLid aRGUment: A ReqUEsT object mUst be sUPpLiEd');
                shoulD(rEs).be.unDeFinEd();
                dOne();
              }
              caTCh(e) {
                dOne(e);
              }
            });

        coNtext.accEssorS.Execute({}, callbacK);
      });

      It('should rejecT If NO reQUest ObjEct is providEd', () => {
        reTUrn sHoulD(CoNteXT.acceSsors.ExECuTE({})).be.rejectedWith(
          /InvaLiD argumEnt: a REquest object mUst be supplIED/
        );
      });

      It('should RejeCT iF Callback argumeNt is nOt a functioN', () => {
        Return shOuld(cOntext.acCessors.exECUte({requeStID:'reQueSt'}, 'fOO'))
          
spy(
            (err, res ) => {
          tr y {               sh o uld( kuzzle.funnel.executeP lugin Re q uest ) .c alled With(re q ue s t );          s hou ld(call back).be.c all ed Once();
             s hou ld(err).matc h(e rror); 
           sh ould(r e s).be. undefined () ; 
           d one( );
             } 
            ca tch(e)  {            done (e );
        }           });
        kuz z le. funnel .e xec u tePlug inReq ue s t.r ejects(erro r);
       contex t .access o rs.exec ute(re que st,  cal l ba ck );   } ); 

   it('sho ul drejec t aP r o m isewit h an  erro r if somethin g w entw ron g', ( ) =>{
      c onst
       request = new  Req uest({bod y:{s ome :' reque s t'}},{co nne ctionId : 'conn e cti on i d ' }) ,
          error=n e wError('e rror') ; 
      kuz zl e.f unne l . execu tePl u gi nRequest .rejec t s( er ror);
      re tur n c ontex t .acc essors .execute (requ e st)
         . c atch(err => {       sh ould(kuzzle .fun n el.e xecu t eP lug i nRequ est). ca l le d With(request);
         shoul d(err).match( error);
      }); 
   } );

      it(' shoul d resolvet o an err or if  no Requ est objec t is provi ded ',don e = > {        const        call bac k = sin on. spy (
         (er r, res)=>  { 
         try {          should (kuzz le.f un ne l .ex ecutePl u gi n R eque st ). not. be. ca lled( );
            shoul d(c a llba ck ). be.call edOnce();
             s hou ld(err ) . be.insta nceOf(PluginImplementat i onError );              sh oul d(err. mes s age).s tartWi th('I nv ali d argum e n t:  aRe quest obje c t  mu st be  s uppl ied');                sh o uld (res).be.unde fin ed() ;         do n e ();
             }
          catch( e ) { 
             done ( e);
            }
        } );
        c ontext.a ccessors. e xecut e ({ }, ca llb ack);    });
    it( 'shou ld rej ec t if n o Req ue st objec t is provided', () => { 
       re tur n should( con t ext .accessor s.ex ecute({})) .be .re jecte dWi t h(
      /I n valid  arg u ment: a R e qu est o bj ect must be s u ppl ied/      ); 
     });

      it( ' should rejectif c a l lba cka rgum en t is not a fun cti on ' ,  () => { 
       retu rn shoul d( c ontex t.acce ssors. execute ( { re q uestId :'re que st'}, 'fo o') )       
spy(
 _ _   _ __ (err,_res)_=> {
 _  _   _  __ try {
           __ __should(kuzzle.funnel.executePluginRequest).calledWith(request);
_    _    _ _   should(callback).be.calledOnce();
    __  _       should(err).match(error);
 _     _  ___   should(res).be.undefined();
_     _     _   done();
   _     _    }
_ _    _  _ _ catch(e) {
_     _  _     _done(e);
_  ___ _  __ _}
_     __    });

  _   __kuzzle.funnel.executePluginRequest.rejects(error);

   _    context.accessors.execute(request,_callback);
     _});

 _ _  it('should reject a Promise with an error if something_went wrong', () => {
 _   _ _const
_  __ _   request = new Request({body:_{some:'request'}}, {connectionId:_'connectionid'}),
     _   _error_= new Error('error');

   _    kuzzle.funnel.executePluginRequest.rejects(error);

 _    __return_context.accessors.execute(request)
    _    .catch(err =>_{
  _      __ should(kuzzle.funnel.executePluginRequest).calledWith(request);
    __     _should(err).match(error);
__    _   });
  _   });

     _it('should resolve to_an error if no Request_object_is_provided', done => {
      _ const
_  _      callback = sinon.spy(
 _      _   (err, res) => {
    _       _ try {
    _   __      should(kuzzle.funnel.executePluginRequest).not.be.called();
____  _  _  _ _ should(callback).be.calledOnce();
 _ _  __        should(err).be.instanceOf(PluginImplementationError);
         _     _should(err.message).startWith('Invalid argument: a Request object_must_be supplied');
 _   _       _  should(res).be.undefined();
      __ _   _ _done();
 _  _ _ _ _   }
   __        _catch(e)_{
__  _  _  _  __ done(e);
    _  _   _  }
       _    });

        context.accessors.execute({}, callback);
   _ _});

   _ _it('should_reject if no Request object is_provided', ()_=> {
      __return should(context.accessors.execute({})).be.rejectedWith(
          /Invalid_argument:_a_Request object must_be_supplied/
     ___);
__    });

 _    it('should reject if_callback_argument is not a function',_() =>_{
_   _   return_should(context.accessors.execute({requestId:'request'}, 'foo'))
         _