mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
more socket user tests
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
48
test/user.js
48
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user