Job returned from save method is undefined in testMode
- Dominant language
- JavaScript
- Stars
- 9.4k
- Forks
- 858
- PR merge metrics
- No merged PRs in 30d
Description
The job is not getting returned during test mode from the save method.
```javascript
const kue = require('kue')
const queue = kue.createQueue()
// Enter Queue testMode
queue.testMode.enter()
const job = queue.create('TEST_QUEUE', {
title: 'TEST'
}).save((err) => {
if (err) return console.error(err)
// job is undefined here
console.log(job.id) // errors out
})
```
It works if I do it this way.
```javascript
const kue = require('kue')
const queue = kue.createQueue()
// Enter Queue testMode
queue.testMode.enter()
const job = queue.create('TEST_QUEUE', {
title: 'TEST'
})
job.save((err) => {
if (err) return console.error(err)
console.log(job.id) // prints 1
})
```
I think the issue is because we are not returning the job instance in the `testJobSave` and `testJobUpdate` methods in https://github.com/Automattic/kue/blob/master/lib/queue/test_mode.js#L9-L26
we could do this to make it work...
```javascript
function testJobSave( fn ) {
if(processQueue) {
jobs.push(this);
return originalJobSave.call(this, fn);
} else {
this.id = _.uniqueId();
jobs.push(this);
if( _.isFunction(fn) ) process.nextTick(fn);
return this;
}
};
function testJobUpdate( fn ) {
if(processQueue) {
return originalJobUpdate.call(this, fn);
} else {
if( _.isFunction(fn) ) process.nextTick(fn);
return this;
}
};```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in lib/queue/test_mode.js at testJobSave and testJobUpdate, then inspect the existing queue test-mode tests. Reproduce the chained save call from the issue and verify the value returned by save and its callback behavior in test mode match the normal path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100