From f0f3a86908406db32f844b5deeaf4f6f8c7e5e51 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 18 Oct 2016 20:45:25 +0300 Subject: [PATCH] closes #5128 write more messaging tests --- src/messaging/rooms.js | 2 +- test/messaging.js | 59 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js index f16843662f..2687448c56 100644 --- a/src/messaging/rooms.js +++ b/src/messaging/rooms.js @@ -165,7 +165,7 @@ module.exports = function (Messaging) { var keys = uids.map(function (uid) { return 'uid:' + uid + ':chat:rooms'; }); - keys.concat(uids.map(function (uid) { + keys = keys.concat(uids.map(function (uid) { return 'uid:' + uid + ':chat:rooms:unread'; })); db.sortedSetsRemove(keys, roomId, next); diff --git a/test/messaging.js b/test/messaging.js index 3dc256e7a0..e82375db37 100644 --- a/test/messaging.js +++ b/test/messaging.js @@ -7,9 +7,13 @@ var async = require('async'); var User = require('../src/user'); var Groups = require('../src/groups'); var Messaging = require('../src/messaging'); -var testUids; + describe('Messaging Library', function () { + var testUids; + var fooUid; + var bazUid; + var herpUid; before(function (done) { // Create 3 users: 1 admin, 2 regular async.parallel([ @@ -22,6 +26,10 @@ describe('Messaging Library', function () { } testUids = uids; + fooUid = uids[0]; + bazUid = uids[1]; + herpUid = uids[2]; + async.parallel([ async.apply(Groups.join, 'administrators', uids[0]), async.apply(User.setSetting, testUids[1], 'restrictChat', '1') @@ -70,6 +78,55 @@ describe('Messaging Library', function () { }); }); + describe('rooms', function () { + var roomId; + it('should create a new chat room', function (done) { + Messaging.newRoom(fooUid, [bazUid, herpUid], function (err, _roomId) { + roomId = _roomId; + assert.ifError(err); + assert(roomId); + done(); + }); + }); + + it('should leave the chat room', function (done) { + Messaging.leaveRoom([bazUid], roomId, function (err) { + assert.ifError(err); + Messaging.isUserInRoom(bazUid, roomId, function (err, isUserInRoom) { + assert.ifError(err); + assert.equal(isUserInRoom, false); + done(); + }); + }); + }); + + it('should send a message to a room', function (done) { + Messaging.sendMessage(fooUid, roomId, 'first chat message', Date.now(), function (err, messageData) { + assert.ifError(err); + assert(messageData); + assert.equal(messageData.content, 'first chat message'); + assert(messageData.fromUser); + assert(messageData.roomId, roomId); + done(); + }); + }); + + it('should get messages from room', function (done) { + Messaging.getMessages({ + callerUid: fooUid, + uid: fooUid, + roomId: roomId, + markRead: true + }, function (err, messages) { + assert.ifError(err); + assert(Array.isArray(messages)); + assert.equal(messages[0].roomId, roomId); + assert.equal(messages[0].fromuid, fooUid); + done(); + }); + }); + }); + after(function (done) { db.emptydb(done); });