ensuring job_id on jobBackend.create and updating test

This commit is contained in:
Simon Martín 2018-02-12 10:39:58 +01:00
parent f9ffa3fec7
commit c351360085
2 changed files with 12 additions and 4 deletions

View File

@ -61,7 +61,17 @@ function isJobFound(redisValues) {
return !!(redisValues[0] && redisValues[1] && redisValues[2] && redisValues[3] && redisValues[4]);
}
function getNotFoundError(job_id) {
var notFoundError = new Error('Job with id ' + job_id + ' not found');
notFoundError.name = 'NotFoundError';
return notFoundError;
}
JobBackend.prototype.get = function (job_id, callback) {
if (!job_id) {
return callback(getNotFoundError(job_id))
}
var self = this;
var redisParams = [
REDIS_PREFIX + job_id,
@ -81,9 +91,7 @@ JobBackend.prototype.get = function (job_id, callback) {
}
if (!isJobFound(redisValues)) {
var notFoundError = new Error('Job with id ' + job_id + ' not found');
notFoundError.name = 'NotFoundError';
return callback(notFoundError);
return callback(getNotFoundError(job_id));
}
var jobData = toObject(job_id, redisParams, redisValues);

View File

@ -58,7 +58,7 @@ describe('job backend', function() {
delete job.data.job_id;
jobBackend.create(job, function (err) {
jobBackend.create(job.data, function (err) {
assert.ok(err);
assert.equal(err.name, 'NotFoundError');
assert.equal(err.message, 'Job with id undefined not found');