Skip to content

Node.js based forum software built for the modern web

more socket user tests

barisusakli7f90e31a3876
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index 41c2e9c2c5..69b229b4b1 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -46,7 +46,7 @@ SocketUser.deleteAccount = function (socket, data, callback) {
user.deleteAccount(socket.uid, next);
},
function (next) {
- socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: 'offline'});
+ require('./index').server.sockets.emit('event:user_status_change', {uid: socket.uid, status: 'offline'});
events.log({
type: 'user-delete',
diff --git a/test/controllers.js b/test/controllers.js
index 03d7d38e11..cd08039557 100644
--- a/test/controllers.js
+++ b/test/controllers.js
@@ -788,12 +788,13 @@ describe('Controllers', function () {
});
describe('account follow page', function () {
+ var socketUser = require('../src/socket.io/user');
var uid;
before(function (done) {
user.create({username: 'follower'}, function (err, _uid) {
assert.ifError(err);
uid = _uid;
- user.follow(uid, fooUid, done);
+ socketUser.follow({uid: uid}, {uid: fooUid}, done);
});
});
@@ -816,7 +817,7 @@ describe('Controllers', function () {
});
it('should return empty after unfollow', function (done ) {
- user.unfollow(uid, fooUid, function (err) {
+ socketUser.unfollow({uid: uid}, {uid: fooUid}, function (err) {
assert.ifError(err);
request(nconf.get('url') + '/api/user/foo/followers', {json: true}, function (err, res, body) {
assert.ifError(err);
diff --git a/test/user.js b/test/user.js
index 114c4dfdc3..c2f67ef709 100644
--- a/test/user.js
+++ b/test/user.js
@@ -610,7 +610,55 @@ describe('User', function () {
});
});
});
+ });
+
+ describe('socket methods', function () {
+ var socketUser = require('../src/socket.io/user');
+
+ it('should fail with invalid data', function (done) {
+ socketUser.exists({uid: testUid}, null, function (err) {
+ assert.equal(err.message, '[[error:invalid-data]]');
+ done();
+ });
+ });
+
+ it('should return true if user/group exists', function (done) {
+ socketUser.exists({uid: testUid}, {username: 'registered-users'}, function (err, exists) {
+ assert.ifError(err);
+ assert(exists);
+ done();
+ });
+ });
+
+ it('should return true if user/group exists', function (done) {
+ socketUser.exists({uid: testUid}, {username: 'John Smith'}, function (err, exists) {
+ assert.ifError(err);
+ assert(exists);
+ done();
+ });
+ });
+
+ it('should return false if user/group does not exists', function (done) {
+ socketUser.exists({uid: testUid}, {username: 'doesnot exist'}, function (err, exists) {
+ assert.ifError(err);
+ assert(!exists);
+ done();
+ });
+ });
+ it('should delete user', function (done) {
+ User.create({username: 'tobedeleted'}, function (err, _uid) {
+ assert.ifError(err);
+ socketUser.deleteAccount({uid: _uid}, {}, function (err) {
+ assert.ifError(err);
+ socketUser.exists({uid: testUid}, {username: 'doesnot exist'}, function (err, exists) {
+ assert.ifError(err);
+ assert(!exists);
+ done();
+ });
+ });
+ });
+ });
});