1
0
Fork 0
out-of-your-element-fork-th.../test/test.js

145 lines
5.9 KiB
JavaScript
Raw Normal View History

// @ts-check
const fs = require("fs")
2023-09-30 12:24:05 +00:00
const {join} = require("path")
2024-03-01 04:28:14 +00:00
const stp = require("stream").promises
const sqlite = require("better-sqlite3")
const migrate = require("../src/db/migrate")
const HeatSync = require("heatsync")
2023-09-30 12:24:05 +00:00
const {test} = require("supertape")
const data = require("./data")
2024-02-18 12:24:21 +00:00
/** @type {import("node-fetch").default} */
// @ts-ignore
const fetch = require("node-fetch")
const {green} = require("ansi-colors")
const passthrough = require("../src/passthrough")
const db = new sqlite(":memory:")
const {reg} = require("../src/matrix/read-registration")
2024-09-29 12:42:12 +00:00
reg.ooye.discord_token = "Njg0MjgwMTkyNTUzODQ0NzQ3.Xl3zlw.baby"
reg.ooye.server_origin = "https://matrix.cadence.moe" // so that tests will pass even when hard-coded
2024-01-20 05:23:48 +00:00
reg.ooye.server_name = "cadence.moe"
2024-06-06 00:12:48 +00:00
reg.id = "baby" // don't actually take authenticated actions on the server
reg.as_token = "baby"
reg.hs_token = "baby"
reg.ooye.bridge_origin = "https://bridge.example.org"
/** @type {import("heatsync").default} */ // @ts-ignore
2023-05-08 05:22:20 +00:00
const sync = new HeatSync({watchFS: false})
2023-09-30 12:24:05 +00:00
const discord = {
guilds: new Map([
[data.guild.general.id, data.guild.general]
]),
application: {
id: "684280192553844747"
},
channels: new Map([
[data.channel.general.id, data.channel.general],
["497161350934560778", {
guild_id: "497159726455455754"
}],
["498323546729086986", {
guild_id: "497159726455455754",
name: "bad-boots-prison"
}]
])
2023-09-30 12:24:05 +00:00
}
2024-09-13 11:47:11 +00:00
Object.assign(passthrough, { discord, sync, db })
const orm = sync.require("../src/db/orm")
2023-09-14 00:32:27 +00:00
passthrough.from = orm.from
passthrough.select = orm.select
const file = sync.require("../src/matrix/file")
2024-03-04 04:02:38 +00:00
/* c8 ignore next */
file._actuallyUploadDiscordFileToMxc = function(url, res) { throw new Error(`Not allowed to upload files during testing.\nURL: ${url}`) }
2023-09-30 12:24:05 +00:00
;(async () => {
2024-03-01 04:28:14 +00:00
/* c8 ignore start - maybe download some more test files in slow mode */
if (process.argv.includes("--slow")) {
test("test files: download", async t => {
/** @param {{url: string, to: string}[]} files */
async function allReporter(files) {
return new Promise(resolve => {
let resolved = 0
const report = files.map(file => file.to.split("/").slice(-1)[0][0])
files.map(download).forEach((p, i) => {
p.then(() => {
report[i] = green(".")
process.stderr.write("\r" + report.join(""))
if (++resolved === files.length) resolve(null)
})
})
})
}
async function download({url, to}) {
if (await fs.existsSync(to)) return
const res = await fetch(url)
await stp.pipeline(res.body, fs.createWriteStream(to, {encoding: "binary"}))
}
await allReporter([
{url: "https://cadence.moe/friends/ooye_test/RLMgJGfgTPjIQtvvWZsYjhjy.png", to: "test/res/RLMgJGfgTPjIQtvvWZsYjhjy.png"},
{url: "https://cadence.moe/friends/ooye_test/bZFuuUSEebJYXUMSxuuSuLTa.png", to: "test/res/bZFuuUSEebJYXUMSxuuSuLTa.png"},
{url: "https://cadence.moe/friends/ooye_test/qWmbXeRspZRLPcjseyLmeyXC.png", to: "test/res/qWmbXeRspZRLPcjseyLmeyXC.png"},
{url: "https://cadence.moe/friends/ooye_test/wcouHVjbKJJYajkhJLsyeJAA.png", to: "test/res/wcouHVjbKJJYajkhJLsyeJAA.png"},
{url: "https://cadence.moe/friends/ooye_test/WbYqNlACRuicynBfdnPYtmvc.gif", to: "test/res/WbYqNlACRuicynBfdnPYtmvc.gif"},
{url: "https://cadence.moe/friends/ooye_test/HYcztccFIPgevDvoaWNsEtGJ.png", to: "test/res/HYcztccFIPgevDvoaWNsEtGJ.png"},
{url: "https://cadence.moe/friends/ooye_test/lHfmJpzgoNyNtYHdAmBHxXix.png", to: "test/res/lHfmJpzgoNyNtYHdAmBHxXix.png"},
{url: "https://cadence.moe/friends/ooye_test/MtRdXixoKjKKOyHJGWLsWLNU.png", to: "test/res/MtRdXixoKjKKOyHJGWLsWLNU.png"},
{url: "https://cadence.moe/friends/ooye_test/HXfFuougamkURPPMflTJRxGc.png", to: "test/res/HXfFuougamkURPPMflTJRxGc.png"},
{url: "https://cadence.moe/friends/ooye_test/ikYKbkhGhMERAuPPbsnQzZiX.png", to: "test/res/ikYKbkhGhMERAuPPbsnQzZiX.png"},
{url: "https://cadence.moe/friends/ooye_test/AYPpqXzVJvZdzMQJGjioIQBZ.png", to: "test/res/AYPpqXzVJvZdzMQJGjioIQBZ.png"},
{url: "https://cadence.moe/friends/ooye_test/UVuzvpVUhqjiueMxYXJiFEAj.png", to: "test/res/UVuzvpVUhqjiueMxYXJiFEAj.png"},
2024-03-01 04:28:14 +00:00
{url: "https://ezgif.com/images/format-demo/butterfly.gif", to: "test/res/butterfly.gif"},
2024-03-04 04:02:38 +00:00
{url: "https://ezgif.com/images/format-demo/butterfly.png", to: "test/res/butterfly.png"},
2024-03-01 04:28:14 +00:00
])
}, {timeout: 60000})
}
/* c8 ignore end */
2023-09-30 12:24:05 +00:00
const p = migrate.migrate(db)
test("migrate: migration works", async t => {
await p
t.pass("it did not throw an error")
})
await p
2024-02-02 02:55:02 +00:00
test("migrate: migration works the second time", async t => {
await migrate.migrate(db)
t.pass("it did not throw an error")
})
2023-09-30 12:24:05 +00:00
db.exec(fs.readFileSync(join(__dirname, "ooye-test-data.sql"), "utf8"))
2024-02-18 12:24:21 +00:00
2024-09-29 12:42:12 +00:00
require("./addbot.test")
require("../src/db/orm.test")
require("../src/discord/utils.test")
require("../src/matrix/kstate.test")
require("../src/matrix/api.test")
require("../src/matrix/file.test")
require("../src/matrix/read-registration.test")
require("../src/matrix/txnid.test")
require("../src/d2m/actions/create-room.test")
require("../src/d2m/actions/create-space.test")
require("../src/d2m/actions/register-user.test")
require("../src/d2m/converters/edit-to-changes.test")
require("../src/d2m/converters/emoji-to-key.test")
require("../src/d2m/converters/lottie.test")
require("../src/d2m/converters/message-to-event.test")
require("../src/d2m/converters/message-to-event.embeds.test")
require("../src/d2m/converters/message-to-event.pk.test")
require("../src/d2m/converters/pins-to-list.test")
require("../src/d2m/converters/remove-reaction.test")
require("../src/d2m/converters/thread-to-announcement.test")
require("../src/d2m/converters/user-to-mxid.test")
require("../src/m2d/converters/event-to-message.test")
require("../src/m2d/converters/utils.test")
require("../src/m2d/converters/emoji-sheet.test")
require("../src/discord/interactions/invite.test")
2024-09-29 12:18:56 +00:00
require("../src/discord/interactions/matrix-info.test")
2024-09-29 12:42:12 +00:00
require("../src/discord/interactions/reactions.test")
2023-09-30 12:24:05 +00:00
})()