@@ -46,6 +46,7 @@ const modDiscordBot = Proxyquire("../src/bot", {
4646 } ,
4747 } ,
4848} ) ;
49+
4950describe ( "DiscordBot" , ( ) => {
5051 let discordBot ;
5152 const config = {
@@ -60,6 +61,7 @@ describe("DiscordBot", () => {
6061 discordSendDelay : 50 ,
6162 } ,
6263 } ;
64+
6365 describe ( "run()" , ( ) => {
6466 it ( "should resolve when ready." , async ( ) => {
6567 discordBot = new modDiscordBot . DiscordBot (
@@ -102,6 +104,7 @@ describe("DiscordBot", () => {
102104 await discordBot . LookupRoom ( "123" , "321" ) ;
103105 } ) ;
104106 } ) ;
107+
105108 describe ( "OnMessage()" , ( ) => {
106109 const channel = new MockTextChannel ( ) ;
107110 const msg = new MockMessage ( channel ) ;
@@ -130,6 +133,7 @@ describe("DiscordBot", () => {
130133 } ;
131134 return discord ;
132135 }
136+
133137 it ( "ignores own messages" , async ( ) => {
134138 discordBot = getDiscordBot ( ) ;
135139 const guild : any = new MockGuild ( "123" , [ ] ) ;
@@ -140,46 +144,54 @@ describe("DiscordBot", () => {
140144 await discordBot . OnMessage ( msg ) ;
141145 expect ( mockBridge . getIntent ( author . id ) . wasCalled ( "sendEvent" , false ) ) . to . equal ( 0 ) ;
142146 } ) ;
147+
143148 it ( "Passes on !matrix commands" , async ( ) => {
144149 discordBot = getDiscordBot ( ) ;
145150 msg . author = author ;
146151 msg . content = "!matrix test" ;
147152 await discordBot . OnMessage ( msg ) ;
148153 expect ( HANDLE_COMMAND ) . to . be . true ;
149154 } ) ;
155+
150156 it ( "skips empty messages" , async ( ) => {
151157 discordBot = getDiscordBot ( ) ;
152158 msg . content = "" ;
153159 msg . author = author ;
154160 await discordBot . OnMessage ( msg as any ) ;
155161 expect ( mockBridge . getIntent ( author . id ) . wasCalled ( "sendEvent" , false ) ) . to . equal ( 0 ) ;
156162 } ) ;
163+
157164 it ( "sends normal messages" , async ( ) => {
158165 discordBot = getDiscordBot ( ) ;
159166 msg . author = author ;
160167 msg . content = "Foxies are amazing!" ;
161168 await discordBot . OnMessage ( msg as any ) ;
162169 mockBridge . getIntent ( author . id ) . wasCalled ( "sendEvent" ) ;
163170 } ) ;
171+
164172 it ( "sends edit messages" , async ( ) => {
165173 discordBot = getDiscordBot ( ) ;
166174 msg . author = author ;
167175 msg . content = "Foxies are super amazing!" ;
176+ msg . url = "https://discord.com/channels/123/321/1028397843632902214" ;
168177 await discordBot . OnMessage ( msg , "editevent" ) ;
169178 mockBridge . getIntent ( author . id ) . wasCalled ( "sendEvent" , true , "!asdf:localhost" , {
170179 "body" : "* Foxies are super amazing!" ,
171180 "format" : "org.matrix.custom.html" ,
172181 "formatted_body" : "* Foxies are super amazing!" ,
182+ "external_url" : "https://discord.com/channels/123/321/1028397843632902214" ,
173183 "m.new_content" : {
174184 body : "Foxies are super amazing!" ,
175185 format : "org.matrix.custom.html" ,
176186 formatted_body : "Foxies are super amazing!" ,
187+ external_url : "https://discord.com/channels/123/321/1028397843632902214" ,
177188 msgtype : "m.text" ,
178189 } ,
179190 "m.relates_to" : { event_id : "editevent" , rel_type : "m.replace" } ,
180191 "msgtype" : "m.text" ,
181192 } ) ;
182193 } ) ;
194+
183195 it ( "uploads images" , async ( ) => {
184196 discordBot = getDiscordBot ( ) ;
185197 msg . author = author ;
@@ -206,6 +218,7 @@ describe("DiscordBot", () => {
206218 url : "mxc://someimage.png" ,
207219 } ) ;
208220 } ) ;
221+
209222 it ( "uploads videos" , async ( ) => {
210223 discordBot = getDiscordBot ( ) ;
211224 msg . author = author ;
@@ -232,6 +245,7 @@ describe("DiscordBot", () => {
232245 url : "mxc://foxes.mov" ,
233246 } ) ;
234247 } ) ;
248+
235249 it ( "uploads audio" , async ( ) => {
236250 discordBot = getDiscordBot ( ) ;
237251 msg . author = author ;
@@ -256,6 +270,7 @@ describe("DiscordBot", () => {
256270 url : "mxc://meow.mp3" ,
257271 } ) ;
258272 } ) ;
273+
259274 it ( "uploads other files" , async ( ) => {
260275 discordBot = getDiscordBot ( ) ;
261276 msg . author = author ;
@@ -281,6 +296,7 @@ describe("DiscordBot", () => {
281296 } ) ;
282297 } ) ;
283298 } ) ;
299+
284300 describe ( "OnMessageUpdate()" , ( ) => {
285301 it ( "should return on an unchanged message" , async ( ) => {
286302 discordBot = new modDiscordBot . DiscordBot (
@@ -308,6 +324,7 @@ describe("DiscordBot", () => {
308324 await discordBot . OnMessageUpdate ( oldMsg , newMsg ) ;
309325 expect ( checkMsgSent ) . to . be . false ;
310326 } ) ;
327+
311328 it ( "should send a matrix edit on an edited discord message" , async ( ) => {
312329 discordBot = new modDiscordBot . DiscordBot (
313330 config ,
@@ -347,6 +364,7 @@ describe("DiscordBot", () => {
347364 await discordBot . OnMessageUpdate ( oldMsg , newMsg ) ;
348365 expect ( checkEditEventSent ) . to . equal ( "editedid" ) ;
349366 } ) ;
367+
350368 it ( "should send a new message if no store event found" , async ( ) => {
351369 discordBot = new modDiscordBot . DiscordBot (
352370 config ,
@@ -392,6 +410,7 @@ describe("DiscordBot", () => {
392410 expect ( checkEditEventSent ) . to . be . undefined ;
393411 } ) ;
394412 } ) ;
413+
395414 describe ( "event:message" , ( ) => {
396415 it ( "should delay messages so they arrive in order" , async ( ) => {
397416 discordBot = new modDiscordBot . DiscordBot (
@@ -414,6 +433,7 @@ describe("DiscordBot", () => {
414433 }
415434 await discordBot . discordMessageQueue [ CHANID ] ;
416435 } ) ;
436+
417437 it ( "should handle messages that reject in the queue" , async ( ) => {
418438 discordBot = new modDiscordBot . DiscordBot (
419439 config ,
0 commit comments