UNPKG

girc

Version:
162 lines (140 loc) 6.63 kB
/*jslint node: true, vars: true*/ /*global describe, it*/ "use strict"; describe('plugins/whois.js', function () { var stream = new (require('stream').PassThrough)(); var cmngr = new (require('../../lib/connectionManager'))({id: "test_plugin_whois", nick: "testnick"}, stream); var con = cmngr.getConnection('test_plugin_whois'); stream.emit('connect'); describe('whois(target, mask, callback)', function () { it('should parse user information', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.nick.should.equal('testnick'); data.username.should.equal('testuser'); data.hostname.should.equal('testhost.com'); data.realname.should.equal('testrealname'); done(); }); stream.write(':example.irc.net 311 thatsme testnick testuser testhost.com * :testrealname\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should parse channels (with modes)', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.channels.should.be.an.instanceOf(Object).and.have.properties({ '#b0wm': [], '#breadfish++': [], '#dev': ['%'], '#foreveralone': ['~'], '#glados': [], '#kerat': ['~'], '#kerat-op': [], '#kochstube': [], '#pupskuchen': [], '#sa-mp.de': ['~'], '#zncbnc': ['~'], }); done(); }); stream.write(':example.irc.net 319 thatsme testnick :~#kerat ~#zncbnc #kerat-op #b0wm %#dev #kochstube #glados #pupskuchen ~#foreveralone ~#sa-mp.de #breadfish++\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should parse server information', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.server.should.equal('server.com'); data.serverInfo.should.equal('Server Info'); done(); }); stream.write(':example.irc.net 312 thatsme testnick server.com :Server Info\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should parse operator', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.oper.should.equal(true); done(); }); stream.write(':example.irc.net 313 thatsme testnick :is a NetAdmin on ircnet\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should parse account', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.account.should.equal('Nick'); done(); }); stream.write(':example.irc.net 330 thatsme testnick Nick :is logged in as\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should parse registered', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.registered.should.equal(true); done(); }); stream.write(':example.irc.net 307 thatsme testnick :is a registered nick\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should parse secure connection', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.secure.should.equal(true); done(); }); stream.write(':example.irc.net 671 thatsme testnick :is using a secure connection\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should parse secure connection', function (done) { con.whois('testnick', function (err, data) { if (err) { return done(err); } data.idle.should.equal(1076); data.signon.should.be.an.instanceof(Date); data.signon.getTime().should.equal(1390235346 * 1000); done(); }); stream.write(':example.irc.net 317 thatsme testnick 1076 1390235346 :seconds idle, signon time\r\n'); stream.write(':example.irc.net 318 thatsme testnick :End of /WHOIS list.\r\n'); }); it('should err with No such nick/channel', function (done) { con.whois('unusednickorchannel'); con.once('whois', function (err) { err.should.equal('No such nick/channel'); done(); }); stream.write(':example.irc.net 401 thatsme unusednickorchannel :No such nick/channel\r\n'); stream.write(':example.irc.net 318 thatsme unusednickorchannel :End of /WHOIS list.\r\n'); }); it('should err with No such server', function (done) { con.whois('not.a.valid.server', function (err) { err.should.equal('No such server'); done(); }); stream.write(':example.irc.net 402 thatsme not.a.valid.server :No such server\r\n'); }); it('should err with Not enough parameters', function (done) { con.once('whois', function (err) { err.should.equal('Not enough parameters'); done(); }); stream.write(':example.irc.net 461 thatsme WHOIS :Not enough parameters.\r\n'); }); }); });