diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js index 9fb9f7a501..cae91cf9d7 100644 --- a/src/controllers/accounts/edit.js +++ b/src/controllers/accounts/edit.js @@ -117,7 +117,7 @@ function getUserData(req, next, callback) { function (data, next) { userData = data; if (!userData) { - return callback(); + return callback(null, null); } db.getObjectField('user:' + userData.uid, 'password', next); }, diff --git a/src/image.js b/src/image.js index 1609993731..9377757cf3 100644 --- a/src/image.js +++ b/src/image.js @@ -88,14 +88,16 @@ image.normalise = function (path, extension, callback) { callback(err, path + '.png'); }); } else { - new Jimp(path, function (err, image) { - if (err) { - return callback(err); - } - image.write(path + '.png', function (err) { - callback(err, path + '.png'); - }); - }); + async.waterfall([ + function (next) { + new Jimp(path, next); + }, + function (image, next) { + image.write(path + '.png', function (err) { + next(err, path + '.png'); + }); + }, + ], callback); } }; diff --git a/test/files/normalise.jpg b/test/files/normalise.jpg new file mode 100644 index 0000000000..013a8d0cb2 Binary files /dev/null and b/test/files/normalise.jpg differ diff --git a/test/image.js b/test/image.js new file mode 100644 index 0000000000..3c7b0c6369 --- /dev/null +++ b/test/image.js @@ -0,0 +1,23 @@ +'use strict'; + +var assert = require('assert'); +var path = require('path'); + +var db = require('./mocks/databasemock'); +var image = require('../src/image'); +var file = require('../src/file'); + +describe('image', function () { + + it('should normalise image', function (done) { + image.normalise(path.join(__dirname, 'files/normalise.jpg'), '.jpg', function (err) { + assert.ifError(err); + file.exists(path.join(__dirname, 'files/normalise.jpg.png'), function (err, exists) { + assert.ifError(err); + assert(exists); + done(); + }); + }); + }); + +});