mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
Add more user tests
This commit is contained in:
60
test/user.js
60
test/user.js
@@ -14,6 +14,7 @@ var Password = require('../src/password');
|
|||||||
var groups = require('../src/groups');
|
var groups = require('../src/groups');
|
||||||
var helpers = require('./helpers');
|
var helpers = require('./helpers');
|
||||||
var meta = require('../src/meta');
|
var meta = require('../src/meta');
|
||||||
|
var plugins = require('../src/plugins');
|
||||||
|
|
||||||
describe('User', function () {
|
describe('User', function () {
|
||||||
var userData;
|
var userData;
|
||||||
@@ -549,6 +550,65 @@ describe('User', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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) {
|
it('should get profile pictures', function (done) {
|
||||||
io.emit('user.getProfilePictures', {uid: uid}, function (err, data) {
|
io.emit('user.getProfilePictures', {uid: uid}, function (err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user