UNPKG

girc

Version:
83 lines (79 loc) 4.27 kB
/*jslint node: true, vars: true*/ /*global describe, it*/ "use strict"; describe('plugins/privmsg.js', function () { var stream = new (require('stream').PassThrough)(); var cmngr = new (require('../../lib/connectionManager'))({id: "test_plugin_privmsg", nick: "testnick"}, stream); var con = cmngr.getConnection('test_plugin_privmsg'); stream.emit('connect'); describe('send(target, [...])', function () { it('should send privmsg if target is string', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('PRIVMSG testnick :The quick brown fox jumps over the lazy dog\r\n'); done(); }); con.send('testnick', 'The quick brown fox jumps over the lazy dog'); }); it('should send privmsg if target is user', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('PRIVMSG testnick :The quick brown fox jumps over the lazy dog\r\n'); done(); }); con.send(con.getUser('testnick'), 'The quick brown fox jumps over the lazy dog'); }); it('should send privmsg if target is channel', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('PRIVMSG #channel :The quick brown fox jumps over the lazy dog\r\n'); done(); }); con.send(con.getChannel('#channel'), 'The quick brown fox jumps over the lazy dog'); }); it('should format with util.format', function (done) { stream.once('data', function (chunk) { chunk.toString().should.equal('PRIVMSG target :The quick brown fox jumps over the lazy dog\r\n'); done(); }); con.send('target', 'The %s brown %s jumps over the lazy %s', 'quick', 'fox', 'dog'); }); }); describe('on PRIVMSG', function () { it('should emit "message"', function (done) { con.once('message', function (event) { event.isAction.should.equal(false); event.channel.getName().should.equal('#channel'); event.user.getNick().should.equal('testnick'); event.message.should.equal('The quick brown fox jumps over the lazy dog'); done(); }); stream.write(':testnick!testuser@testhost.com PRIVMSG #channel :The quick brown fox jumps over the lazy dog\r\n'); }); it('should emit "message" as action', function (done) { con.once('message', function (event) { event.isAction.should.equal(true); event.channel.getName().should.equal('#channel'); event.user.getNick().should.equal('testnick'); event.message.should.equal('The quick brown fox jumps over the lazy dog'); done(); }); stream.write(':testnick!testuser@testhost.com PRIVMSG #channel :\u0001ACTIONThe quick brown fox jumps over the lazy dog\u0001\r\n'); }); it('should emit "privatemessage"', function (done) { con.once('privatemessage', function (event) { event.isAction.should.equal(false); event.user.getNick().should.equal('testnick'); event.message.should.equal('The quick brown fox jumps over the lazy dog'); done(); }); stream.write(':testnick!testuser@testhost.com PRIVMSG testnick :The quick brown fox jumps over the lazy dog\r\n'); }); it('should emit "privatemessage" as action', function (done) { con.once('privatemessage', function (event) { event.isAction.should.equal(true); event.user.getNick().should.equal('testnick'); event.message.should.equal('The quick brown fox jumps over the lazy dog'); done(); }); stream.write(':testnick!testuser@testhost.com PRIVMSG testnick :\u0001ACTIONThe quick brown fox jumps over the lazy dog\u0001\r\n'); }); }); });