mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 01:40:08 +00:00
* fix: guild create tests * fix(test): use setTimeout instead of while loop and fix some tests * fix(test): fix some test and fix maxMs Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
|
import { assertExists } from "../deps.ts";
|
|
import { cache } from "../../src/cache.ts";
|
|
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
|
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
|
import { delayUntil } from "../util/delay_until.ts";
|
|
|
|
async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
|
const channel = await createChannel(tempData.guildId, {
|
|
name: "Discordeno-test",
|
|
});
|
|
|
|
assertExists(channel);
|
|
// Wait few seconds for the channel create event to arrive and cache it
|
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
|
|
|
const message = type === "raw"
|
|
? await sendMessage(channel.id, "Hello World!")
|
|
: await channel.send("Hello World!");
|
|
|
|
// Assertions
|
|
assertExists(message);
|
|
|
|
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
|
await delayUntil(10000, () => cache.messages.has(message.id));
|
|
|
|
if (!cache.messages.has(message.id)) {
|
|
throw new Error("The message seemed to be sent but it was not cached.");
|
|
}
|
|
}
|
|
|
|
Deno.test({
|
|
name: "[message] send a new message",
|
|
async fn() {
|
|
await ifItFailsBlameWolf("raw");
|
|
},
|
|
...defaultTestOptions,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[message] channel.send()",
|
|
async fn() {
|
|
await ifItFailsBlameWolf("getter");
|
|
},
|
|
...defaultTestOptions,
|
|
});
|