From a0ff3734cf670e6833c78f4f9fda9917a9af013e Mon Sep 17 00:00:00 2001 From: pichalite Date: Fri, 30 Dec 2016 00:51:22 +0000 Subject: [PATCH] Add more user tests --- test/user.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/user.js b/test/user.js index 03a8ff73c4..b0ed74887b 100644 --- a/test/user.js +++ b/test/user.js @@ -14,6 +14,7 @@ var Password = require('../src/password'); var groups = require('../src/groups'); var helpers = require('./helpers'); var meta = require('../src/meta'); +var plugins = require('../src/plugins'); describe('User', function () { var userData; @@ -548,6 +549,65 @@ describe('User', function () { done(); }); }); + + it('should return error if no plugins listening for filter:uploadImage when uploading from url', function (done) { + var url = nconf.get('url') + '/logo.png'; + User.uploadFromUrl(uid, url, function (err, uploadedPicture) { + assert.equal(err.message, '[[error:no-plugin]]'); + done(); + }); + }); + + it('should return error if the extension is invalid when uploading from url', function (done) { + var url = nconf.get('url') + '/favicon.ico'; + + function filterMethod(data, callback) { + data.foo += 5; + callback(null, data); + } + + plugins.registerHook('test-plugin', {hook: 'filter:uploadImage', method: filterMethod}); + + User.uploadFromUrl(uid, url, function (err, uploadedPicture) { + assert.equal(err.message, '[[error:invalid-image-extension]]'); + done(); + }); + }); + + it('should return error if the file is too big when uploading from url', function (done) { + var url = nconf.get('url') + '/logo.png'; + meta.config.maximumProfileImageSize = 1; + + function filterMethod(data, callback) { + data.foo += 5; + callback(null, data); + } + + plugins.registerHook('test-plugin', {hook: 'filter:uploadImage', method: filterMethod}); + + User.uploadFromUrl(uid, url, function (err, uploadedPicture) { + assert.equal(err.message, '[[error:file-too-big, ' + meta.config.maximumProfileImageSize + ']]'); + done(); + }); + }); + + it('should upload picture when uploading from url', function (done) { + var url = nconf.get('url') + '/logo.png'; + meta.config.maximumProfileImageSize = ''; + + function filterMethod(data, callback) { + data.foo += 5; + callback(null, {url: url}); + } + + plugins.registerHook('test-plugin', {hook: 'filter:uploadImage', method: filterMethod}); + + User.uploadFromUrl(uid, url, function (err, uploadedPicture) { + assert.ifError(err); + assert.equal(uploadedPicture.url, url); + done(); + }); + }); it('should get profile pictures', function (done) { io.emit('user.getProfilePictures', {uid: uid}, function (err, data) {