make the mock client get method async
and update worker tests to use async value
This commit is contained in:
4
test/fixtures/elasticsearch.js
vendored
4
test/fixtures/elasticsearch.js
vendored
@@ -45,14 +45,14 @@ Client.prototype.get = function (params = {}, source = {}) {
|
|||||||
status: 'pending'
|
status: 'pending'
|
||||||
}, source);
|
}, source);
|
||||||
|
|
||||||
return {
|
return Promise.resolve({
|
||||||
_index: params.index || 'index',
|
_index: params.index || 'index',
|
||||||
_type: params.type || DEFAULT_SETTING_DOCTYPE,
|
_type: params.type || DEFAULT_SETTING_DOCTYPE,
|
||||||
_id: params.id || 'AVRPRLnlp7Ur1SZXfT-T',
|
_id: params.id || 'AVRPRLnlp7Ur1SZXfT-T',
|
||||||
_version: params.version || 1,
|
_version: params.version || 1,
|
||||||
found: true,
|
found: true,
|
||||||
_source: _source
|
_source: _source
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.search = function (params = {}, count = 5, source = {}) {
|
Client.prototype.search = function (params = {}, count = 5, source = {}) {
|
||||||
|
|||||||
@@ -285,9 +285,12 @@ describe('Worker class', function () {
|
|||||||
id: 12345,
|
id: 12345,
|
||||||
version: 3
|
version: 3
|
||||||
};
|
};
|
||||||
job = mockQueue.client.get(params);
|
return mockQueue.client.get(params)
|
||||||
worker = new Worker(mockQueue, 'test', noop);
|
.then((jobDoc) => {
|
||||||
updateSpy = sinon.spy(mockQueue.client, 'update');
|
job = jobDoc;
|
||||||
|
worker = new Worker(mockQueue, 'test', noop);
|
||||||
|
updateSpy = sinon.spy(mockQueue.client, 'update');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -364,16 +367,18 @@ describe('Worker class', function () {
|
|||||||
anchorMoment = moment(anchor);
|
anchorMoment = moment(anchor);
|
||||||
clock = sinon.useFakeTimers(anchorMoment.valueOf());
|
clock = sinon.useFakeTimers(anchorMoment.valueOf());
|
||||||
|
|
||||||
job = mockQueue.client.get();
|
return mockQueue.client.get()
|
||||||
worker = new Worker(mockQueue, 'test', noop);
|
.then((jobDoc) => {
|
||||||
updateSpy = sinon.spy(mockQueue.client, 'update');
|
job = jobDoc;
|
||||||
|
worker = new Worker(mockQueue, 'test', noop);
|
||||||
|
updateSpy = sinon.spy(mockQueue.client, 'update');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
clock.restore();
|
clock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should use version on update', function () {
|
it('should use version on update', function () {
|
||||||
worker._failJob(job);
|
worker._failJob(job);
|
||||||
const query = updateSpy.firstCall.args[0];
|
const query = updateSpy.firstCall.args[0];
|
||||||
@@ -427,8 +432,12 @@ describe('Worker class', function () {
|
|||||||
payload = {
|
payload = {
|
||||||
value: random(0, 100, true)
|
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) {
|
it('should call the workerFn with the payload', function (done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user