diff --git a/test/test-parsing.js b/test/test-parsing.js index 4304de4..d331bda 100644 --- a/test/test-parsing.js +++ b/test/test-parsing.js @@ -1,4 +1,4 @@ -const { expect, Discord } = require('./imports'); +const { expect, sinon, Discord } = require('./imports'); const { createBot } = require('./helpers'); describe('Harmony', function() { @@ -49,6 +49,86 @@ describe('Harmony', function() { expect(text).to.equal('test command'); }); }); + + context('with unclear un-mention', function() { + beforeEach(function() { + const bot = this.bot; + const botUser = bot.client.user; + const botMember = bot.getMyGuildMemberIn(bot.client.guild); + this.user = bot.client.newUser(); + this.message = bot.client.channel.newMessage({ + content: `${botMember.displayName}, here is a test`, + mentions: new Discord.Collection([]), + author: this.user, + }); + this.messageWithoutName = 'here is a test'; + this.promptMessage = bot.client.channel.newMessage({ + content: 'do you want me to respond to that?', + author: botUser, + }); + }); + + it('resolves negatively without config', async function() { + // leave user with default settings (wantsMoreCheck is false) + const { bot, message } = this; + + return bot.checkMessageAddressesMe(message).then(([addressesMe, text]) => { + expect(addressesMe).to.equal(false); + expect(text).to.be.undefined; + }); + }); + + it('checks with config and handles time out', async function() { + const { bot, message, promptMessage, user } = this; + await bot.persistenceManager.setUserData(user, { wantsMoreCheck: true }); + + message.reply = sinon.stub().withArgs('do you want me to respond to that?').resolves(promptMessage); + bot.emojiPrompt = sinon.stub().callsFake(function(prompt, options, target) { + expect(prompt).to.equal(promptMessage); + expect(options).to.deep.equal(['✅', '❎']); + expect(target).to.equal(user); + + return Promise.resolve(new Discord.Collection([[]])); + }); + + return bot.checkMessageAddressesMe(message).then(([addressesMe, text]) => { + expect(addressesMe).to.equal(false); + expect(text).to.be.undefined; + }); + }); + + it('can resolve negatively to check with config', async function() { + const { bot, message, promptMessage, user } = this; + await bot.persistenceManager.setUserData(user, { wantsMoreCheck: true }); + + message.reply = sinon.stub().resolves(promptMessage); + bot.emojiPrompt = sinon.stub().callsFake(function(prompt) { + const negativeReaction = prompt.newReaction('❎', 2, true); + return Promise.resolve(new Discord.Collection([['❎', negativeReaction]])); + }); + + return bot.checkMessageAddressesMe(message).then(([addressesMe, text]) => { + expect(addressesMe).to.equal(false); + expect(text).to.be.undefined; + }); + }); + + it('can resolve positively to check with config', async function() { + const { bot, message, messageWithoutName, promptMessage, user } = this; + await bot.persistenceManager.setUserData(user, { wantsMoreCheck: true }); + + message.reply = sinon.stub().resolves(promptMessage); + bot.emojiPrompt = sinon.stub().callsFake(function(prompt) { + const negativeReaction = prompt.newReaction('✅', 2, true); + return Promise.resolve(new Discord.Collection([['✅', negativeReaction]])); + }); + + return bot.checkMessageAddressesMe(message).then(([addressesMe, text]) => { + expect(addressesMe).to.equal(true); + expect(text).to.equal(messageWithoutName); + }); + }); + }); }); context.skip('in DM');