Skip to content

Commit

Permalink
Add tests for custom IRC output, fix to connect in Discord tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Throne3d committed Mar 26, 2017
1 parent 756505f commit dfe13b1
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions test/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ describe('Bot', function () {
it('should not replace unmatched patterns', function () {
const formatDiscord = '{$unmatchedPattern} stays intact: {$author} {$text}';
const bot = new Bot({ ...configMsgFormatDefault, formatDiscord });
bot.connect();

const username = 'testuser';
const msg = 'test message';
Expand All @@ -454,11 +455,137 @@ describe('Bot', function () {
it('should respect custom formatting for Discord', function () {
const formatDiscord = '<{$author}> {$ircChannel} => {$discordChannel}: {$text}';
const bot = new Bot({ ...configMsgFormatDefault, formatDiscord });
bot.connect();

const username = 'test';
const msg = 'test @user <#1234>';
const expected = `<test> #irc => #discord: ${msg}`;
bot.sendToDiscord(username, '#irc', msg);
this.sendMessageStub.should.have.been.calledWith(expected);
});

it('should successfully send messages with default config', function () {
this.bot = new Bot(configMsgFormatDefault);
this.bot.connect();

this.bot.sendToDiscord('testuser', '#irc', 'test message');
this.sendMessageStub.should.have.been.calledOnce;

const guild = createGuildStub();
const message = {
content: 'test message',
mentions: { users: [] },
channel: {
name: 'discord'
},
author: {
username: 'otherauthor',
id: 'not bot id'
},
guild
};

this.bot.sendToIRC(message);
this.sendMessageStub.should.have.been.calledOnce;
});

it('should not replace unmatched patterns', function () {
const formatDiscord = '{$unmatchedPattern} stays intact: {$author} {$text}';
this.bot = new Bot({ ...configMsgFormatDefault, formatDiscord });
this.bot.connect();

const username = 'testuser';
const msg = 'test message';
const expected = `{$unmatchedPattern} stays intact: ${username} ${msg}`;
this.bot.sendToDiscord(username, '#irc', msg);
this.sendMessageStub.should.have.been.calledWith(expected);
});

it('should respect custom formatting for Discord', function () {
const formatDiscord = '<{$author}> {$ircChannel} => {$discordChannel}: {$text}';
this.bot = new Bot({ ...configMsgFormatDefault, formatDiscord });
this.bot.connect();

const username = 'test';
const msg = 'test @user <#1234>';
const expected = `<test> #irc => #discord: ${msg}`;
this.bot.sendToDiscord(username, '#irc', msg);
this.sendMessageStub.should.have.been.calledWith(expected);
});

it('should respect custom formatting for regular IRC output', function () {
const formatIRCText = '<{$nickname}> {$discordChannel} => {$ircChannel}: {$text}';
this.bot = new Bot({ ...configMsgFormatDefault, formatIRCText });
this.bot.connect();

const guild = createGuildStub();
const message = {
content: 'test message',
mentions: { users: [] },
channel: {
name: 'discord'
},
author: {
username: 'testauthor',
id: 'not bot id'
},
guild
};
const expected = '<testauthor> #discord => #irc: test message';

this.bot.sendToIRC(message);
ClientStub.prototype.say.should.have.been.calledWith('#irc', expected);
});

it('should respect custom formatting for commands in IRC output', function () {
const formatCommandPrelude = '{$nickname} from {$discordChannel} sent command to {$ircChannel}:';
this.bot = new Bot({ ...configMsgFormatDefault, formatCommandPrelude });
this.bot.connect();

const text = '!testcmd';
const guild = createGuildStub();
const message = {
content: text,
mentions: { users: [] },
channel: {
name: 'discord'
},
author: {
username: 'testauthor',
id: 'not bot id'
},
guild
};
const expected = 'testauthor from #discord sent command to #irc:';

this.bot.sendToIRC(message);
ClientStub.prototype.say.getCall(0).args.should.deep.equal(['#irc', expected]);
ClientStub.prototype.say.getCall(1).args.should.deep.equal(['#irc', text]);
});

it('should respect custom formatting for attachment URLs in IRC output', function () {
const formatURLAttachment = '<{$nickname}> {$discordChannel} => {$ircChannel}, attachment: {$attachmentURL}';
this.bot = new Bot({ ...configMsgFormatDefault, formatURLAttachment });
this.bot.connect();

const attachmentUrl = 'https://image/url.jpg';
const guild = createGuildStub();
const message = {
content: '',
mentions: { users: [] },
attachments: createAttachments(attachmentUrl),
channel: {
name: 'discord'
},
author: {
username: 'otherauthor',
id: 'not bot id'
},
guild
};

this.bot.sendToIRC(message);
const expected = `<otherauthor> #discord => #irc, attachment: ${attachmentUrl}`;
ClientStub.prototype.say.should.have.been.calledWith('#irc', expected);
});
});

0 comments on commit dfe13b1

Please sign in to comment.