mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
more tests
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var validator = require('validator');
|
var validator = require('validator');
|
||||||
|
|
||||||
@@ -82,7 +81,7 @@ SocketModules.chats.send = function (socket, data, callback) {
|
|||||||
function (message, next) {
|
function (message, next) {
|
||||||
Messaging.notifyUsersInRoom(socket.uid, data.roomId, message);
|
Messaging.notifyUsersInRoom(socket.uid, data.roomId, message);
|
||||||
user.updateOnlineUsers(socket.uid);
|
user.updateOnlineUsers(socket.uid);
|
||||||
next();
|
next(null, message);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ var Groups = require('../src/groups');
|
|||||||
var Messaging = require('../src/messaging');
|
var Messaging = require('../src/messaging');
|
||||||
var helpers = require('./helpers');
|
var helpers = require('./helpers');
|
||||||
|
|
||||||
|
|
||||||
describe('Messaging Library', function () {
|
describe('Messaging Library', function () {
|
||||||
var testUids;
|
var testUids;
|
||||||
var fooUid;
|
var fooUid;
|
||||||
@@ -84,8 +85,9 @@ describe('Messaging Library', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('rooms', function () {
|
describe('rooms', function () {
|
||||||
|
var socketModules = require('../src/socket.io/modules');
|
||||||
it('should create a new chat room', function (done) {
|
it('should create a new chat room', function (done) {
|
||||||
Messaging.newRoom(fooUid, [bazUid, herpUid], function (err, _roomId) {
|
socketModules.chats.newRoom({uid: fooUid}, {touid: bazUid}, function (err, _roomId) {
|
||||||
roomId = _roomId;
|
roomId = _roomId;
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(roomId);
|
assert(roomId);
|
||||||
@@ -93,8 +95,15 @@ describe('Messaging Library', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add a user to room', function (done) {
|
||||||
|
socketModules.chats.addUserToRoom({uid: fooUid}, {roomId: roomId, username: 'herp'}, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should leave the chat room', function (done) {
|
it('should leave the chat room', function (done) {
|
||||||
Messaging.leaveRoom([bazUid], roomId, function (err) {
|
socketModules.chats.leave({uid: bazUid}, roomId, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
Messaging.isUserInRoom(bazUid, roomId, function (err, isUserInRoom) {
|
Messaging.isUserInRoom(bazUid, roomId, function (err, isUserInRoom) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@@ -105,21 +114,26 @@ describe('Messaging Library', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should send a message to a room', function (done) {
|
it('should send a message to a room', function (done) {
|
||||||
Messaging.sendMessage(fooUid, roomId, 'first chat message', Date.now(), function (err, messageData) {
|
socketModules.chats.send({uid: fooUid}, {roomId: roomId, message: 'first chat message'}, function (err, messageData) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(messageData);
|
assert(messageData);
|
||||||
assert.equal(messageData.content, 'first chat message');
|
assert.equal(messageData.content, 'first chat message');
|
||||||
assert(messageData.fromUser);
|
assert(messageData.fromUser);
|
||||||
assert(messageData.roomId, roomId);
|
assert(messageData.roomId, roomId);
|
||||||
done();
|
socketModules.chats.getRaw({uid: fooUid}, {roomId: roomId, mid: messageData.mid}, function (err, raw) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(raw, 'first chat message');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should get messages from room', function (done) {
|
it('should get messages from room', function (done) {
|
||||||
Messaging.getMessages({
|
socketModules.chats.getMessages({uid: fooUid}, {
|
||||||
callerUid: fooUid,
|
|
||||||
uid: fooUid,
|
uid: fooUid,
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
|
start: 0,
|
||||||
markRead: true
|
markRead: true
|
||||||
}, function (err, messages) {
|
}, function (err, messages) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@@ -129,6 +143,14 @@ describe('Messaging Library', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should load chat room', function (done) {
|
||||||
|
socketModules.chats.loadRoom({uid: fooUid}, {roomId: roomId}, function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert(data);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('controller', function () {
|
describe('controller', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user