beginnings: rendering text to message
This commit is contained in:
52
src/render.test.ts
Normal file
52
src/render.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import test from "ava"
|
||||
import { Client, TextChannel } from "discord.js"
|
||||
import { nanoid } from "nanoid"
|
||||
import { testBotToken, testChannelId } from "../test/env.js"
|
||||
import { raise } from "./helpers/raise.js"
|
||||
import { waitForWithTimeout } from "./helpers/wait-for-with-timeout.js"
|
||||
import { render } from "./render.js"
|
||||
|
||||
const client = new Client({
|
||||
intents: ["GUILDS"],
|
||||
})
|
||||
|
||||
let channel: TextChannel
|
||||
|
||||
test.before(async () => {
|
||||
await client.login(testBotToken)
|
||||
|
||||
const result =
|
||||
client.channels.cache.get(testChannelId) ??
|
||||
(await client.channels.fetch(testChannelId)) ??
|
||||
raise("Channel not found")
|
||||
|
||||
if (!(result instanceof TextChannel)) {
|
||||
throw new Error("Channel must be a text channel")
|
||||
}
|
||||
|
||||
channel = result
|
||||
})
|
||||
|
||||
test.after(() => {
|
||||
client.destroy()
|
||||
})
|
||||
|
||||
test("rendering text", async (t) => {
|
||||
const content = nanoid()
|
||||
const root = render(content, channel)
|
||||
|
||||
await waitForWithTimeout(
|
||||
() => channel.messages.cache.some((m) => m.content === content),
|
||||
4000,
|
||||
)
|
||||
|
||||
root.destroy()
|
||||
|
||||
await waitForWithTimeout(() => {
|
||||
return channel.messages.cache
|
||||
.filter((m) => !m.deleted)
|
||||
.every((m) => m.content !== content)
|
||||
}, 4000)
|
||||
|
||||
t.pass()
|
||||
})
|
||||
Reference in New Issue
Block a user