make the mock client get method async

and update worker tests to use async value
This commit is contained in:
2016-05-16 15:03:20 -07:00
parent 8d21dc6967
commit be1eb81059
2 changed files with 20 additions and 11 deletions

View File

@@ -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 = {}) {

View File

@@ -285,10 +285,13 @@ describe('Worker class', function () {
id: 12345,
version: 3
};
job = mockQueue.client.get(params);
return mockQueue.client.get(params)
.then((jobDoc) => {
job = jobDoc;
worker = new Worker(mockQueue, 'test', noop);
updateSpy = sinon.spy(mockQueue.client, 'update');
});
});
afterEach(() => {
clock.restore();
@@ -364,16 +367,18 @@ describe('Worker class', function () {
anchorMoment = moment(anchor);
clock = sinon.useFakeTimers(anchorMoment.valueOf());
job = mockQueue.client.get();
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,9 +432,13 @@ describe('Worker class', function () {
payload = {
value: random(0, 100, true)
};
job = mockQueue.client.get({}, { payload });
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) {
const workerFn = function (jobPayload) {