mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
more tests
This commit is contained in:
@@ -72,15 +72,21 @@ SocketUser.emailConfirm = function (socket, data, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {
|
if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {
|
||||||
callback();
|
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
||||||
}
|
}
|
||||||
user.getUserField(socket.uid, 'email', function (err, email) {
|
|
||||||
if (err || !email) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
user.email.sendValidationEmail(socket.uid, email, callback);
|
async.waterfall([
|
||||||
});
|
function (next) {
|
||||||
|
user.getUserField(socket.uid, 'email', next);
|
||||||
|
},
|
||||||
|
function (email, next) {
|
||||||
|
if (!email) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
user.email.sendValidationEmail(socket.uid, email, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -109,39 +115,37 @@ SocketUser.reset.commit = function (socket, data, callback) {
|
|||||||
if (!data || !data.code || !data.password) {
|
if (!data || !data.code || !data.password) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
var uid;
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
async.parallel({
|
||||||
|
uid: async.apply(db.getObjectField, 'reset:uid', data.code),
|
||||||
|
reset: async.apply(user.reset.commit, data.code, data.password)
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (results, next) {
|
||||||
|
uid = results.uid;
|
||||||
|
events.log({
|
||||||
|
type: 'password-reset',
|
||||||
|
uid: uid,
|
||||||
|
ip: socket.ip
|
||||||
|
});
|
||||||
|
|
||||||
async.parallel({
|
user.getUserField(uid, 'username', next);
|
||||||
uid: async.apply(db.getObjectField, 'reset:uid', data.code),
|
},
|
||||||
reset: async.apply(user.reset.commit, data.code, data.password)
|
function (username, next) {
|
||||||
}, function (err, results) {
|
var now = new Date();
|
||||||
if (err) {
|
var parsedDate = now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate();
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
var uid = results.uid;
|
|
||||||
var now = new Date();
|
|
||||||
var parsedDate = now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate();
|
|
||||||
|
|
||||||
user.getUserField(uid, 'username', function (err, username) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
emailer.send('reset_notify', uid, {
|
emailer.send('reset_notify', uid, {
|
||||||
username: username,
|
username: username,
|
||||||
date: parsedDate,
|
date: parsedDate,
|
||||||
site_title: meta.config.title || 'NodeBB',
|
site_title: meta.config.title || 'NodeBB',
|
||||||
subject: '[[email:reset.notify.subject]]'
|
subject: '[[email:reset.notify.subject]]'
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
events.log({
|
next();
|
||||||
type: 'password-reset',
|
}
|
||||||
uid: uid,
|
], callback);
|
||||||
ip: socket.ip
|
|
||||||
});
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.isFollowing = function (socket, data, callback) {
|
SocketUser.isFollowing = function (socket, data, callback) {
|
||||||
@@ -224,16 +228,10 @@ SocketUser.saveSettings = function (socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.setTopicSort = function (socket, sort, callback) {
|
SocketUser.setTopicSort = function (socket, sort, callback) {
|
||||||
if (!socket.uid) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
user.setSetting(socket.uid, 'topicPostSort', sort, callback);
|
user.setSetting(socket.uid, 'topicPostSort', sort, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.setCategorySort = function (socket, sort, callback) {
|
SocketUser.setCategorySort = function (socket, sort, callback) {
|
||||||
if (!socket.uid) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
user.setSetting(socket.uid, 'categoryTopicSort', sort, callback);
|
user.setSetting(socket.uid, 'categoryTopicSort', sort, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -160,6 +160,9 @@ module.exports = function (User) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
User.setSetting = function (uid, key, value, callback) {
|
User.setSetting = function (uid, key, value, callback) {
|
||||||
|
if (!parseInt(uid, 10)) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
db.setObjectField('user:' + uid + ':settings', key, value, callback);
|
db.setObjectField('user:' + uid + ':settings', key, value, callback);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -794,7 +794,14 @@ describe('Controllers', function () {
|
|||||||
user.create({username: 'follower'}, function (err, _uid) {
|
user.create({username: 'follower'}, function (err, _uid) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
uid = _uid;
|
uid = _uid;
|
||||||
socketUser.follow({uid: uid}, {uid: fooUid}, done);
|
socketUser.follow({uid: uid}, {uid: fooUid}, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
socketUser.isFollowing({uid: uid}, {uid: fooUid}, function (err, isFollowing) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert(isFollowing);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
96
test/user.js
96
test/user.js
@@ -707,6 +707,102 @@ describe('User', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should error if requireEmailConfirmation is disabled', function (done) {
|
||||||
|
socketUser.emailConfirm({uid: testUid}, {}, function (err) {
|
||||||
|
assert.equal(err.message, '[[error:email-confirmations-are-disabled]]');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send email confirm', function (done) {
|
||||||
|
Meta.config.requireEmailConfirmation = 1;
|
||||||
|
socketUser.emailConfirm({uid: testUid}, {}, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
Meta.config.requireEmailConfirmation = 0;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send reset email', function (done) {
|
||||||
|
socketUser.reset.send({uid: 0}, 'john@example.com', function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return invalid-data error', function (done) {
|
||||||
|
socketUser.reset.send({uid: 0}, null, function (err) {
|
||||||
|
assert.equal(err.message, '[[error:invalid-data]]');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not error', function (done) {
|
||||||
|
socketUser.reset.send({uid: 0}, 'doestnot@exist.com', function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should commit reset', function (done) {
|
||||||
|
db.getObject('reset:uid', function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
var code = Object.keys(data)[0];
|
||||||
|
socketUser.reset.commit({uid: 0}, {code: code, password: 'swordfish'}, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should save user settings', function (done) {
|
||||||
|
var data = {
|
||||||
|
uid: 1,
|
||||||
|
settings: {
|
||||||
|
bootswatchSkin: 'default',
|
||||||
|
homePageRoute: 'none',
|
||||||
|
homePageCustom: '',
|
||||||
|
openOutgoingLinksInNewTab: 0,
|
||||||
|
scrollToMyPost: 1,
|
||||||
|
delayImageLoading: 1,
|
||||||
|
userLang: 'en-GB',
|
||||||
|
usePagination: 1,
|
||||||
|
topicsPerPage: '10',
|
||||||
|
postsPerPage: '5',
|
||||||
|
showemail: 1,
|
||||||
|
showfullname: 1,
|
||||||
|
restrictChat: 0,
|
||||||
|
followTopicsOnCreate: 1,
|
||||||
|
followTopicsOnReply: 1,
|
||||||
|
notificationSound: '',
|
||||||
|
incomingChatSound: '',
|
||||||
|
outgoingChatSound: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
socketUser.saveSettings({uid: testUid}, data, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set moderation note', function (done) {
|
||||||
|
User.create({username: 'noteadmin'}, function (err, adminUid) {
|
||||||
|
assert.ifError(err);
|
||||||
|
groups.join('administrators', adminUid, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
socketUser.setModerationNote({uid: adminUid}, {uid: testUid, note: 'this is a test user'}, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
User.getUserField(testUid, 'moderationNote', function (err, note) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(note, 'this is a test user');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('approval queue', function () {
|
describe('approval queue', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user