UNPKG

girc

Version:
88 lines (82 loc) 3.6 kB
/*jslint node: true, vars: true*/ /*global describe, it*/ "use strict"; describe('plugins/mode.js', function () { var stream = new (require('stream').PassThrough)(); var cmngr = new (require('../../lib/connectionManager'))({id: "test_plugin_mode", nick: "testnick"}, stream); var con = cmngr.getConnection('test_plugin_mode'); stream.emit('connect'); describe('mode(target, flags, params)', function () { it('should set a mode', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('MODE #channel +r random\r\n'); done(); }); con.mode('#channel', '+r', 'random'); }); it('params should be optional', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('MODE #channel +r\r\n'); done(); }); con.mode('#channel', '+r'); }); it('should set a mode if target is user', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('MODE user +r random\r\n'); done(); }); con.mode(con.getUser('user'), '+r', 'random'); }); it('should set a mode if target is channel', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('MODE #channel +r random\r\n'); done(); }); con.mode(con.getChannel('#channel'), '+r', 'random'); }); }); describe('on MODE', function () { it('should parse usermode', function (done) { con.once('mode', function (event) { event.by.getNick().should.equal('testnick'); event.adding.should.equal(true); event.mode.should.equal('x'); done(); }); stream.write(':testnick!testuser@testhost.com MODE test +x\r\n'); }); it('should parse usermode aswell', function (done) { con.once('mode', function (event) { event.by.should.equal('testnick'); event.adding.should.equal(true); event.mode.should.equal('Z'); con.once('mode', function (event) { event.by.should.equal('testnick'); event.adding.should.equal(true); event.mode.should.equal('i'); done(); }); }); stream.write(':testnick MODE testnick :+Zi\r\n'); }); it('should parse channelmode', function (done) { con.once('mode', function (event) { event.channel.getName().should.equal('#foo'); event.by.getNick().should.equal('foo'); event.argument.should.equal('bar'); event.adding.should.equal(false); event.mode.should.equal('o'); con.once('mode', function (event) { event.channel.getName().should.equal('#foo'); event.by.getNick().should.equal('foo'); event.argument.should.equal('baz'); event.adding.should.equal(true); event.mode.should.equal('v'); done(); }); }); stream.write(':foo!bar@baz.com MODE #foo -o+v bar baz\r\n'); }); }); });