From 275d066348247acc2c525d439154397b7e36d4f2 Mon Sep 17 00:00:00 2001 From: Ian Mitchell Date: Wed, 13 Jan 2016 11:32:08 -0800 Subject: [PATCH] Initial Pass Work for #122. WIP --- test/commands/test_choose.js | 50 +++++++++---------- test/commands/test_command.js | 8 +-- test/commands/test_imgur.js | 20 ++++---- test/commands/test_order.js | 44 ++++++++--------- test/commands/test_reply.js | 92 +++++++++-------------------------- test/commands/test_time.js | 14 +++--- test/commands/test_twitter.js | 16 +++--- test/commands/test_youtube.js | 24 ++++----- test/test_arx7.js | 46 ++++++++++-------- 9 files changed, 135 insertions(+), 179 deletions(-) diff --git a/test/commands/test_choose.js b/test/commands/test_choose.js index 30ce1e9..04f4896 100644 --- a/test/commands/test_choose.js +++ b/test/commands/test_choose.js @@ -13,55 +13,55 @@ describe('Choose', () => { describe('Triggers', () => { it('should respond to .c trigger', () => { return choose.message('Mocha', '#test', '.c this, that').then(() => { - assert(client.lastMessage); + assert(client.lastMessage, 'Bot did not send message to channel'); }); }); it('should respond to .choose trigger', () => { return choose.message('Mocha', '#test', '.choose one, two').then(() => { - assert(client.lastMessage); + assert(client.lastMessage, 'Bot did not send message to channel'); }); }); it('should respond to .erande trigger', () => { return choose.message('Mocha', '#test', '.erande one, two').then(() => { - assert(client.lastMessage); + assert(client.lastMessage, 'Bot did not send message to channel'); }); }); it('should respond to .選んで trigger', () => { return choose.message('Mocha', '#test', '.選んで one, two').then(() => { - assert(client.lastMessage); + assert(client.lastMessage, 'Bot did not send message to channel'); }); }); it('should respond to .選ぶがよい trigger', () => { return choose.message('Mocha', '#test', '.選ぶがよい one, two').then(() => { - assert(client.lastMessage); + assert(client.lastMessage, 'Bot did not send message to channel'); }); }); it('should not respond to .choo trigger', () => { return choose.message('Mocha', '#test', '.choo one, two').then(() => { - assert.equal(null, client.lastMessage); + assert(!client.lastMessage, 'Bot sent message to channel'); }); }); it('should activate in beginning of phrase', () => { return choose.message('Mocha', '#test', '.c this, that').then(() => { - assert.notEqual(null, client.lastMessage); + assert(client.lastMessage, 'Bot did not send message to channel'); }); }); it('should not activate in middle of phrase', () => { return choose.message('Mocha', '#test', 'test .c this, that').then(() => { - assert.equal(null, client.lastMessage); + assert(!client.lastMessage, 'Bot sent message to channel'); }); }); it('should not activate with an empty list', () => { return choose.message('Mocha', '#test', '.c').then(() => { - assert.equal(null, client.lastMessage); + assert.equal(client.lastMessage, null); }); }); @@ -72,19 +72,19 @@ describe('Choose', () => { ]; return choose.message('Mocha', '#test', '.c ,, , ,,').then(() => { - assert(outputs.includes(client.lastMessage)); + assert(outputs.includes(client.lastMessage), 'Invalid option chosen'); }); }); it('should activate with a single commas', () => { return choose.message('Mocha', '#test', '.c , ').then(() => { - assert.equal('Mocha: ,', client.lastMessage); + assert.equal(client.lastMessage, 'Mocha: ,'); }); }); it('should be case insensitive', () => { return choose.message('Mocha', '#test', '.CHOOSE A').then(() => { - assert.equal('Mocha: A', client.lastMessage); + assert.equal(client.lastMessage, 'Mocha: A'); }); }); }); @@ -92,13 +92,13 @@ describe('Choose', () => { describe('General Usage', () => { it('should respond in correct channel', () => { return choose.message('Mocha', '#test', '.c this, that').then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastTarget, '#test'); }); }); it("should include user's name", () => { return choose.message('Mocha', '#test', '.choose this, that').then(() => { - assert(client.lastMessage.startsWith('Mocha: ')); + assert(client.lastMessage.startsWith('Mocha: '), 'Invalid username prefix'); }); }); }); @@ -106,7 +106,7 @@ describe('Choose', () => { describe('Comma Delimited List', () => { it('should choose from the list', () => { return choose.message('Mocha', '#test', '.choose that, that').then(() => { - assert.equal('Mocha: that', client.lastMessage); + assert.equal(client.lastMessage, 'Mocha: that'); }); }); }); @@ -114,7 +114,7 @@ describe('Choose', () => { describe('Space Delimited List', () => { it('should choose from the list', () => { return choose.message('Mocha', '#test', '.c commie commie').then(() => { - assert.equal('Mocha: commie', client.lastMessage); + assert.equal(client.lastMessage, 'Mocha: commie'); }); }); }); @@ -128,8 +128,8 @@ describe('Choose', () => { for (let i = 0; i < 20; i++) { choose.message('Mocha', '#test', `.c ${range}`); const value = client.lastMessage.replace('Mocha: ', ''); - assert(value >= lowerBound); - assert(value <= upperBound); + assert(value >= lowerBound, 'Value less than lower bound'); + assert(value <= upperBound, 'Value greater than upper bound'); } }); @@ -138,11 +138,10 @@ describe('Choose', () => { const upperBound = 5; const range = `${upperBound}-${lowerBound}`; - return choose.message('Mocha', '#test', `.c ${range}`).then(() => { const value = client.lastMessage.replace('Mocha: ', ''); - assert(value <= upperBound); - assert(value >= lowerBound); + assert(value >= lowerBound, 'Value less than lower bound'); + assert(value <= upperBound, 'Value greater than upper bound'); }); }); @@ -151,11 +150,10 @@ describe('Choose', () => { const upperBound = -5; const range = `${lowerBound}-${upperBound}`; - return choose.message('Mocha', '#test', `.c ${range}`).then(() => { const value = client.lastMessage.replace('Mocha: ', ''); - assert(value <= upperBound); - assert(value >= lowerBound); + assert(value >= lowerBound, 'Value less than lower bound'); + assert(value <= upperBound, 'Value greater than upper bound'); }); }); @@ -189,8 +187,8 @@ describe('Choose', () => { } } }).then(() => { - assert(lowerBoundChosen); - assert(upperBoundChosen); + assert(lowerBoundChosen, 'Lower bound not chosen (possible)'); + assert(upperBoundChosen, 'Upper bound not chosen (possible)'); }); }); }); diff --git a/test/commands/test_command.js b/test/commands/test_command.js index 6ca512e..ae0693e 100644 --- a/test/commands/test_command.js +++ b/test/commands/test_command.js @@ -15,22 +15,22 @@ describe('Command', () => { describe('Blacklist', () => { it('should block .ly links', () => { command.send('#test', 'Desch: http://bit.ly link'); - assert.equal('Blacklist triggered.', client.lastMessage); + assert.equal(client.lastMessage, 'Blacklist triggered.'); }); it('should block .lewd', () => { command.send('#test', 'Desch: .lewd'); - assert.equal('Blacklist triggered.', client.lastMessage); + assert.equal(client.lastMessage, 'Blacklist triggered.'); }); it('should block `xd`', () => { command.send('#test', 'Desch: xd'); - assert.equal('Blacklist triggered.', client.lastMessage); + assert.equal(client.lastMessage, 'Blacklist triggered.'); }); it('should not block xdcc', () => { command.send('#test', 'Desch: xdcc'); - assert.equal('Desch: xdcc', client.lastMessage); + assert.equal(client.lastMessage, 'Desch: xdcc'); }); }); }); diff --git a/test/commands/test_imgur.js b/test/commands/test_imgur.js index 12c6c31..5b01d7c 100644 --- a/test/commands/test_imgur.js +++ b/test/commands/test_imgur.js @@ -24,27 +24,27 @@ describe('Imgur', () => { describe('Triggers', () => { it('should activate anywhere in phrase with Gallery URL', () => { return imgur.message('Mocha', '#test0', `ARX-7 ${link}!`).then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should activate anywhere in phrase with Standard URL', () => { return imgur.message('Mocha', '#test', `ARX-7 ${standard}!`).then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should activate anywhere in phrase with Direct URL', () => { return imgur.message('Mocha', '#test4', `ARX-7 ${direct}!`).then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should log and handle malformed links', () => { return imgur.message('Mocha', '#test', `${malformed}`).catch(error => { - assert(error instanceof Error); - assert(error.message.startsWith('Imgur Info')); - assert.equal('Sorry, could not find Imgur info.', client.lastMessage); + assert(error instanceof Error, 'Incorrect Error returned'); + assert(error.message.startsWith('Imgur Info'), 'Incorrect Error message'); + assert.equal(client.lastMessage, 'Sorry, could not find Imgur info.'); }); }); }); @@ -52,13 +52,13 @@ describe('Imgur', () => { describe('General Usage', () => { it('should respond in correct channel', () => { return imgur.message('Mocha', '#test', link).then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastTarget, '#test'); }); }); it('should include [Imgur]', () => { return imgur.message('Mocha', '#test', link).then(() => { - assert(client.lastMessage.startsWith('[Imgur] ')); + assert(client.lastMessage.startsWith('[Imgur] '), 'Message not properly tagged'); }); }); }); @@ -72,14 +72,14 @@ describe('Imgur', () => { it('should display correct title', () => { return imgur.message('Mocha', '#test', link).then(() => { - assert(client.lastMessage.includes(title)); + assert(client.lastMessage.includes(title), 'Message does not include title'); }); }); it('should include view count', () => { return imgur.message('Mocha', '#test', link).then(() => { const views = client.lastMessage.split('Views: ')[1]; - assert((parseInt(views, 10) > 300)); + assert((parseInt(views, 10) > 300), 'Message contains invalid view amount'); }); }); }); diff --git a/test/commands/test_order.js b/test/commands/test_order.js index fe5a0a5..11c16dc 100644 --- a/test/commands/test_order.js +++ b/test/commands/test_order.js @@ -22,37 +22,37 @@ describe('Order', () => { describe('Triggers', () => { it('should respond to .o trigger', () => { return order.message('Mocha', '#test', '.o this, that').then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should respond to .order trigger', () => { return order.message('Mocha', '#test', '.order one, two').then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should not respond to .orde trigger', () => { return order.message('Mocha', '#test', '.orde one, two').then(() => { - assert.equal(null, client.lastMessage); + assert.equal(client.lastMessage, null); }); }); it('should activate in beginning of phrase', () => { return order.message('Mocha', '#test', '.o this, that').then(() => { - assert.notEqual(null, client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should not activate in middle of phrase', () => { return order.message('Mocha', '#test', 'test .o this, that').then(() => { - assert.equal(null, client.lastMessage); + assert.equal(client.lastMessage, null); }); }); it('should not activate with an empty list', () => { return order.message('Mocha', '#test', '.o').then(() => { - assert.equal(null, client.lastMessage); + assert.equal(client.lastMessage, null); }); }); @@ -64,19 +64,19 @@ describe('Order', () => { ]; return order.message('Mocha', '#test', '.o ,, , ,,').then(() => { - assert(outputs.includes(client.lastMessage)); + assert(outputs.includes(client.lastMessage), 'Output not found in valid list'); }); }); it('should activate with a single comma', () => { return order.message('Mocha', '#test', '.o ,').then(() => { - assert.equal('Mocha: ,', client.lastMessage); + assert.equal(client.lastMessage, 'Mocha: ,'); }); }); it('should be case insensitive', () => { return order.message('Mocha', '#test', '.ORDER A').then(() => { - assert.equal('Mocha: A', client.lastMessage); + assert.equal(client.lastMessage, 'Mocha: A'); }); }); }); @@ -84,7 +84,7 @@ describe('Order', () => { describe('General Usage', () => { it('should respond in correct channel', () => { return order.message('Mocha', '#test', '.o this, that').then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastTarget, '#test'); }); }); @@ -105,8 +105,8 @@ describe('Order', () => { return order.message('Mocha', '#test', `.o ${range}`).then(() => { const values = client.lastMessage.replace('Mocha: ', '').split(', '); values.forEach(val => { - assert(val >= lowerBound); - assert(val <= upperBound); + assert(val >= lowerBound, 'Value less than lower bound'); + assert(val <= upperBound, 'Value greater than upper bound'); }); }); }); @@ -118,7 +118,7 @@ describe('Order', () => { ]; return order.message('Mocha', '#test', '.o 6-5').then(() => { - assert(expected.includes(client.lastMessage)); + assert(expected.includes(client.lastMessage), 'Output not found in valid list'); }); }); @@ -129,7 +129,7 @@ describe('Order', () => { ]; return order.message('Mocha', '#test', '.o -5--6').then(() => { - assert(expected.includes(client.lastMessage)); + assert(expected.includes(client.lastMessage), 'Output not found in valid list'); }); }); @@ -140,15 +140,15 @@ describe('Order', () => { return order.message('Mocha', '#test', `.o ${range}`).then(() => { const values = client.lastMessage.replace('Mocha: ', '').split(', '); - assert(values.includes(lowerBound.toString())); - assert(values.includes(upperBound.toString())); + assert(values.includes(lowerBound.toString()), 'Lowerbound not included'); + assert(values.includes(upperBound.toString()), 'Upperbound not included'); }); }); it('should only include a max of 20 items', () => { return order.message('Mocha', '#test', '.o 1-25').then(() => { - assert.equal(21, client.lastMessage.split(', ').length); - assert(client.lastMessage.includes('and some more...')); + assert.equal(21, client.lastMessage.split(', ').length, 'More results than expected'); + assert(client.lastMessage.includes('and some more...'), "'More' not included"); }); }); @@ -156,7 +156,7 @@ describe('Order', () => { return order.message('Mocha', '#test', '.o 1-2048').then(() => { let msg = client.lastMessage.replace('Mocha: ', ''); msg = msg.replace(', and some more...', ''); - msg.split(', ').forEach(val => assert(val <= 1024)); + msg.split(', ').forEach(val => assert(val <= 1024, 'Value over 1024')); }); }); @@ -181,7 +181,7 @@ describe('Order', () => { ]; return order.message('Mocha', '#test', '.o a, b c, d').then(() => { - assert(expected.includes(client.lastMessage)); + assert(expected.includes(client.lastMessage), 'Value not in expected list'); }); }); @@ -201,7 +201,7 @@ describe('Order', () => { return new Promise(resolve => { for (let i = 0; i < runs; i++) { order.message('Mocha', '#test', '.o a b c'); - assert(expected.includes(client.lastMessage)); + assert(expected.includes(client.lastMessage), 'Value not in expected list'); results.push(client.lastMessage); // Still can fail, but has a [(0.167^20) * 100]% chance of it @@ -213,7 +213,7 @@ describe('Order', () => { } } }).then(() => { - assert(uniq(results).length > 1); + assert(uniq(results).length > 1, 'Results not randomized (possible)'); }); }); }); diff --git a/test/commands/test_reply.js b/test/commands/test_reply.js index 1fc994b..b6157ca 100644 --- a/test/commands/test_reply.js +++ b/test/commands/test_reply.js @@ -12,106 +12,60 @@ describe('Reply', () => { client.resetLog(); }); - it('should not respond to invalid triggers', () => { - return reply.message('Mocha', '#test', 'Hi Desch').then(() => { - assert(!client.lastMessage); - }); - }); - - describe('> ping', () => { - it('should respond', () => { + describe('Triggers', () => { + it('should respond to `ping`', () => { return reply.message('Mocha', '#test', 'ping').then(() => { - assert.equal('pong', client.lastMessage); + assert.equal(client.lastMessage, 'pong'); }); }); - it('should respond in correct channel', () => { - return reply.message('Mocha', '#test', 'ping').then(() => { - assert.equal('#test', client.lastTarget); - }); - }); - }); - - describe('> bot respond', () => { - it('should respond', () => { + it('should respond to `bot respond`', () => { return reply.message('Mocha', '#test', 'bot respond').then(() => { - assert.equal("I'm a pretty stupid bot.", client.lastMessage); + assert.equal(client.lastMessage, "I'm a pretty stupid bot."); }); }); - it('should respond in correct channel', () => { - return reply.message('Mocha', '#test', 'bot respond').then(() => { - assert.equal('#test', client.lastTarget); - }); - }); - }); - - describe('> bot be nice', () => { - it('should respond', () => { - return reply.message('Mocha', '#test', 'bot be nice').then(() => { - assert.equal('sorry :(', client.lastMessage); - }); - }); - - it('should respond in correct channel', () => { + it('should respond to `bot be nice`', () => { return reply.message('Mocha', '#test', 'bot be nice').then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastMessage, 'sorry :('); }); }); - }); - describe('> gj bot', () => { - it('should respond', () => { + it('should respond to `gj bot`', () => { return reply.message('Mocha', '#test', 'gj bot').then(() => { - assert.equal('thx', client.lastMessage); + assert.equal(client.lastMessage, 'thx'); }); }); - it('should respond in correct channel', () => { - return reply.message('Mocha', '#test', 'gj bot').then(() => { - assert.equal('#test', client.lastTarget); - }); - }); - }); - - describe('> thx bot', () => { - it('should respond', () => { - return reply.message('Mocha', '#test', 'thx bot').then(() => { - assert.equal('np', client.lastMessage); - }); - }); - - it('should respond in correct channel', () => { + it('should respond to `thx bot`', () => { return reply.message('Mocha', '#test', 'thx bot').then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastMessage, 'np'); }); }); - }); - describe('> bot pls', () => { - it('should respond', () => { + it('should respond to `bot pls`', () => { return reply.message('Mocha', '#test', 'bot pls').then(() => { - assert.equal('( ¬‿¬)', client.lastMessage); + assert.equal(client.lastMessage, '( ¬‿¬)'); }); }); - it('should respond in correct channel', () => { - return reply.message('Mocha', '#test', 'bot pls').then(() => { - assert.equal('#test', client.lastTarget); + it('should respond to `!bugreport`', () => { + return reply.message('Mocha', '#test', '!bugreport').then(() => { + assert.equal(client.lastMessage, 'Hi! To file a feature request or bug, go to: https://github.com/IanMitchell/ARX-7'); }); }); - }); - describe('> !bugreport', () => { - it('should respond', () => { - return reply.message('Mocha', '#test', '!bugreport').then(() => { - assert.equal('Hi! To file a feature request or bug, go to: https://github.com/IanMitchell/ARX-7', client.lastMessage); + it('should not respond to invalid triggers', () => { + return reply.message('Mocha', '#test', 'Hi Desch').then(() => { + assert.equal(client.lastMessage, null); }); }); + }); + describe('General', () => { it('should respond in correct channel', () => { - return reply.message('Mocha', '#test', '!bugreport').then(() => { - assert.equal('#test', client.lastTarget); + return reply.message('Mocha', '#test', 'bot pls').then(() => { + assert.equal(client.lastTarget, '#test'); }); }); }); diff --git a/test/commands/test_time.js b/test/commands/test_time.js index adbc211..bc13096 100644 --- a/test/commands/test_time.js +++ b/test/commands/test_time.js @@ -23,19 +23,19 @@ describe('Time', () => { describe('Triggers', () => { it('should activate in beginning of phrase', () => { return time.message('Mocha', '#test', '.time JST').then(() => { - assert.notEqual(null, client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should not activate in middle of phrase', () => { return time.message('Mocha', '#test', 'test .time JST').then(() => { - assert.equal(null, client.lastMessage); + assert.equal(client.lastMessage, null); }); }); it('should handle incorrect timezones', () => { return time.message('Mocha', '#test', `.time JET`).then(() => { - assert(client.lastMessage.endsWith(timezone(new Date(), TIME_FORMAT))); + assert(client.lastMessage.endsWith(timezone(new Date(), TIME_FORMAT)), 'Incorrect Timezone Ending'); }); }); @@ -49,13 +49,13 @@ describe('Time', () => { describe('General Usage', () => { it('should respond in correct channel', () => { return time.message('Mocha', '#test', '.time JST').then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastTarget, '#test'); }); }); it("should include user's name", () => { return time.message('Mocha', '#test', '.time JST').then(() => { - assert(client.lastMessage.startsWith('Mocha: ')); + assert(client.lastMessage.startsWith('Mocha: '), 'Does not contain username'); }); }); @@ -64,7 +64,7 @@ describe('Time', () => { return time.message('Mocha', '#test', '.time JST').then(() => { const currentTime = timezone(jst, TIME_FORMAT).split(' GMT')[0]; - assert(client.lastMessage.includes(currentTime)); + assert(client.lastMessage.includes(currentTime), 'Current time incorrect'); }); }); @@ -73,7 +73,7 @@ describe('Time', () => { return time.message('Mocha', '#test', '.time jst').then(() => { const currentTime = timezone(jst, TIME_FORMAT).split(' GMT')[0]; - assert(client.lastMessage.includes(currentTime)); + assert(client.lastMessage.includes(currentTime), 'Current time incorrect'); }); }); }); diff --git a/test/commands/test_twitter.js b/test/commands/test_twitter.js index ca9e9aa..67366d9 100644 --- a/test/commands/test_twitter.js +++ b/test/commands/test_twitter.js @@ -18,15 +18,15 @@ describe('Twitter', () => { describe('Triggers', () => { it('should activate anywhere in phrase', () => { return twitter.message('Mocha', '#test', `Tweet ${link}!`).then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should log and handle malformed links', () => { return twitter.message('Mocha', '#test', `${malformed}`).catch(error => { - assert(error instanceof Error); - assert(error.message.startsWith('Twitter Info')); - assert.equal('Sorry, could not find Twitter info.', client.lastMessage); + assert(error instanceof Error, 'Incorrect Error returned'); + assert(error.message.startsWith('Twitter Info'), 'Incorrect Error message'); + assert.equal(client.lastMessage, 'Sorry, could not find Twitter info.'); }); }); }); @@ -34,13 +34,13 @@ describe('Twitter', () => { describe('General Usage', () => { it('should respond in correct channel', () => { return twitter.message('Mocha', '#test', link).then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastTarget, '#test'); }); }); it('should include [Twitter]', () => { return twitter.message('Mocha', '#test', link).then(() => { - assert(client.lastMessage.startsWith('[Twitter]: ')); + assert(client.lastMessage.startsWith('[Twitter]: '), 'Message not properly tagged'); }); }); }); @@ -50,14 +50,14 @@ describe('Twitter', () => { return twitter.message('Mocha', '#test', link).then(() => { const tweet = client.lastMessage.toLowerCase(); const expected = ' | By Ian Mitchell (@IanMitchel1)'.toLowerCase(); - assert(tweet.includes(expected)); + assert(tweet.includes(expected), 'Incorrect tweet information'); }); }); it('should handle special characters', () => { return twitter.message('Mocha', '#test', link).then(() => { const tweet = client.lastMessage.toLowerCase(); - assert((tweet.includes('<') && tweet.includes('>'))); + assert((tweet.includes('<') && tweet.includes('>')), 'Message missing special characters'); }); }); }); diff --git a/test/commands/test_youtube.js b/test/commands/test_youtube.js index 40f44f7..7447eb3 100644 --- a/test/commands/test_youtube.js +++ b/test/commands/test_youtube.js @@ -18,51 +18,51 @@ describe('YouTube', () => { describe('Triggers', () => { it('should respond to .yt trigger', () => { return youtube.message('Mocha', '#test', '.yt FMP!').then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should respond to .youtube trigger', () => { return youtube.message('Mocha', '#test', '.youtube FMP!').then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should not respond to .youtub trigger', () => { return youtube.message('Mocha', '#test', '.youtub FMP!').then(() => { - assert.equal(null, client.lastMessage); + assert.equal(client.lastMessage, null); }); }); it('should activate in beginning of phrase', () => { return youtube.message('Mocha', '#test', '.yt FMP!').then(() => { - assert.notEqual(null, client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should not activate in middle of phrase', () => { return youtube.message('Mocha', '#test', 'test .yt FMP!').then(() => { - assert.equal(null, client.lastMessage); + assert.equal(client.lastMessage, null); }); }); it('should activate lookup anywhere in phrase', () => { return youtube.message('Mocha', '#test', `Cool ${link} vid`).then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should be case insensitive', () => { return youtube.message('Mocha', '#test', '.YT A').then(() => { - assert(client.lastMessage); + assert.notEqual(client.lastMessage, null); }); }); it('should log and handle malformed links', () => { return youtube.message('Mocha', '#test', `${malformed}`).catch(error => { - assert(error instanceof Error); - assert(error.message.startsWith('YouTube Info')); - assert.equal('Sorry, could not find YouTube info.', client.lastMessage); + assert(error instanceof Error, 'Incorrect Error returned'); + assert(error.message.startsWith('YouTube Info'), 'Incorrect Error message'); + assert.equal(client.lastMessage, 'Sorry, could not find YouTube info.'); }); }); }); @@ -70,13 +70,13 @@ describe('YouTube', () => { describe('General Usage', () => { it('should respond in correct channel', () => { return youtube.message('Mocha', '#test', '.yt End Credits').then(() => { - assert.equal('#test', client.lastTarget); + assert.equal(client.lastTarget, '#test'); }); }); it('should include [YouTube]', () => { return youtube.message('Mocha', '#test2', '.yt End Credits').then(() => { - assert(client.lastMessage.startsWith('[YouTube] ')); + assert(client.lastMessage.startsWith('[YouTube] '), 'Message not properly tagged'); }); }); }); diff --git a/test/test_arx7.js b/test/test_arx7.js index e7925cc..c8f37ef 100644 --- a/test/test_arx7.js +++ b/test/test_arx7.js @@ -36,32 +36,32 @@ describe('ARX-7', () => { it('should identify on connect', () => { arx7.connect(); assert.equal(client.lastTarget, 'NickServ'); - assert.equal(client.lastMessage, `identify password`); + assert.equal(client.lastMessage, 'identify password'); }); it('should join channels after identify', () => { assert.equal(client.lastMessage, null); assert.equal(client.channelLog.length, 0); arx7.connect(); - assert(client.lastMessage); - assert(client.channelLog.length > 0); + assert.notEqual(client.lastMessage, null); + assert.notEqual(client.channelLog.length, 0, 'Channel log is empty'); }); it('should handle uppercase channel names', () => { arx7.connect(); - assert(client.channelLog.includes('#arx-7')); + assert(client.channelLog.includes('#arx-7'), 'Channel log missing #arx-7'); }); it('should join +k channels', () => { arx7.connect(); - assert(client.channelLog.includes('#arbalest sagara')); + assert(client.channelLog.includes('#arbalest sagara'), 'Channl log missing join'); }); }); describe('Responds to CTCP Version', () => { it('should respond with VERSION', () => { arx7.version('Mocha', 'ARX-7'); - assert(client.lastMessage.includes('VERSION')); + assert(client.lastMessage.includes('VERSION'), 'VERSION not in response'); assert.equal(client.lastType, 'notice'); }); }); @@ -69,22 +69,22 @@ describe('ARX-7', () => { describe('Responds to Messages', () => { it('should send message to plugins', () => { arx7.message('Mocha', '#arx-7', '.c 1 2 3'); - arx7.commands.forEach(command => assert.equal(command.log.length, 1)); + arx7.commands.forEach(command => assert.equal(command.log.length, 1, 'Command log missing response')); }); // Aoi-chan Test it('should send message to plugins for non-lowercase channel', () => { arx7.join('#Some-Channel', 'ARX-7'); arx7.message('Mocha', '#Some-Channel', '.c 1 2 3'); - assert(arx7.commands[0].log.includes('.c 1 2 3')); + assert(arx7.commands[0].log.includes('.c 1 2 3'), 'Command log missing response'); }); it('should channel-restrict plugins', () => { arx7.message('Mocha', '#arbalest', '.c 1 2 3'); - assert(arx7.commands[0].log.includes('.c 1 2 3')); + assert(arx7.commands[0].log.includes('.c 1 2 3'), 'Command log missing choose'); for (let i = 1; i < arx7.commands.length; i++) { - assert.equal(arx7.commands[i].log.length, 0); + assert.equal(arx7.commands[i].log.length, 0, 'Command log is not empty'); } }); }); @@ -104,14 +104,14 @@ describe('ARX-7', () => { it('should respond to Query', () => { return arx7.message('Mocha', 'ARX-7', 'Hi').then(() => { - assert(client.lastMessage); - assert(client.lastMessage.includes('Desch, Jukey, Aoi-chan')); + assert(client.lastMessage, 'Query response incorrect'); + assert(client.lastMessage.includes('Desch, Jukey, Aoi-chan'), 'Query admin list incorrect'); }); }); it('should respond to Admin Query', () => { return arx7.message('Desch', 'ARX-7', 'Hi').then(() => { - assert(client.lastMessage.includes('Command not recognized')); + assert(client.lastMessage.includes('Command not recognized'), 'Invalid query admin response'); }); }); @@ -185,14 +185,18 @@ describe('ARX-7', () => { }); describe('Responds to Kicks and Bans', () => { - // TODO: Fix setTimeout - // it('should attempt to rejoin after kicks in 3 seconds', () => { - // arx7.kick('#test', 'ARX-7', 'Mocha', 'Testing'); - // assert.equal(null, client.getLastChannel()); - // setTimeout(() => { - // assert.equal('#test', client.getLastChannel()); - // }, 1000 * 3); - // }); + // Arrow functions prevent us from using `this.timeout` + it('should attempt to rejoin after kicks in 3 seconds', function() { + this.timeout(4500); + arx7.kick('#test', 'ARX-7', 'Mocha', 'Testing'); + assert.equal(null, client.getLastChannel()); + return new Promise(resolve => { + setTimeout(() => { + assert.equal('#test', client.getLastChannel()); + resolve(); + }, 1000 * 4); + }); + }); it('should attempt to rejoin after bans in 3 minutes');