mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { cache, 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";
|
|
import { delayUntil } from "../util/delay_until.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 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.");
|
|
}
|
|
|
|
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,
|
|
});
|