@@ -8,6 +8,7 @@ import discord from 'discord.js';
8
8
import Bot from '../lib/bot' ;
9
9
import createDiscordStub from './stubs/discord-stub' ;
10
10
import ClientStub from './stubs/irc-client-stub' ;
11
+ import createWebhookStub from './stubs/webhook-stub' ;
11
12
import config from './fixtures/single-test-config.json' ;
12
13
import configMsgFormatDefault from './fixtures/msg-formats-default.json' ;
13
14
@@ -32,6 +33,8 @@ describe('Bot', function () {
32
33
ClientStub . prototype . say = sandbox . stub ( ) ;
33
34
ClientStub . prototype . send = sandbox . stub ( ) ;
34
35
ClientStub . prototype . join = sandbox . stub ( ) ;
36
+ this . sendWebhookMessageStub = sandbox . stub ( ) ;
37
+ discord . WebhookClient = createWebhookStub ( this . sendWebhookMessageStub ) ;
35
38
this . bot = new Bot ( config ) ;
36
39
this . bot . connect ( ) ;
37
40
} ) ;
@@ -793,11 +796,29 @@ describe('Bot', function () {
793
796
} ) ;
794
797
795
798
it ( 'should create webhooks clients for each webhook url in the config' , function ( ) {
796
- this . bot . webhooks . should . have . property ( '#irc ' ) ;
799
+ this . bot . webhooks . should . have . property ( '#withwebhook ' ) ;
797
800
} ) ;
798
801
799
802
it ( 'should extract id and token from webhook urls' , function ( ) {
800
- this . bot . webhooks [ '#irc' ] . id . should . equal ( 'id' ) ;
801
- this . bot . webhooks [ '#irc' ] . token . should . equal ( 'token' ) ;
803
+ this . bot . webhooks [ '#withwebhook' ] . id . should . equal ( 'id' ) ;
804
+ this . bot . webhooks [ '#withwebhook' ] . token . should . equal ( 'token' ) ;
805
+ } ) ;
806
+
807
+ it ( 'should find the matching webhook when it exists' , function ( ) {
808
+ this . bot . findWebhook ( '#ircwebhook' ) . should . not . equal ( null ) ;
809
+ } ) ;
810
+
811
+ it ( 'should prefer webhooks to send a message when possible' , function ( ) {
812
+ const newConfig = { ...config , webhooks : { '#discord' : 'https://discordapp.com/api/webhooks/id/token' } } ;
813
+ const bot = new Bot ( newConfig ) ;
814
+ bot . connect ( ) ;
815
+ bot . sendToDiscord ( 'nick' , '#irc' , 'text' ) ;
816
+ this . sendWebhookMessageStub . should . have . been . called ;
817
+ } ) ;
818
+
819
+ it ( 'should find the user\'s avatar when the irc nick is also a discord username' , function ( ) {
820
+ const testUser = new discord . User ( this . bot . discord , { username : 'avatarUser' , id : '123' , avatar : '123' } ) ;
821
+ this . findUserStub . withArgs ( 'username' , testUser . username ) . returns ( testUser ) ;
822
+ this . bot . getDiscordAvatar ( 'avatarUser' ) . should . not . equal ( null ) ;
802
823
} ) ;
803
824
} ) ;
0 commit comments