girc
Version:
IRC Client library
42 lines (36 loc) • 1.83 kB
JavaScript
/*jslint node: true, vars: true*/
/*global describe, it*/
;
describe('plugins/topic.js', function () {
var stream = new (require('stream').PassThrough)();
var cmngr = new (require('../../lib/connectionManager'))({id: "test_plugin_topic", nick: "testnick"}, stream);
var con = cmngr.getConnection('test_plugin_topic');
stream.emit('connect');
describe('on TOPIC', function () {
it('should emit "topic"', function (done) {
con.once('topic', function (event) {
event.channel.getName().should.equal('#channel');
event.topic.should.equal('HOT TOPIC');
event.user.getNick().should.equal('foo');
event.time.should.be.an.instanceof(Date);
event.time.getTime().should.equal(1391341086 * 1000);
event.changed.should.equal(false);
done();
});
stream.write(':vulcanus.kerat.net 332 testnick #channel :HOT TOPIC\r\n');
stream.write(':vulcanus.kerat.net 333 testnick #channel foo!bar@baz.com 1391341086\r\n');
});
it('should emit "topic" changed', function (done) {
con.once('topic', function (event) {
event.channel.getName().should.equal('#channel');
event.topic.should.equal('HOT TOPIC');
event.user.getNick().should.equal('testnick');
event.time.should.be.an.instanceof(Date);
event.time.getTime().should.be.within(new Date().getTime() - 10, new Date().getTime() + 10);//~ now
event.changed.should.equal(true);
done();
});
stream.write(':testnick!testuser@testhost.com TOPIC #channel :HOT TOPIC\r\n');
});
});
});