throw together some scuffed integration testing infra
This commit is contained in:
@@ -1,60 +1,17 @@
|
||||
import { raise } from "@reacord/helpers/raise"
|
||||
import type { TextBasedChannel } from "discord.js"
|
||||
import {
|
||||
CategoryChannel,
|
||||
ChannelType,
|
||||
ComponentType,
|
||||
GatewayIntentBits,
|
||||
} from "discord.js"
|
||||
import { ComponentType } from "discord.js"
|
||||
import React from "react"
|
||||
import { beforeAll, expect, test } from "vitest"
|
||||
import { createDiscordClient } from "../library/create-discord-client"
|
||||
import {
|
||||
ActionRow,
|
||||
Button,
|
||||
Option,
|
||||
ReacordClient,
|
||||
Select,
|
||||
} from "../library/main"
|
||||
import { testEnv } from "./test-env"
|
||||
import { ActionRow, Button, Option, Select } from "../library/main"
|
||||
import { ReacordTester } from "./tester"
|
||||
|
||||
let channel: TextBasedChannel
|
||||
let tester: ReacordTester
|
||||
beforeAll(async () => {
|
||||
const client = await createDiscordClient(testEnv.TEST_BOT_TOKEN, {
|
||||
intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages,
|
||||
})
|
||||
|
||||
const category =
|
||||
client.channels.cache.get(testEnv.TEST_CATEGORY_ID) ??
|
||||
(await client.channels.fetch(testEnv.TEST_CATEGORY_ID))
|
||||
|
||||
if (!(category instanceof CategoryChannel)) {
|
||||
throw new TypeError("Category channel not found")
|
||||
}
|
||||
|
||||
const channelName = "test-channel"
|
||||
|
||||
let existing = category.children.cache.find((the) => the.name === channelName)
|
||||
if (!existing || !existing.isTextBased()) {
|
||||
existing = await category.children.create({
|
||||
type: ChannelType.GuildText,
|
||||
name: channelName,
|
||||
})
|
||||
}
|
||||
channel = existing
|
||||
|
||||
for (const [, message] of await channel.messages.fetch()) {
|
||||
await message.delete()
|
||||
}
|
||||
tester = await ReacordTester.create()
|
||||
})
|
||||
|
||||
test("action row", async () => {
|
||||
const reacord = new ReacordClient({
|
||||
token: testEnv.TEST_BOT_TOKEN,
|
||||
})
|
||||
|
||||
reacord.send(
|
||||
channel.id,
|
||||
const { message } = await tester.render(
|
||||
"action row",
|
||||
<>
|
||||
<Button label="outside button" onClick={() => {}} />
|
||||
<ActionRow>
|
||||
@@ -68,10 +25,6 @@ test("action row", async () => {
|
||||
</>,
|
||||
)
|
||||
|
||||
const message = await channel
|
||||
.awaitMessages({ max: 1 })
|
||||
.then((result) => result.first() ?? raise("message not found"))
|
||||
|
||||
expect(message.components.map((c) => c.toJSON())).toEqual([
|
||||
{
|
||||
type: ComponentType.ActionRow,
|
||||
@@ -109,4 +62,4 @@ test("action row", async () => {
|
||||
],
|
||||
},
|
||||
])
|
||||
}, 15_000)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user