@@ -27,6 +27,7 @@ describe('Bot', function() {
27
27
irc . Client = ClientStub ;
28
28
discord . Client = DiscordStub ;
29
29
DiscordStub . prototype . sendMessage = sandbox . stub ( ) ;
30
+ DiscordStub . prototype . users = { get : sandbox . stub ( ) } ;
30
31
ClientStub . prototype . say = sandbox . stub ( ) ;
31
32
ClientStub . prototype . send = sandbox . stub ( ) ;
32
33
ClientStub . prototype . join = sandbox . stub ( ) ;
@@ -169,6 +170,42 @@ describe('Bot', function() {
169
170
this . bot . parseText ( message ) . should . equal ( '@testuser hi' ) ;
170
171
} ) ;
171
172
173
+ it ( 'should convert user mentions from IRC' , function ( ) {
174
+ const testuser = new discord . User ( { username : 'testuser' , id : '123' } , this . bot . discord ) ;
175
+ this . bot . discord . users . get . withArgs ( 'username' , testuser . username ) . returns ( testuser ) ;
176
+
177
+ const username = 'ircuser' ;
178
+ const text = 'Hello, @testuser!' ;
179
+ const expected = `**<${ username } >** Hello, <@${ testuser . id } >!` ;
180
+
181
+ this . bot . sendToDiscord ( username , '#irc' , text ) ;
182
+ DiscordStub . prototype . sendMessage . should . have . been . calledWith ( discordChannel , expected ) ;
183
+ } ) ;
184
+
185
+ it ( 'should not convert user mentions from IRC if such user does not exist' , function ( ) {
186
+ const username = 'ircuser' ;
187
+ const text = 'See you there @5pm' ;
188
+ const expected = `**<${ username } >** See you there @5pm` ;
189
+
190
+ this . bot . sendToDiscord ( username , '#irc' , text ) ;
191
+ DiscordStub . prototype . sendMessage . should . have . been . calledWith ( discordChannel , expected ) ;
192
+ } ) ;
193
+
194
+ it ( 'should convert multiple user mentions from IRC' , function ( ) {
195
+ const testuser = new discord . User ( { username : 'testuser' , id : '123' } , this . bot . discord ) ;
196
+ this . bot . discord . users . get . withArgs ( 'username' , testuser . username ) . returns ( testuser ) ;
197
+ const anotheruser = new discord . User ( { username : 'anotheruser' , id : '124' } , this . bot . discord ) ;
198
+ this . bot . discord . users . get . withArgs ( 'username' , anotheruser . username ) . returns ( anotheruser ) ;
199
+
200
+ const username = 'ircuser' ;
201
+ const text = 'Hello, @testuser and @anotheruser, was our meeting scheduled @5pm?' ;
202
+ const expected = `**<${ username } >** Hello, <@${ testuser . id } > and <@${ anotheruser . id } >,` +
203
+ ` was our meeting scheduled @5pm?` ;
204
+
205
+ this . bot . sendToDiscord ( username , '#irc' , text ) ;
206
+ DiscordStub . prototype . sendMessage . should . have . been . calledWith ( discordChannel , expected ) ;
207
+ } ) ;
208
+
172
209
it ( 'should convert newlines from discord' , function ( ) {
173
210
const message = {
174
211
mentions : [ ] ,
0 commit comments