afterEach((done) => { rp.get.restore(); rp.post.restore(); cacheSetSpy.restore(); cacheGetSpy.restore(); done(); });
it('fail if no response getting the key', (done) => { // Mock out the get call for fetching the key to give an error rp.get.restore(); reqStub = sinon.stub(rp, 'get'); reqStub.returns(Promise.reject()); token_util.verify(token1_valid, trusted_issuers).then((decoded) => { done(new Error('Should fail no response getting the key')); }).catch(() => { // We expect an error here done(); }); });
it('fail signed with a different key', (done) => { // Mock out the get call for fetching the key to give an error rp.get.restore(); reqStub = sinon.stub(rp, 'get'); reqStub.returns(Promise.resolve(JSON.stringify({ value: key2 }))); // Using a key from another server, verification should fail token_util.verify(token1_valid, trusted_issuers).then((decoded) => { done(new Error('Should fail if token and key mismatch')); }).catch((err) => { // We expect an error here try { expect(err.name).to.equal('JsonWebTokenError'); expect(err.message).to.equal('invalid signature'); done(); } catch (e) { return done(e); } }); });
after(function() { request.put.restore(); request.get.restore(); });
afterEach(() => { request.get.restore() })
return service.getCuisines().catch(function(error) { assert.isTrue(error.message === 'Something went wrong'); requestPromise.get.restore(); });
return service.getCuisines().then(function(result) { assert.isTrue(result === 'result'); requestPromise.get.restore(); });