Skip to content

Commit

Permalink
added test for error data payloads in subscriber callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Oct 16, 2017
1 parent 1622e1a commit 3df5463
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions test/failureTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,32 @@ describe('error', function(){

});

it('should fail a job from a subscriber callback', function(finished) {
it('failure event is raised from subscriber error', function(finished) {

this.timeout(3000);

const errorMessage = 'something went wrong';
const jobName = 'suspect-job';
let jobId;


boss.publish(jobName)
.then(id => jobId = id);

boss.on('failed', failure => {
assert.equal(failure.job.id, jobId);
assert.equal(errorMessage, failure.error.message);
boss.removeAllListeners('failed');
finished();
});

boss.subscribe(jobName, job => {
let myError = new Error(errorMessage);
let myError = new Error(errorMessage);

job.done(myError)
.catch(error => {
console.error(error);
assert(false, error.message);
});

});
job.done(myError)
.catch(error => {
console.error(error);
assert(false, error.message);
});
})
.then(() => boss.publish(jobName))
.then(id => jobId = id);

});

Expand Down Expand Up @@ -158,6 +156,22 @@ describe('error', function(){
})
});

it('subscribe failure via done() should pass error payload to failed job', function(finished){
const jobName = 'fetchFailedWithPayload';
const failPayload = 'mah error';

boss.subscribe(jobName, job => {
job.done(failPayload)
.then(() => boss.fetchFailed(jobName))
.then(failedJob => {
assert.strictEqual(failedJob.data.response, failPayload);
finished();
})
})
.then(() => boss.publish(jobName));

});

});


Expand Down

0 comments on commit 3df5463

Please sign in to comment.