Spoiler Fix #90
1 changed files with 113 additions and 117 deletions
fix format
commit
cfafac2480
|
|
@ -1,10 +1,10 @@
|
|||
const { test } = require("supertape")
|
||||
const { messageToEvent } = require("./message-to-event")
|
||||
const { MatrixServerError } = require("../../matrix/mreq")
|
||||
const {test} = require("supertape")
|
||||
const {messageToEvent} = require("./message-to-event")
|
||||
const {MatrixServerError} = require("../../matrix/mreq")
|
||||
const data = require("../../../test/data")
|
||||
const { mockGetEffectivePower } = require("../../matrix/utils.test")
|
||||
const {mockGetEffectivePower} = require("../../matrix/utils.test")
|
||||
const Ty = require("../../types")
|
||||
const { db } = require("../../passthrough")
|
||||
const {db} = require("../../passthrough")
|
||||
|
||||
/**
|
||||
* @param {string} roomID
|
||||
|
|
@ -12,7 +12,7 @@ const { db } = require("../../passthrough")
|
|||
* @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) {
|
||||
return async function(roomID, eventID) {
|
||||
t.equal(roomID, roomID_in)
|
||||
t.equal(eventID, eventID_in)
|
||||
return new Promise(resolve => {
|
||||
|
|
@ -74,8 +74,8 @@ test("message2event: simple room mention", async t => {
|
|||
t.equal(roomID, "!BnKuBPCvyfOkhcUjEu:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:matrix.org": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -102,8 +102,8 @@ test("message2event: simple room link", async t => {
|
|||
t.equal(roomID, "!BnKuBPCvyfOkhcUjEu:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:matrix.org": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -130,8 +130,8 @@ test("message2event: nicked room mention", async t => {
|
|||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:matrix.org": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -214,12 +214,12 @@ test("message2event: timestamps", async t => {
|
|||
+ "\n3 October 2026 at 9:30 am (UTC)"
|
||||
+ "\n24 December 2026 at 11:00 pm (UTC)",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `<a href="https://bridge.example.org/time/1791106413/S">4 Oct 2026, 9:33:33 am (UTC)</a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791106436/f">4 October 2026 at 9:33 am (UTC)</a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791106440/F">Sunday, 4 October 2026 at 9:34 am (UTC)</a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791106448/T">9:34:08 am (UTC)</a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791019800/R">3 October 2026 at 9:30 am (UTC)</a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1798153200/R">24 December 2026 at 11:00 pm (UTC)</a>`,
|
||||
formatted_body: `<a href="https://bridge.example.org/time/1791106413/S"><time data-style="S" datetime="2026-10-04T09:33:33.000Z">4 Oct 2026, 9:33:33 am (UTC)</time></a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791106436/f"><time data-style="f" datetime="2026-10-04T09:33:56.000Z">4 October 2026 at 9:33 am (UTC)</time></a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791106440/F"><time data-style="F" datetime="2026-10-04T09:34:00.000Z">Sunday, 4 October 2026 at 9:34 am (UTC)</time></a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791106448/T"><time data-style="T" datetime="2026-10-04T09:34:08.000Z">9:34:08 am (UTC)</time></a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1791019800/R"><time data-style="R" datetime="2026-10-03T09:30:00.000Z">3 October 2026 at 9:30 am (UTC)</time></a>`
|
||||
+ `<br><a href="https://bridge.example.org/time/1798153200/R"><time data-style="R" datetime="2026-12-24T23:00:00.000Z">24 December 2026 at 11:00 pm (UTC)</time></a>`,
|
||||
"m.mentions": {}
|
||||
}])
|
||||
})
|
||||
|
|
@ -234,8 +234,8 @@ test("message2event: simple message link", async t => {
|
|||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:super.invalid": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:super.invalid": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -270,8 +270,8 @@ test("message2event: message link that OOYE doesn't know about", async t => {
|
|||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:matrix.org": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -308,8 +308,8 @@ test("message2event: message timestamp failed to fetch", async t => {
|
|||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:matrix.org": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -505,7 +505,7 @@ test("message2event: simple reply to matrix user", async t => {
|
|||
})
|
||||
|
||||
test("message2event: simple reply to matrix user, reply fallbacks disabled", async t => {
|
||||
const events = await messageToEvent(data.message.simple_reply_to_matrix_user, data.guild.general, { includeReplyFallback: false }, {
|
||||
const events = await messageToEvent(data.message.simple_reply_to_matrix_user, data.guild.general, {includeReplyFallback: false}, {
|
||||
api: {
|
||||
getEvent: mockGetEvent(t, "!kLRqKKUQXcibIMtOpl:cadence.moe", "$Ij3qo7NxMA4VPexlAiIx2CB9JbsiGhJeyt-2OvkAUe4", {
|
||||
type: "m.room.message",
|
||||
|
|
@ -1151,12 +1151,10 @@ test("message2event: very large png is converted to jpeg for upload", async t =>
|
|||
async fetch(url, init) {
|
||||
t.equal(url, "https://media.discordapp.net/attachments/1160894080998461480/1548656385292509274/855064e9-bdae-487a-a497-c662bd510487.png?format=jpeg")
|
||||
t.equal(init.method, "HEAD")
|
||||
return new Response("wa", {
|
||||
headers: {
|
||||
return new Response("wa", {headers: {
|
||||
"Content-Type": "image/jpeg",
|
||||
"Content-Length": 483085
|
||||
}
|
||||
})
|
||||
}})
|
||||
}
|
||||
})
|
||||
t.deepEqual(events, [{
|
||||
|
|
@ -1448,8 +1446,8 @@ test("message2event: constructed forwarded message", async t => {
|
|||
async getJoinedMembers() {
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:matrix.org": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1507,8 +1505,8 @@ test("message2event: constructed forwarded text", async t => {
|
|||
async getJoinedMembers() {
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@user:matrix.org": { display_name: null, avatar_url: null }
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1552,10 +1550,10 @@ test("message2event: don't scan forwarded messages for mentions", async t => {
|
|||
})
|
||||
|
||||
test("message2event: invite no details embed if no event", async t => {
|
||||
const events = await messageToEvent({ content: "https://discord.gg/placeholder?event=1381190945646710824" }, {}, {}, {
|
||||
const events = await messageToEvent({content: "https://discord.gg/placeholder?event=1381190945646710824"}, {}, {}, {
|
||||
snow: {
|
||||
invite: {
|
||||
getInvite: async () => ({ ...data.invite.irl, guild_scheduled_event: null })
|
||||
getInvite: async () => ({...data.invite.irl, guild_scheduled_event: null})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -1572,7 +1570,7 @@ test("message2event: invite no details embed if no event", async t => {
|
|||
})
|
||||
|
||||
test("message2event: irl invite event renders embed", async t => {
|
||||
const events = await messageToEvent({ content: "https://discord.gg/placeholder?event=1381190945646710824" }, {}, {}, {
|
||||
const events = await messageToEvent({content: "https://discord.gg/placeholder?event=1381190945646710824"}, {}, {}, {
|
||||
snow: {
|
||||
invite: {
|
||||
getInvite: async () => data.invite.irl
|
||||
|
|
@ -1605,7 +1603,7 @@ test("message2event: irl invite event renders embed", async t => {
|
|||
})
|
||||
|
||||
test("message2event: vc invite event renders embed", async t => {
|
||||
const events = await messageToEvent({ content: "https://discord.gg/placeholder?event=1381174024801095751" }, {}, {}, {
|
||||
const events = await messageToEvent({content: "https://discord.gg/placeholder?event=1381174024801095751"}, {}, {}, {
|
||||
snow: {
|
||||
invite: {
|
||||
getInvite: async () => data.invite.vc
|
||||
|
|
@ -1639,12 +1637,12 @@ test("message2event: vc invite event renders embed", async t => {
|
|||
})
|
||||
|
||||
test("message2event: vc invite event renders embed with room link", async t => {
|
||||
const events = await messageToEvent({ content: "https://discord.gg/placeholder?event=1381174024801095751" }, {}, {}, {
|
||||
const events = await messageToEvent({content: "https://discord.gg/placeholder?event=1381174024801095751"}, {}, {}, {
|
||||
api: {
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
getJoinedMembers: async () => ({
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": { display_name: null, avatar_url: null },
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
@ -1681,7 +1679,7 @@ test("message2event: vc invite event renders embed with room link", async t => {
|
|||
})
|
||||
|
||||
test("message2event: expired/invalid invites are sent as-is", async t => {
|
||||
const events = await messageToEvent({ content: "https://discord.gg/placeholder?event=1381190945646710824" }, {}, {}, {
|
||||
const events = await messageToEvent({content: "https://discord.gg/placeholder?event=1381190945646710824"}, {}, {}, {
|
||||
snow: {
|
||||
invite: {
|
||||
async getInvite() {
|
||||
|
|
@ -1785,8 +1783,7 @@ test("message2event: cross-room reply", async t => {
|
|||
}
|
||||
},
|
||||
content: "cross-room reply"
|
||||
}, {}, {}, {
|
||||
api: {
|
||||
}, {}, {}, {api: {
|
||||
async getEvent(roomID, eventID) {
|
||||
called++
|
||||
t.equal(roomID, "!mHmhQQPwXNananaOLD:cadence.moe")
|
||||
|
|
@ -1810,8 +1807,7 @@ test("message2event: cross-room reply", async t => {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}})
|
||||
t.deepEqual(events, [
|
||||
{
|
||||
$type: "m.room.message",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue