mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-31 16:00:07 +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>
68 lines
1.9 KiB
TypeScript
68 lines
1.9 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 { deleteMessage } from "../../src/helpers/messages/delete_message.ts";
|
|
import { delayUntil } from "../util/delay_until.ts";
|
|
|
|
async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
|
|
const message = await sendMessage(tempData.channelId, "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));
|
|
// Make sure the message was created.
|
|
if (!cache.messages.has(message.id)) {
|
|
throw new Error("The message seemed to be sent but it was not cached.");
|
|
}
|
|
|
|
// Delete the message now
|
|
if (type === "raw") {
|
|
await deleteMessage(tempData.channelId, message.id, reason);
|
|
} else {
|
|
await message.delete(reason);
|
|
}
|
|
|
|
// Wait 5 seconds to give it time for MESSAGE_DELETE event
|
|
await delayUntil(10000, () => !cache.messages.has(message.id));
|
|
// Make sure it is gone from cache
|
|
if (cache.messages.has(message.id)) {
|
|
throw new Error(
|
|
"The message should have been deleted but it is still in cache.",
|
|
);
|
|
}
|
|
}
|
|
|
|
Deno.test({
|
|
name: "[message] delete a message without a reason.",
|
|
async fn() {
|
|
await ifItFailsBlameWolf("raw");
|
|
},
|
|
...defaultTestOptions,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[message] delete a message with a reason.",
|
|
async fn() {
|
|
await ifItFailsBlameWolf("raw", "with a reason");
|
|
},
|
|
...defaultTestOptions,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[message] message.delete() without a reason.",
|
|
async fn() {
|
|
await ifItFailsBlameWolf("getter");
|
|
},
|
|
...defaultTestOptions,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[message] message.delete() with a reason.",
|
|
async fn() {
|
|
await ifItFailsBlameWolf("getter", "with a reason");
|
|
},
|
|
...defaultTestOptions,
|
|
});
|