From e3616ab0f9125174cb4e4c4285383a5bd18da69c Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 18 Nov 2016 15:32:35 +0300 Subject: [PATCH] socket/meta test --- src/socket.io/meta.js | 6 +++--- test/socket.io.js | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index 5714f24080..baa0abc0aa 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -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 */ diff --git a/test/socket.io.js b/test/socket.io.js index 345d8782f4..ff255a0208 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -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); });