2023-08-19 10:54:23 +00:00
const { test } = require ( "supertape" )
const { messageToEvent } = require ( "./message-to-event" )
const data = require ( "../../test/data" )
const Ty = require ( "../../types" )
/ * *
* @ param { string } roomID
* @ param { string } eventID
* @ returns { ( roomID : string , eventID : string ) => Promise < Ty . Event . Outer < Ty . Event . M _Room _Message >> }
* /
function mockGetEvent ( t , roomID _in , eventID _in , outer ) {
return async function ( roomID , eventID ) {
t . equal ( roomID , roomID _in )
t . equal ( eventID , eventID _in )
return new Promise ( resolve => {
setTimeout ( ( ) => {
resolve ( {
event _id : eventID _in ,
room _id : roomID _in ,
origin _server _ts : 1680000000000 ,
unsigned : {
age : 2245 ,
transaction _id : "$local.whatever"
} ,
... outer
} )
} )
} )
}
}
test ( "message2event embeds: nothing but a field" , async t => {
const events = await messageToEvent ( data . message _with _embeds . nothing _but _a _field , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
2023-10-01 10:55:42 +00:00
msgtype : "m.notice" ,
2023-10-02 09:26:00 +00:00
body : "> **Amanda 🎵#2192 :online:"
+ "\n> willow tree, branch 0**"
+ "\n> **❯ Uptime:**\n> 3m 55s\n> **❯ Memory:**\n> 64.45MB" ,
2023-10-01 10:55:42 +00:00
format : "org.matrix.custom.html" ,
2023-10-02 09:26:00 +00:00
formatted _body : '<blockquote><strong>Amanda 🎵#2192 <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/LCEqjStXCxvRQccEkuslXEyZ\" title=\":online:\" alt=\":online:\">'
2023-10-01 10:55:42 +00:00
+ '<br>willow tree, branch 0</strong>'
+ '<br><strong>❯ Uptime:</strong><br>3m 55s'
2023-10-02 09:26:00 +00:00
+ '<br><strong>❯ Memory:</strong><br>64.45MB</blockquote>'
2023-10-01 10:55:42 +00:00
} ] )
} )
test ( "message2event embeds: reply with just an embed" , async t => {
const events = await messageToEvent ( data . message _with _embeds . reply _with _only _embed , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
msgtype : "m.notice" ,
"m.mentions" : { } ,
2023-10-02 09:26:00 +00:00
body : "> [**⏺️ dynastic (@dynastic)**](https://twitter.com/i/user/719631291747078145)"
+ "\n> \n> **https://twitter.com/i/status/1707484191963648161**"
+ "\n> \n> does anyone know where to find that one video of the really mysterious yam-like object being held up to a bunch of random objects, like clocks, and they have unexplained impossible reactions to it?"
+ "\n> \n> **Retweets**"
+ "\n> 119"
+ "\n> \n> **Likes**"
+ "\n> 5581"
+ "\n> \n> — Twitter" ,
2023-10-01 10:55:42 +00:00
format : "org.matrix.custom.html" ,
2023-10-02 09:26:00 +00:00
formatted _body : '<blockquote><a href="https://twitter.com/i/user/719631291747078145"><strong>⏺️ dynastic (@dynastic)</strong></a>'
2023-10-01 10:55:42 +00:00
+ '<br><br><strong><a href="https://twitter.com/i/status/1707484191963648161">https://twitter.com/i/status/1707484191963648161</a></strong>'
+ '<br><br>does anyone know where to find that one video of the really mysterious yam-like object being held up to a bunch of random objects, like clocks, and they have unexplained impossible reactions to it?'
2023-10-02 09:26:00 +00:00
+ '<br><br><strong>Retweets</strong><br>119<br><br><strong>Likes</strong><br>5581<br><br>— Twitter</blockquote>'
2023-10-01 10:55:42 +00:00
} ] )
} )
test ( "message2event embeds: image embed and attachment" , async t => {
const events = await messageToEvent ( data . message _with _embeds . image _embed _and _attachment , data . guild . general , { } , {
api : {
async getJoinedMembers ( roomID ) {
return { joined : [ ] }
}
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-08-19 10:54:23 +00:00
msgtype : "m.text" ,
2023-10-01 10:55:42 +00:00
body : "https://tootsuite.net/Warp-Gate2.gif\ntanget: @ monster spawner" ,
format : "org.matrix.custom.html" ,
formatted _body : '<a href="https://tootsuite.net/Warp-Gate2.gif">https://tootsuite.net/Warp-Gate2.gif</a><br>tanget: @ monster spawner' ,
"m.mentions" : { }
} , {
$type : "m.room.message" ,
msgtype : "m.image" ,
url : "mxc://cadence.moe/zAXdQriaJuLZohDDmacwWWDR" ,
body : "Screenshot_20231001_034036.jpg" ,
external _url : "https://cdn.discordapp.com/attachments/176333891320283136/1157854643037163610/Screenshot_20231001_034036.jpg?ex=651a1faa&is=6518ce2a&hm=eb5ca80a3fa7add8765bf404aea2028a28a2341e4a62435986bcdcf058da82f3&" ,
filename : "Screenshot_20231001_034036.jpg" ,
info : {
h : 1170 ,
w : 1080 ,
size : 51981 ,
mimetype : "image/jpeg"
} ,
"m.mentions" : { }
2023-08-19 10:54:23 +00:00
} ] )
} )