ep_rocketchat
Version:
Integrating rocketchat with Etherpad
101 lines (90 loc) • 3.56 kB
JavaScript
;
const RocketChatClient = require('../rocketChat/clients/rocketChatClientInstance').rocketChatClientInstance;
const should = require('should');
const co = require('co');
const config = {
protocol: process.env.protocol,
host: process.env.host,
port: process.env.port,
userId: process.env.userId,
token: process.env.token,
};
describe('im private message', () => {
let rocketChatClient = null;
before((done) => {
rocketChatClient = new RocketChatClient('https', config.host, config.port, config.userId, config.token, done);
});
const imTestUser = {
name: 'name',
email: 'email@example.com',
password: 'anypassyouwant',
username: 'uniqueusername',
sendWelcomeEmail: false,
joinDefaultChannels: false,
verified: false,
requirePasswordChange: false,
roles: ['user'],
};
imTestUser.name += Date.now();
imTestUser.username += Date.now();
imTestUser.email = `email${Date.now()}@example.com`;
let roomId = null;
before(function (done) {
this.timeout(50000);
rocketChatClient.users.create(imTestUser);
setTimeout(() => {
rocketChatClient.chat.postMessage({channel: `@${imTestUser.username}`, text: 'start im chat'}, (err, msg) => {
should(msg.success).be.true();
roomId = msg.message.rid;
done();
});
}, 1000);
});
it('Closes an im and adds the direct message back to the user’s list of direct messages.', () => co(function* () {
const closeResult = yield rocketChatClient.im.close(roomId);
should(closeResult.success).be.ok();
const openResult = yield rocketChatClient.im.open(roomId);
should(openResult.success).be.ok();
}));
it('Sets the topic for the direct message.', () => {
const topic = 'Hello world';
return co(function* () {
const setTopicResult = yield rocketChatClient.im.setTopic(roomId, topic);
setTopicResult.success.should.equal(true);
setTopicResult.topic.should.equal(topic);
});
});
it('Retrieves the messages from a direct message. the message should contain the \'start im chat\'', () => {
const message = 'start im chat';
return co(function *() {
const historyResult = yield rocketChatClient.im.history({roomId});
historyResult.success.should.equal(true);
historyResult.messages.length.should.be.aboveOrEqual(1);
historyResult.messages.should.matchAny((msgItem) => {
msgItem.msg.should.equal(message);
});
});
});
it('Lists all of the direct messages in the server, created im room should in the list', () => co(function *() {
const listEveryoneResult = yield rocketChatClient.im.listEveryone();
listEveryoneResult.success.should.equal(true);
listEveryoneResult.ims.should.matchAny((im) => {
im._id.should.equal(roomId);
});
}));
it('Lists all of the direct messages the calling user has joined, created im room should in the list', () => co(function *() {
const listResult = yield rocketChatClient.im.list();
listResult.success.should.equal(true);
listResult.ims.should.matchAny((im) => {
im._id.should.equal(roomId);
});
}));
xit('Retrieves the messages from any direct message in the server,' +
' the \'start im chat\' should in the message list', () => co(function *() {
const messagesResult = yield rocketChatClient.im.messagesOthers(roomId);
messagesResult.success.should.equal(true);
messagesResult.messages.should.matchAny((message) => {
message.msg.should.equal('start im chat');
});
}));
});