ooye-nix-patches/src/discord/interactions/reactions.test.js
2024-09-30 01:42:12 +13:00

88 lines
2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const {test} = require("supertape")
const data = require("../../../test/data")
const DiscordTypes = require("discord-api-types/v10")
const {db, discord} = require("../../passthrough")
const {MatrixServerError} = require("../../matrix/mreq")
const {_interact} = require("./reactions")
test("reactions: checks if message is bridged", async t => {
const msg = await _interact({
data: {
target_id: "0"
}
}, {})
t.equal(msg.data.content, "This message hasn't been bridged to Matrix.")
})
test("reactions: different response if nobody reacted", async t => {
const msg = await _interact({
data: {
target_id: "1126786462646550579"
}
}, {
api: {
async getFullRelations(roomID, eventID) {
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
t.equal(eventID, "$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg")
return []
}
}
})
t.equal(msg.data.content, "Nobody from Matrix reacted to this message.")
})
test("reactions: shows reactions if there are some, ignoring discord users", async t => {
let called = 1
const msg = await _interact({
data: {
target_id: "1126786462646550579"
}
}, {
api: {
async getFullRelations(roomID, eventID) {
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
t.equal(eventID, "$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg")
return [{
sender: "@cadence:cadence.moe",
content: {
"m.relates_to": {
key: "🐈",
rel_type: "m.annotation"
}
}
}, {
sender: "@rnl:cadence.moe",
content: {
"m.relates_to": {
key: "🐈",
rel_type: "m.annotation"
}
}
}, {
sender: "@cadence:cadence.moe",
content: {
"m.relates_to": {
key: "🐈‍⬛",
rel_type: "m.annotation"
}
}
}, {
sender: "@_ooye_rnl:cadence.moe",
content: {
"m.relates_to": {
key: "🐈",
rel_type: "m.annotation"
}
}
}]
}
}
})
t.equal(
msg.data.content,
"🐈 ⮞ cadence [they] ⬩ @rnl:cadence.moe"
+ "\n🐈⬛ ⮞ cadence [they]"
)
t.equal(called, 1)
})