Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Commit

Permalink
Test indirect references to Harmony with config enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Throne3d committed Apr 28, 2018
1 parent cee1a4c commit 8828e4b
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion test/test-parsing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { expect, Discord } = require('./imports');
const { expect, sinon, Discord } = require('./imports');
const { createBot } = require('./helpers');

describe('Harmony', function() {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 8828e4b

Please sign in to comment.