From 091f459f5ebe6fa70ee2427857a5ee11d50fb665 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 2 Dec 2016 14:58:13 +0300 Subject: [PATCH] search socket test --- src/user/approval.js | 31 +++++++++++++++---------------- test/user.js | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/user/approval.js b/src/user/approval.js index c8b78eb75f..2f9d9f847a 100644 --- a/src/user/approval.js +++ b/src/user/approval.js @@ -46,18 +46,19 @@ module.exports = function (User) { }; function sendNotificationToAdmins(username, callback) { - notifications.create({ - bodyShort: '[[notifications:new_register, ' + username + ']]', - nid: 'new_register:' + username, - path: '/admin/manage/registration', - mergeId: 'new_register' - }, function (err, notification) { - if (err || !notification) { - return callback(err); + async.waterfall([ + function (next) { + notifications.create({ + bodyShort: '[[notifications:new_register, ' + username + ']]', + nid: 'new_register:' + username, + path: '/admin/manage/registration', + mergeId: 'new_register' + }, next); + }, + function (notification, next) { + notifications.pushGroup(notification, 'administrators', next); } - - notifications.pushGroup(notification, 'administrators', callback); - }); + ], callback); } User.acceptRegistration = function (username, callback) { @@ -153,13 +154,11 @@ module.exports = function (User) { }, function (users, next) { users = users.map(function (user, index) { - if (!user) { - return null; + if (user) { + user.timestampISO = utils.toISOString(data[index].score); + delete user.hashedPassword; } - user.timestampISO = utils.toISOString(data[index].score); - delete user.hashedPassword; - return user; }).filter(Boolean); diff --git a/test/user.js b/test/user.js index 3567906601..c5769579e1 100644 --- a/test/user.js +++ b/test/user.js @@ -170,6 +170,7 @@ describe('User', function () { }); describe('.search()', function () { + var socketUser = require('../src/socket.io/user'); it('should return an object containing an array of matching users', function (done) { User.search({query: 'john'}, function (err, searchData) { assert.ifError(err); @@ -178,6 +179,30 @@ describe('User', function () { 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 () {