girc
Version:
IRC Client library
112 lines (109 loc) • 4.38 kB
JavaScript
/*jslint node: true, vars: true*/
/*global describe, it*/
;
var Stream = require('stream').PassThrough;
describe('channel.js', function () {
var stream = new Stream();
var ConManagr = require('../lib/connectionManager');
var cmngr = new ConManagr({id: "test_lib_channel", nick: "testnick"}, stream);
var con = cmngr.getConnection('test_lib_channel');
stream.emit('connect');
var chan = con.getChannel('#channel');
describe('toString()', function () {
it('should return channel name', function (done) {
chan.toString().should.equal('#channel');
done();
});
});
describe('getName()', function () {
it('should return channel name', function (done) {
chan.getName().should.equal('#channel');
done();
});
});
describe('getTopic()', function () {
it('should return topic object', function (done) {
chan.getTopic().should.be.an.Object;
done();
});
});
describe('getNames()', function () {
it('should return names object', function (done) {
chan.getTopic().should.be.an.Object;
done();
});
});
describe('userHasMode()', function () {
it('should return true/false', function (done) {
chan.userHasMode('test', '%').should.not.be.ok;
done();
});
});
describe('isUserInChannel()', function () {
it('should return true/false', function (done) {
chan.isUserInChannel('test').should.not.be.ok;
done();
});
});
describe('notice(msg)', function () {
it('should send msg as notice to the channel', function (done) {
stream.once('data', function (chunk) {
chunk.toString().should.equal('NOTICE #channel :example message\r\n');
done();
});
chan.notice('example message');
});
});
describe('say(msg)', function () {
it('should send msg as privmsg to the channel', function (done) {
stream.once('data', function (chunk) {
chunk.toString().should.equal('PRIVMSG #channel :example message\r\n');
done();
});
chan.say('example message');
});
});
describe('reply(user, msg)', function () {
it('should send msg as privmsg to the channel with the prefix <user>:', function (done) {
stream.once('data', function (chunk) {
chunk.toString().should.equal('PRIVMSG #channel :testnick: example message\r\n');
done();
});
chan.reply('testnick', 'example message');
});
it('should also work if user is a user instance', function (done) {
stream.once('data', function (chunk) {
chunk.toString().should.equal('PRIVMSG #channel :testnick: example message\r\n');
done();
});
chan.reply(con.getUser('testnick'), 'example message');
});
});
describe('kick(user, reason)', function () {
it('should kick <user> from the channel with <reason>', function (done) {
stream.once('data', function (chunk) {
chunk.toString().should.equal('KICK #channel testnick :example reason\r\n');
done();
});
chan.kick('testnick', 'example reason');
});
});
describe('ban(mask)', function () {
it('should set mode +b <mask> in the channel', function (done) {
stream.once('data', function (chunk) {
chunk.toString().should.equal('MODE #channel +b testnick!testuser@testhost.com\r\n');
done();
});
chan.ban('testnick!testuser@testhost.com');
});
});
describe('unban(mask)', function () {
it('should set mode -b <mask> in the channel', function (done) {
stream.once('data', function (chunk) {
chunk.toString().should.equal('MODE #channel -b testnick!testuser@testhost.com\r\n');
done();
});
chan.unban('testnick!testuser@testhost.com');
});
});
});