Skip to content

Commit f0ffc26

Browse files
committed
Don't mutate given param, remove unnecessary guild constant
1 parent e47d8e3 commit f0ffc26

File tree

1 file changed

+24
-50
lines changed

1 file changed

+24
-50
lines changed

test/bot.test.js

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Bot', function () {
4545

4646
this.addUser = function (user, member = null) {
4747
const userObj = new discord.User(this.bot.discord, user);
48-
const guildMember = Object.assign(member || user, { user: userObj });
48+
const guildMember = Object.assign({}, member || user, { user: userObj });
4949
guildMember.nick = guildMember.nickname; // nick => nickname in Discord API
5050
const memberObj = new discord.GuildMember(this.guild, guildMember);
5151
this.guild.members.set(userObj.id, memberObj);
@@ -139,7 +139,6 @@ describe('Bot', function () {
139139
const text = 'testmessage';
140140
const newConfig = { ...config, ircNickColor: false };
141141
const bot = new Bot(newConfig);
142-
const guild = this.guild;
143142
bot.connect();
144143
const message = {
145144
content: text,
@@ -151,7 +150,7 @@ describe('Bot', function () {
151150
username: 'otherauthor',
152151
id: 'not bot id'
153152
},
154-
guild
153+
guild: this.guild
155154
};
156155

157156
bot.sendToIRC(message);
@@ -161,7 +160,6 @@ describe('Bot', function () {
161160

162161
it('should send correct messages to irc', function () {
163162
const text = 'testmessage';
164-
const guild = this.guild;
165163
const message = {
166164
content: text,
167165
mentions: { users: [] },
@@ -172,7 +170,7 @@ describe('Bot', function () {
172170
username: 'otherauthor',
173171
id: 'not bot id'
174172
},
175-
guild
173+
guild: this.guild
176174
};
177175

178176
this.bot.sendToIRC(message);
@@ -183,7 +181,6 @@ describe('Bot', function () {
183181

184182
it('should send to IRC channel mapped by discord channel ID if available', function () {
185183
const text = 'test message';
186-
const guild = this.guild;
187184
const message = {
188185
content: text,
189186
mentions: { users: [] },
@@ -195,7 +192,7 @@ describe('Bot', function () {
195192
username: 'test',
196193
id: 'not bot id'
197194
},
198-
guild
195+
guild: this.guild
199196
};
200197

201198
// Wrap it in colors:
@@ -207,7 +204,6 @@ describe('Bot', function () {
207204

208205
it('should send to IRC channel mapped by discord channel name if ID not available', function () {
209206
const text = 'test message';
210-
const guild = this.guild;
211207
const message = {
212208
content: text,
213209
mentions: { users: [] },
@@ -219,7 +215,7 @@ describe('Bot', function () {
219215
username: 'test',
220216
id: 'not bot id'
221217
},
222-
guild
218+
guild: this.guild
223219
};
224220

225221
// Wrap it in colors:
@@ -231,7 +227,6 @@ describe('Bot', function () {
231227

232228
it('should send attachment URL to IRC', function () {
233229
const attachmentUrl = 'https://image/url.jpg';
234-
const guild = this.guild;
235230
const message = {
236231
content: '',
237232
mentions: { users: [] },
@@ -243,7 +238,7 @@ describe('Bot', function () {
243238
username: 'otherauthor',
244239
id: 'not bot id'
245240
},
246-
guild
241+
guild: this.guild
247242
};
248243

249244
this.bot.sendToIRC(message);
@@ -254,7 +249,6 @@ describe('Bot', function () {
254249
it('should send text message and attachment URL to IRC if both exist', function () {
255250
const text = 'Look at this cute cat picture!';
256251
const attachmentUrl = 'https://image/url.jpg';
257-
const guild = this.guild;
258252
const message = {
259253
content: text,
260254
attachments: createAttachments(attachmentUrl),
@@ -266,7 +260,7 @@ describe('Bot', function () {
266260
username: 'otherauthor',
267261
id: 'not bot id'
268262
},
269-
guild
263+
guild: this.guild
270264
};
271265

272266
this.bot.sendToIRC(message);
@@ -279,7 +273,6 @@ describe('Bot', function () {
279273
});
280274

281275
it('should not send an empty text message with an attachment to IRC', function () {
282-
const guild = this.guild;
283276
const message = {
284277
content: '',
285278
attachments: createAttachments('https://image/url.jpg'),
@@ -291,7 +284,7 @@ describe('Bot', function () {
291284
username: 'otherauthor',
292285
id: 'not bot id'
293286
},
294-
guild
287+
guild: this.guild
295288
};
296289

297290
this.bot.sendToIRC(message);
@@ -300,13 +293,12 @@ describe('Bot', function () {
300293
});
301294

302295
it('should not send its own messages to irc', function () {
303-
const guild = this.guild;
304296
const message = {
305297
author: {
306298
username: 'bot',
307299
id: this.bot.discord.user.id
308300
},
309-
guild
301+
guild: this.guild
310302
};
311303

312304
this.bot.sendToIRC(message);
@@ -315,7 +307,6 @@ describe('Bot', function () {
315307

316308
it('should not send messages to irc if the channel isn\'t in the channel mapping',
317309
function () {
318-
const guild = this.guild;
319310
const message = {
320311
channel: {
321312
name: 'wrongdiscord'
@@ -324,7 +315,7 @@ describe('Bot', function () {
324315
username: 'otherauthor',
325316
id: 'not bot id'
326317
},
327-
guild
318+
guild: this.guild
328319
};
329320

330321
this.bot.sendToIRC(message);
@@ -333,7 +324,6 @@ describe('Bot', function () {
333324

334325
it('should parse text from discord when sending messages', function () {
335326
const text = '<#1234>';
336-
const guild = this.guild;
337327
const message = {
338328
content: text,
339329
mentions: { users: [] },
@@ -344,7 +334,7 @@ describe('Bot', function () {
344334
username: 'test',
345335
id: 'not bot id'
346336
},
347-
guild
337+
guild: this.guild
348338
};
349339

350340
// Wrap it in colors:
@@ -356,7 +346,6 @@ describe('Bot', function () {
356346

357347
it('should use #deleted-channel when referenced channel fails to exist', function () {
358348
const text = '<#1235>';
359-
const guild = this.guild;
360349
const message = {
361350
content: text,
362351
mentions: { users: [] },
@@ -367,7 +356,7 @@ describe('Bot', function () {
367356
username: 'test',
368357
id: 'not bot id'
369358
},
370-
guild
359+
guild: this.guild
371360
};
372361

373362
// Discord displays "#deleted-channel" if channel doesn't exist (e.g. <#1235>)
@@ -379,7 +368,6 @@ describe('Bot', function () {
379368
});
380369

381370
it('should convert user mentions from discord', function () {
382-
const guild = this.guild;
383371
const message = {
384372
mentions: {
385373
users: [{
@@ -388,14 +376,13 @@ describe('Bot', function () {
388376
}],
389377
},
390378
content: '<@123> hi',
391-
guild
379+
guild: this.guild
392380
};
393381

394382
this.bot.parseText(message).should.equal('@testuser hi');
395383
});
396384

397385
it('should convert user nickname mentions from discord', function () {
398-
const guild = this.guild;
399386
const message = {
400387
mentions: {
401388
users: [{
@@ -404,7 +391,7 @@ describe('Bot', function () {
404391
}],
405392
},
406393
content: '<@!123> hi',
407-
guild
394+
guild: this.guild
408395
};
409396

410397
this.bot.parseText(message).should.equal('@testuser hi');
@@ -473,7 +460,6 @@ describe('Bot', function () {
473460

474461
it('should hide usernames for commands to IRC', function () {
475462
const text = '!test command';
476-
const guild = this.guild;
477463
const message = {
478464
content: text,
479465
mentions: { users: [] },
@@ -484,7 +470,7 @@ describe('Bot', function () {
484470
username: 'test',
485471
id: 'not bot id'
486472
},
487-
guild
473+
guild: this.guild
488474
};
489475

490476
this.bot.sendToIRC(message);
@@ -509,7 +495,6 @@ describe('Bot', function () {
509495
const bot = new Bot(newConfig);
510496
const id = 'not bot id';
511497
const nickname = 'discord-nickname';
512-
const guild = this.guild;
513498
this.guild.members.set(id, { nickname });
514499
bot.connect();
515500
const message = {
@@ -522,7 +507,7 @@ describe('Bot', function () {
522507
username: 'otherauthor',
523508
id
524509
},
525-
guild
510+
guild: this.guild
526511
};
527512

528513
bot.sendToIRC(message);
@@ -555,7 +540,6 @@ describe('Bot', function () {
555540
it('should convert role mentions from discord', function () {
556541
this.addRole({ name: 'example-role', id: '12345' });
557542
const text = '<@&12345>';
558-
const guild = this.guild;
559543
const message = {
560544
content: text,
561545
mentions: { users: [] },
@@ -566,7 +550,7 @@ describe('Bot', function () {
566550
username: 'test',
567551
id: 'not bot id'
568552
},
569-
guild
553+
guild: this.guild
570554
};
571555

572556
this.bot.parseText(message).should.equal('@example-role');
@@ -576,7 +560,6 @@ describe('Bot', function () {
576560
this.addRole({ name: 'example-role', id: '12345' });
577561

578562
const text = '<@&12346>';
579-
const guild = this.guild;
580563
const message = {
581564
content: text,
582565
mentions: { users: [] },
@@ -587,7 +570,7 @@ describe('Bot', function () {
587570
username: 'test',
588571
id: 'not bot id'
589572
},
590-
guild
573+
guild: this.guild
591574
};
592575

593576
// Discord displays "@deleted-role" if role doesn't exist (e.g. <@&12346>)
@@ -622,8 +605,6 @@ describe('Bot', function () {
622605

623606
bot.sendToDiscord('testuser', '#irc', 'test message');
624607
this.sendStub.should.have.been.calledOnce;
625-
626-
const guild = this.guild;
627608
const message = {
628609
content: 'test message',
629610
mentions: { users: [] },
@@ -634,7 +615,7 @@ describe('Bot', function () {
634615
username: 'otherauthor',
635616
id: 'not bot id'
636617
},
637-
guild
618+
guild: this.guild
638619
};
639620

640621
bot.sendToIRC(message);
@@ -671,8 +652,6 @@ describe('Bot', function () {
671652

672653
this.bot.sendToDiscord('testuser', '#irc', 'test message');
673654
this.sendStub.should.have.been.calledOnce;
674-
675-
const guild = this.guild;
676655
const message = {
677656
content: 'test message',
678657
mentions: { users: [] },
@@ -683,7 +662,7 @@ describe('Bot', function () {
683662
username: 'otherauthor',
684663
id: 'not bot id'
685664
},
686-
guild
665+
guild: this.guild
687666
};
688667

689668
this.bot.sendToIRC(message);
@@ -731,8 +710,6 @@ describe('Bot', function () {
731710
const format = { ircText: '<{$nickname}> {$discordChannel} => {$ircChannel}: {$text}' };
732711
this.bot = new Bot({ ...configMsgFormatDefault, format });
733712
this.bot.connect();
734-
735-
const guild = this.guild;
736713
const message = {
737714
content: 'test message',
738715
mentions: { users: [] },
@@ -743,7 +720,7 @@ describe('Bot', function () {
743720
username: 'testauthor',
744721
id: 'not bot id'
745722
},
746-
guild
723+
guild: this.guild
747724
};
748725
const expected = '<testauthor> #discord => #irc: test message';
749726

@@ -757,7 +734,6 @@ describe('Bot', function () {
757734
this.bot.connect();
758735

759736
const text = '!testcmd';
760-
const guild = this.guild;
761737
const message = {
762738
content: text,
763739
mentions: { users: [] },
@@ -768,7 +744,7 @@ describe('Bot', function () {
768744
username: 'testauthor',
769745
id: 'not bot id'
770746
},
771-
guild
747+
guild: this.guild
772748
};
773749
const expected = 'testauthor from #discord sent command to #irc:';
774750

@@ -783,7 +759,6 @@ describe('Bot', function () {
783759
this.bot.connect();
784760

785761
const attachmentUrl = 'https://image/url.jpg';
786-
const guild = this.guild;
787762
const message = {
788763
content: '',
789764
mentions: { users: [] },
@@ -795,7 +770,7 @@ describe('Bot', function () {
795770
username: 'otherauthor',
796771
id: 'not bot id'
797772
},
798-
guild
773+
guild: this.guild
799774
};
800775

801776
this.bot.sendToIRC(message);
@@ -809,7 +784,6 @@ describe('Bot', function () {
809784
this.bot.connect();
810785

811786
const text = '!testcmd';
812-
const guild = this.guild;
813787
const message = {
814788
content: text,
815789
mentions: { users: [] },
@@ -820,7 +794,7 @@ describe('Bot', function () {
820794
username: 'testauthor',
821795
id: 'not bot id'
822796
},
823-
guild
797+
guild: this.guild
824798
};
825799

826800
this.bot.sendToIRC(message);

0 commit comments

Comments
 (0)