tests: add all messages tests

This commit is contained in:
TriForMine
2021-04-10 10:54:30 +02:00
parent 69b8fe4545
commit 63675aa818
10 changed files with 499 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
import { cache, delay, getPins, pin, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { DiscordenoMessage } from "../../src/structures/message.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw") {
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 delay(5000);
if (!cache.messages.has(message.id)) {
throw new Error(
"The message seemed to be sent but it was not cached.",
);
}
if (type === "raw") {
await pin(message.channelId, message.id);
} else {
await message.pin();
}
const pins = await getPins(tempData.channelId);
assertEquals(
pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length,
1,
);
}
Deno.test({
name: "[message] pin a message",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.pin()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});