socket/meta test

v1.18.x
barisusakli 8 years ago
parent 853cea7fec
commit e3616ab0f9

@ -1,20 +1,20 @@
'use strict';
var meta = require('../meta');
var user = require('../user');
var topics = require('../topics');
var websockets = require('./');
var SocketMeta = {
rooms: {}
};
SocketMeta.reconnected = function (socket, data, callback) {
callback = callback || function () {};
if (socket.uid) {
topics.pushUnreadCount(socket.uid);
user.notifications.pushCount(socket.uid);
}
callback();
};
/* Rooms */

@ -275,6 +275,53 @@ describe('socket.io', function () {
});
});
it('should push unread notifications on reconnect', function (done) {
var socketMeta = require('../src/socket.io/meta');
socketMeta.reconnected({uid: 1}, {}, function (err) {
assert.ifError(err);
done();
});
});
it('should error if the room is missing', function (done) {
io.emit('meta.rooms.enter', null, function (err) {
assert.equal(err.message, '[[error:invalid-data]]');
done();
});
});
it('should return if uid is 0', function (done) {
var socketMeta = require('../src/socket.io/meta');
socketMeta.rooms.enter({uid: 0}, null, function (err) {
assert.ifError(err);
done();
});
});
it('should join a room', function (done) {
io.emit('meta.rooms.enter', {enter: 'recent_topics'}, function (err) {
assert.ifError(err);
done();
});
});
it('should leave current room', function (done) {
io.emit('meta.rooms.leaveCurrent', {}, function (err) {
assert.ifError(err);
done();
});
});
it('should get server time', function (done) {
var socketMeta = require('../src/socket.io/meta');
socketMeta.getServerTime({uid: 1}, null, function (err, time) {
assert.ifError(err);
assert(time);
done();
});
});
after(function (done) {
db.emptydb(done);
});

Loading…
Cancel
Save