const {test} = require("supertape") const {messageToEvent} = require("./message-to-event") const data = require("../../test/data") const Ty = require("../../types") 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": {}, msgtype: "m.notice", body: "| ### Amanda 🎵#2192 :online:" + "\n| willow tree, branch 0" + "\n| **❯ Uptime:**\n| 3m 55s\n| **❯ Memory:**\n| 64.45MB", format: "org.matrix.custom.html", formatted_body: '
' }]) }) 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": {}, 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| — Twitter", format: "org.matrix.custom.html", formatted_body: 'Amanda 🎵#2192 ' + '
willow tree, branch 0' + '
❯ Uptime:
3m 55s' + '
❯ Memory:
64.45MB
' + '' }]) }) 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", msgtype: "m.text", body: "https://tootsuite.net/Warp-Gate2.gif\ntanget: @ monster spawner", format: "org.matrix.custom.html", formatted_body: 'https://tootsuite.net/Warp-Gate2.gifhttps://twitter.com/i/status/1707484191963648161' + '
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?' + '
Retweets
119Likes
— Twitter
5581
", "m.mentions": {} }]) t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each") }) test("message2event embeds: crazy html is all escaped", async t => { const events = await messageToEvent(data.message_with_embeds.escaping_crazy_html_tags, data.guild.general) t.deepEqual(events, [{ $type: "m.room.message", msgtype: "m.notice", body: "| ## ⏺️ [Heyreply draft
The following is a message composed via consensus of the Stinker Council.
For those who are not currently aware of our existence, we represent the organization known as Wonderland. Our previous mission centered around the assortment and study of puzzling objects, entities and other assorted phenomena. This mission was the focus of our organization for more than 28 years.
Due to circumstances outside of our control, this directive has now changed. Our new mission will be the extermination of the stinker race.
There will be no further communication.