mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
more tests
This commit is contained in:
24
src/posts.js
24
src/posts.js
@@ -188,11 +188,11 @@ var plugins = require('./plugins');
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
user.getSettings(uid, function (err, settings) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
function (settings, next) {
|
||||
var byVotes = settings.topicPostSort === 'most_votes';
|
||||
var sets = posts.map(function (post) {
|
||||
return byVotes ? 'tid:' + post.tid + ':posts:votes' : 'tid:' + post.tid + ':posts';
|
||||
@@ -209,18 +209,16 @@ var plugins = require('./plugins');
|
||||
return post.pid;
|
||||
});
|
||||
|
||||
db[method](sets, pids, function (err, indices) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db[method](sets, pids, next);
|
||||
},
|
||||
function (indices, next) {
|
||||
for (var i = 0; i < indices.length; ++i) {
|
||||
indices[i] = utils.isNumber(indices[i]) ? parseInt(indices[i], 10) + 1 : 0;
|
||||
}
|
||||
|
||||
callback(null, indices);
|
||||
});
|
||||
});
|
||||
next(null, indices);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.updatePostVoteCount = function (postData, callback) {
|
||||
|
||||
@@ -104,19 +104,20 @@ User.sendValidationEmail = function (socket, uids, callback) {
|
||||
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
||||
}
|
||||
|
||||
user.getUsersFields(uids, ['uid', 'email'], function (err, usersData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.getUsersFields(uids, ['uid', 'email'], next);
|
||||
},
|
||||
function (usersData, next) {
|
||||
async.eachLimit(usersData, 50, function (userData, next) {
|
||||
if (userData.email && userData.uid) {
|
||||
user.email.sendValidationEmail(userData.uid, userData.email, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}, callback);
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.sendPasswordResetEmail = function (socket, uids, callback) {
|
||||
|
||||
@@ -390,7 +390,27 @@ describe('Categories', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get active users', function (done) {
|
||||
Categories.create({
|
||||
name: 'test'
|
||||
}, function (err, category) {
|
||||
assert.ifError(err);
|
||||
Topics.post({
|
||||
uid: posterUid,
|
||||
cid: category.cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic'
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
Categories.getActiveUsers(category.cid, function (err, uids) {
|
||||
assert.ifError(err);
|
||||
assert.equal(uids[0], posterUid);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
after(function (done) {
|
||||
|
||||
@@ -829,6 +829,25 @@ describe('Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('post redirect', function () {
|
||||
it('should 404 for invalid pid', function (done) {
|
||||
request(nconf.get('url') + '/post/fail', function (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 404);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return correct post path', function (done) {
|
||||
request(nconf.get('url') + '/api/post/' + pid, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 308);
|
||||
assert.equal(body, '"/topic/1/test-topic-title/1"');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
var analytics = require('../src/analytics');
|
||||
analytics.writeData(function (err) {
|
||||
|
||||
@@ -253,8 +253,13 @@ describe('socket.io', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should validate emails', function (done) {
|
||||
|
||||
|
||||
describe('validation emails', function () {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
var meta = require('../src/meta');
|
||||
|
||||
it('should validate emails', function (done) {
|
||||
socketAdmin.user.validateEmail({uid: adminUid}, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
user.getUserField(regularUid, 'email:confirmed', function (err, emailConfirmed) {
|
||||
@@ -265,6 +270,33 @@ describe('socket.io', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid uids', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.sendValidationEmail({uid: adminUid}, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if email validation is not required', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.sendValidationEmail({uid: adminUid}, [regularUid], function (err) {
|
||||
assert.equal(err.message, '[[error:email-confirmations-are-disabled]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send validation email', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
meta.config.requireEmailConfirmation = 1;
|
||||
socketAdmin.user.sendValidationEmail({uid: adminUid}, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
meta.config.requireEmailConfirmation = 0;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should search users', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.search({uid: adminUid}, {query: 'reg', searchBy: 'username'}, function (err, data) {
|
||||
|
||||
23
test/user.js
23
test/user.js
@@ -684,6 +684,29 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if data is invalid', function (done) {
|
||||
socketUser.emailExists({uid: testUid}, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if email exists', function (done) {
|
||||
socketUser.emailExists({uid: testUid}, {email: 'john@example.com'}, function (err, exists) {
|
||||
assert.ifError(err);
|
||||
assert(exists);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if email does not exist', function (done) {
|
||||
socketUser.emailExists({uid: testUid}, {email: 'does@not.exist'}, function (err, exists) {
|
||||
assert.ifError(err);
|
||||
assert(!exists);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('approval queue', function () {
|
||||
|
||||
Reference in New Issue
Block a user