From be1eb81059ff9c04ee0776d583ef175955e3a209 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 16 May 2016 15:03:20 -0700 Subject: [PATCH] make the mock client get method async and update worker tests to use async value --- test/fixtures/elasticsearch.js | 4 ++-- test/src/worker.js | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/test/fixtures/elasticsearch.js b/test/fixtures/elasticsearch.js index c7df356..3862254 100644 --- a/test/fixtures/elasticsearch.js +++ b/test/fixtures/elasticsearch.js @@ -45,14 +45,14 @@ Client.prototype.get = function (params = {}, source = {}) { status: 'pending' }, source); - return { + return Promise.resolve({ _index: params.index || 'index', _type: params.type || DEFAULT_SETTING_DOCTYPE, _id: params.id || 'AVRPRLnlp7Ur1SZXfT-T', _version: params.version || 1, found: true, _source: _source - }; + }); }; Client.prototype.search = function (params = {}, count = 5, source = {}) { diff --git a/test/src/worker.js b/test/src/worker.js index 53d7eee..86be3c3 100644 --- a/test/src/worker.js +++ b/test/src/worker.js @@ -285,9 +285,12 @@ describe('Worker class', function () { id: 12345, version: 3 }; - job = mockQueue.client.get(params); - worker = new Worker(mockQueue, 'test', noop); - updateSpy = sinon.spy(mockQueue.client, 'update'); + return mockQueue.client.get(params) + .then((jobDoc) => { + job = jobDoc; + worker = new Worker(mockQueue, 'test', noop); + updateSpy = sinon.spy(mockQueue.client, 'update'); + }); }); afterEach(() => { @@ -364,16 +367,18 @@ describe('Worker class', function () { anchorMoment = moment(anchor); clock = sinon.useFakeTimers(anchorMoment.valueOf()); - job = mockQueue.client.get(); - worker = new Worker(mockQueue, 'test', noop); - updateSpy = sinon.spy(mockQueue.client, 'update'); + return mockQueue.client.get() + .then((jobDoc) => { + job = jobDoc; + worker = new Worker(mockQueue, 'test', noop); + updateSpy = sinon.spy(mockQueue.client, 'update'); + }); }); afterEach(() => { clock.restore(); }); - it('should use version on update', function () { worker._failJob(job); const query = updateSpy.firstCall.args[0]; @@ -427,8 +432,12 @@ describe('Worker class', function () { payload = { value: random(0, 100, true) }; - job = mockQueue.client.get({}, { payload }); - updateSpy = sinon.spy(mockQueue.client, 'update'); + + return mockQueue.client.get({}, { payload }) + .then((jobDoc) => { + job = jobDoc; + updateSpy = sinon.spy(mockQueue.client, 'update'); + }); }); it('should call the workerFn with the payload', function (done) {