search socket test

v1.18.x
barisusakli 8 years ago
parent 4b6e4f085d
commit 091f459f5e

@ -46,18 +46,19 @@ module.exports = function (User) {
}; };
function sendNotificationToAdmins(username, callback) { function sendNotificationToAdmins(username, callback) {
async.waterfall([
function (next) {
notifications.create({ notifications.create({
bodyShort: '[[notifications:new_register, ' + username + ']]', bodyShort: '[[notifications:new_register, ' + username + ']]',
nid: 'new_register:' + username, nid: 'new_register:' + username,
path: '/admin/manage/registration', path: '/admin/manage/registration',
mergeId: 'new_register' mergeId: 'new_register'
}, function (err, notification) { }, next);
if (err || !notification) { },
return callback(err); function (notification, next) {
notifications.pushGroup(notification, 'administrators', next);
} }
], callback);
notifications.pushGroup(notification, 'administrators', callback);
});
} }
User.acceptRegistration = function (username, callback) { User.acceptRegistration = function (username, callback) {
@ -153,12 +154,10 @@ module.exports = function (User) {
}, },
function (users, next) { function (users, next) {
users = users.map(function (user, index) { users = users.map(function (user, index) {
if (!user) { if (user) {
return null;
}
user.timestampISO = utils.toISOString(data[index].score); user.timestampISO = utils.toISOString(data[index].score);
delete user.hashedPassword; delete user.hashedPassword;
}
return user; return user;
}).filter(Boolean); }).filter(Boolean);

@ -170,6 +170,7 @@ describe('User', function () {
}); });
describe('.search()', function () { describe('.search()', function () {
var socketUser = require('../src/socket.io/user');
it('should return an object containing an array of matching users', function (done) { it('should return an object containing an array of matching users', function (done) {
User.search({query: 'john'}, function (err, searchData) { User.search({query: 'john'}, function (err, searchData) {
assert.ifError(err); assert.ifError(err);
@ -178,6 +179,30 @@ describe('User', function () {
done(); done();
}); });
}); });
it('should search user', function (done) {
socketUser.search({uid: testUid}, {query: 'john'}, function (err, searchData) {
assert.ifError(err);
assert.equal(searchData.users[0].username, 'John Smith');
done();
});
});
it('should error for guest', function (done) {
Meta.config.allowGuestUserSearching = 0;
socketUser.search({uid: 0}, {query: 'john'}, function (err) {
assert.equal(err.message, '[[error:not-logged-in]]');
Meta.config.allowGuestUserSearching = 1;
done();
});
});
it('should error with invalid data', function (done) {
socketUser.search({uid: testUid}, null, function (err) {
assert.equal(err.message, '[[error:invalid-data]]');
done();
});
});
}); });
describe('.delete()', function () { describe('.delete()', function () {

Loading…
Cancel
Save