Files
discordeno/tests/messages/get_messages.ts
T
Skillz4Killz 3d39b3878a change: ids to use bigint instead of string (#892)
* p1 of bigints change

* shtuff fixes and bits

* Commit from GitHub Actions (Lint)

* finish bigint structs

* typings fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* blame wolf

* Commit from GitHub Actions (Lint)

* foxed

* Commit from GitHub Actions (Lint)

* fix unit tests

* Commit from GitHub Actions (Lint)

* change: guildUpdate guild ID can't change

* delete server has been renamed to delete guild

* fixes

Co-authored-by: Skillz4Killz <Skillz4Killz@users.noreply.github.com>
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
2021-05-03 18:05:18 +01:00

50 lines
1.5 KiB
TypeScript

import { cache, getMessages, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
Deno.test({
name: "[message] fetch messages",
async fn() {
const message = await sendMessage(tempData.channelId, "Hello World!");
const secondMessage = await sendMessage(
tempData.channelId,
"Hello World 2!",
);
const thirdMessage = await sendMessage(
tempData.channelId,
"Hello World 3!",
);
// Assertions
assertExists(message);
assertExists(secondMessage);
assertExists(thirdMessage);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(
10000,
() =>
cache.messages.has(message.id) &&
cache.messages.has(secondMessage.id) &&
cache.messages.has(thirdMessage.id),
);
// Make sure the message was created.
if (
!cache.messages.has(message.id) ||
!cache.messages.has(secondMessage.id) ||
!cache.messages.has(thirdMessage.id)
) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Fetch the messages
const fetchedMessages = await getMessages(tempData.channelId, {
after: message.id.toString(),
limit: 2,
});
// Check if getMessages has worked
assertEquals(fetchedMessages?.length, 2);
},
...defaultTestOptions,
});