mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
tests: use delayUntil instead of delay
This commit is contained in:
@@ -3,7 +3,7 @@ import { assertExists } from "../deps.ts";
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { categoryChildren, createChannel } from "../../src/helpers/mod.ts";
|
||||
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] category channel ids",
|
||||
@@ -16,11 +16,11 @@ Deno.test({
|
||||
// Assertions
|
||||
assertExists(category);
|
||||
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.channels.has(category.id));
|
||||
|
||||
if (!cache.channels.has(category.id)) {
|
||||
throw new Error(
|
||||
"The channel seemed to be created but it was not cached."
|
||||
"The channel seemed to be created but it was not cached.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,15 +31,15 @@ Deno.test({
|
||||
name: `Discordeno-test-${num}`,
|
||||
parentId: category.id,
|
||||
})
|
||||
)
|
||||
),
|
||||
);
|
||||
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => channels.every((c) => cache.channels.has(c.id)));
|
||||
|
||||
// If every channel is not present in the cache, error out
|
||||
if (!channels.every((c) => cache.channels.has(c.id))) {
|
||||
throw new Error(
|
||||
"The channels seemed to be created but it was not cached."
|
||||
"The channels seemed to be created but it was not cached.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ Deno.test({
|
||||
!channels.every((c) => ids.has(c.id))
|
||||
) {
|
||||
throw new Error(
|
||||
"The category channel ids did not match with the category channels."
|
||||
"The category channel ids did not match with the category channels.",
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3,8 +3,8 @@ import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
||||
const channel = await createChannel(tempData.guildId, options);
|
||||
@@ -16,7 +16,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
||||
if (save) tempData.channelId = channel.id;
|
||||
|
||||
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.channels.has(channel.id));
|
||||
|
||||
if (!cache.channels.has(channel.id)) {
|
||||
throw new Error("The channel seemed to be created but it was not cached.");
|
||||
@@ -24,13 +24,13 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
||||
|
||||
if (options.topic && channel.topic !== options.topic) {
|
||||
throw new Error(
|
||||
"The channel was supposed to have a topic but it does not appear to be the same topic."
|
||||
"The channel was supposed to have a topic but it does not appear to be the same topic.",
|
||||
);
|
||||
}
|
||||
|
||||
if (options.bitrate && channel.bitrate !== options.bitrate) {
|
||||
throw new Error(
|
||||
"The channel was supposed to have a bitrate but it does not appear to be the same bitrate."
|
||||
"The channel was supposed to have a bitrate but it does not appear to be the same bitrate.",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ Deno.test({
|
||||
name: "Discordeno-test",
|
||||
type: DiscordChannelTypes.GUILD_CATEGORY,
|
||||
},
|
||||
true
|
||||
true,
|
||||
);
|
||||
},
|
||||
...defaultTestOptions,
|
||||
@@ -81,7 +81,7 @@ Deno.test({
|
||||
name: "Discordeno-test",
|
||||
type: DiscordChannelTypes.GUILD_VOICE,
|
||||
},
|
||||
true
|
||||
true,
|
||||
);
|
||||
},
|
||||
...defaultTestOptions,
|
||||
@@ -96,7 +96,7 @@ Deno.test({
|
||||
type: DiscordChannelTypes.GUILD_VOICE,
|
||||
bitrate: 32000,
|
||||
},
|
||||
true
|
||||
true,
|
||||
);
|
||||
},
|
||||
...defaultTestOptions,
|
||||
@@ -111,7 +111,7 @@ Deno.test({
|
||||
type: DiscordChannelTypes.GUILD_VOICE,
|
||||
userLimit: 32,
|
||||
},
|
||||
true
|
||||
true,
|
||||
);
|
||||
},
|
||||
...defaultTestOptions,
|
||||
@@ -125,7 +125,7 @@ Deno.test({
|
||||
name: "Discordeno-test",
|
||||
rateLimitPerUser: 2423,
|
||||
},
|
||||
true
|
||||
true,
|
||||
);
|
||||
},
|
||||
...defaultTestOptions,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||
import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] delete a channel without a reason.",
|
||||
@@ -12,22 +12,22 @@ Deno.test({
|
||||
name: "delete-channel",
|
||||
});
|
||||
// wait 5 seconds to give it time for CHANNEL_CREATE event
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.channels.has(channel.id));
|
||||
// Make sure the channel was created.
|
||||
if (!cache.channels.has(channel.id)) {
|
||||
throw new Error(
|
||||
"The channel should have been created but it is not in the cache."
|
||||
"The channel should have been created but it is not in the cache.",
|
||||
);
|
||||
}
|
||||
|
||||
// Delete the channel now without a reason
|
||||
await deleteChannel(tempData.guildId, channel.id);
|
||||
// wait 5 seconds to give it time for CHANNEL_DELETE event
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => !cache.channels.has(channel.id));
|
||||
// Make sure it is gone from cache
|
||||
if (cache.channels.has(channel.id)) {
|
||||
throw new Error(
|
||||
"The channel should have been deleted but it is still in cache."
|
||||
"The channel should have been deleted but it is still in cache.",
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -42,22 +42,22 @@ Deno.test({
|
||||
name: "delete-channel",
|
||||
});
|
||||
// wait 5 seconds to give it time for CHANNEL_CREATE event
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.channels.has(channel.id));
|
||||
// Make sure the channel was created.
|
||||
if (!cache.channels.has(channel.id)) {
|
||||
throw new Error(
|
||||
"The channel should have been created but it is not in the cache."
|
||||
"The channel should have been created but it is not in the cache.",
|
||||
);
|
||||
}
|
||||
|
||||
// Delete the channel now without a reason
|
||||
await deleteChannel(tempData.guildId, channel.id, "with a reason");
|
||||
// wait 5 seconds to give it time for CHANNEL_DELETE event
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => !cache.channels.has(channel.id));
|
||||
// Make sure it is gone from cache
|
||||
if (cache.channels.has(channel.id)) {
|
||||
throw new Error(
|
||||
"The channel should have been deleted but it is still in cache."
|
||||
"The channel should have been deleted but it is still in cache.",
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { createGuild } from "../../src/helpers/guilds/create_guild.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] create a new guild",
|
||||
@@ -17,7 +17,7 @@ Deno.test({
|
||||
tempData.guildId = guild.id;
|
||||
|
||||
// Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.guilds.has(guild.id));
|
||||
|
||||
if (!cache.guilds.has(guild.id)) {
|
||||
throw new Error("The guild seemed to be created but it was not cached.");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { deleteServer } from "../../src/helpers/guilds/delete_server.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] delete a guild",
|
||||
@@ -14,7 +14,7 @@ Deno.test({
|
||||
}
|
||||
|
||||
await deleteServer(tempData.guildId);
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.guilds.has(tempData.guildId));
|
||||
|
||||
if (cache.guilds.has(tempData.guildId)) {
|
||||
throw new Error("The guild was not able to be deleted.");
|
||||
|
||||
@@ -2,10 +2,10 @@ import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { DiscordReaction } from "../../src/types/messages/reaction.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
|
||||
import { addReaction } from "../../src/helpers/messages/add_reaction.ts";
|
||||
import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
@@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -33,7 +33,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
}
|
||||
},
|
||||
)
|
||||
).id
|
||||
}>`;
|
||||
@@ -45,16 +45,16 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
|
||||
await message.addReaction(emojiId);
|
||||
}
|
||||
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.messages.get(message.id)?.reactions?.length > 0);
|
||||
|
||||
assertEquals(
|
||||
await cache.messages
|
||||
.get(message.id)
|
||||
?.reactions?.filter(
|
||||
(reaction: DiscordReaction) =>
|
||||
reaction.emoji?.name === (custom ? "blamewolf" : "❤")
|
||||
reaction.emoji?.name === (custom ? "blamewolf" : "❤"),
|
||||
).length,
|
||||
1
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import {
|
||||
addReactions,
|
||||
cache,
|
||||
createEmoji,
|
||||
delay,
|
||||
sendMessage,
|
||||
} from "../../mod.ts";
|
||||
import { addReactions, cache, createEmoji, 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";
|
||||
|
||||
async function ifItFailsBlameWolf(
|
||||
type: "getter" | "raw",
|
||||
custom = false,
|
||||
ordered = false
|
||||
ordered = false,
|
||||
) {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
|
||||
@@ -19,7 +14,7 @@ async function ifItFailsBlameWolf(
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -39,7 +34,7 @@ async function ifItFailsBlameWolf(
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
}
|
||||
},
|
||||
)
|
||||
).id
|
||||
}>`,
|
||||
@@ -53,7 +48,7 @@ async function ifItFailsBlameWolf(
|
||||
name: "blamewolf2",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
}
|
||||
},
|
||||
)
|
||||
).id
|
||||
}>`,
|
||||
@@ -66,7 +61,7 @@ async function ifItFailsBlameWolf(
|
||||
await message.addReactions(emojiIds, ordered);
|
||||
}
|
||||
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.messages.get(message.id)?.reactions?.length > 0);
|
||||
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 2);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { delay } from "../../src/util/utils.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, {
|
||||
@@ -12,10 +12,9 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
|
||||
assertExists(channel);
|
||||
// Wait few seconds for the channel create event to arrive and cache it
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.channels.has(channel.id));
|
||||
|
||||
const message =
|
||||
type === "raw"
|
||||
const message = type === "raw"
|
||||
? await sendMessage(channel.id, "Hello World!")
|
||||
: await channel.send("Hello World!");
|
||||
|
||||
@@ -23,7 +22,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { delay } from "../../src/util/utils.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!");
|
||||
@@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -25,11 +25,11 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
|
||||
}
|
||||
|
||||
// Wait 5 seconds to give it time for MESSAGE_DELETE event
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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."
|
||||
"The message should have been deleted but it is still in cache.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import {
|
||||
cache,
|
||||
delay,
|
||||
deleteMessage,
|
||||
deleteMessages,
|
||||
sendMessage,
|
||||
} from "../../mod.ts";
|
||||
import { cache, deleteMessages, sendMessage } from "../../mod.ts";
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
async function ifItFailsBlameWolf(reason?: string) {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
@@ -14,7 +9,7 @@ async function ifItFailsBlameWolf(reason?: string) {
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -25,7 +20,7 @@ async function ifItFailsBlameWolf(reason?: string) {
|
||||
// Assertions
|
||||
assertExists(secondMessage);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => cache.messages.has(secondMessage.id));
|
||||
// Make sure the message was created.
|
||||
if (!cache.messages.has(secondMessage.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
@@ -35,15 +30,19 @@ async function ifItFailsBlameWolf(reason?: string) {
|
||||
await deleteMessages(
|
||||
tempData.channelId,
|
||||
[message.id, secondMessage.id],
|
||||
reason
|
||||
reason,
|
||||
);
|
||||
|
||||
// Wait 5 seconds to give it time for MESSAGE_DELETE event
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() =>
|
||||
!cache.messages.has(message.id) && !cache.messages.has(secondMessage.id),
|
||||
);
|
||||
// Make sure it is gone from cache
|
||||
if (cache.messages.has(message.id) || cache.messages.has(secondMessage.id)) {
|
||||
throw new Error(
|
||||
"The message should have been deleted but it is still in cache."
|
||||
"The message should have been deleted but it is still in cache.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { cache } from "../../src/cache.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
|
||||
import { editMessage } from "../../src/helpers/messages/edit_message.ts";
|
||||
import { delayUntil } from "../util/delay_until.ts";
|
||||
|
||||
async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
@@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -24,7 +24,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
await message.edit("Goodbye World!");
|
||||
}
|
||||
// Wait 5 seconds to give it time for MESSAGE_UPDATE event
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.content === "Goodbye World!",
|
||||
);
|
||||
|
||||
// Make sure it has been modified in cache
|
||||
assertEquals(cache.messages.get(message.id)?.content, "Goodbye World!");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { cache, delay, getMessage, sendMessage } from "../../mod.ts";
|
||||
import { cache, getMessage, 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 a message",
|
||||
@@ -10,7 +11,7 @@ Deno.test({
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { cache, delay, getMessages, sendMessage } from "../../mod.ts";
|
||||
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",
|
||||
@@ -8,11 +9,11 @@ Deno.test({
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
const secondMessage = await sendMessage(
|
||||
tempData.channelId,
|
||||
"Hello World 2!"
|
||||
"Hello World 2!",
|
||||
);
|
||||
const thirdMessage = await sendMessage(
|
||||
tempData.channelId,
|
||||
"Hello World 3!"
|
||||
"Hello World 3!",
|
||||
);
|
||||
|
||||
// Assertions
|
||||
@@ -20,7 +21,13 @@ Deno.test({
|
||||
assertExists(secondMessage);
|
||||
assertExists(thirdMessage);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() =>
|
||||
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) ||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import {
|
||||
addReaction,
|
||||
cache,
|
||||
delay,
|
||||
getReactions,
|
||||
sendMessage,
|
||||
} from "../../mod.ts";
|
||||
import { addReaction, cache, getReactions, 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 reactions",
|
||||
@@ -16,7 +11,7 @@ Deno.test({
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -28,7 +23,7 @@ Deno.test({
|
||||
const fetchedReactions = await getReactions(
|
||||
tempData.channelId,
|
||||
message.id,
|
||||
"❤"
|
||||
"❤",
|
||||
);
|
||||
// Check if getMessage has worked
|
||||
assertEquals(fetchedReactions.size, 1);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { cache, delay, getPins, pin, sendMessage } from "../../mod.ts";
|
||||
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!");
|
||||
@@ -10,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -25,7 +26,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
const pins = await getPins(tempData.channelId);
|
||||
assertEquals(
|
||||
pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length,
|
||||
1
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
addReactions,
|
||||
cache,
|
||||
delay,
|
||||
removeAllReactions,
|
||||
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";
|
||||
|
||||
async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
@@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -23,7 +23,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Add reactions to the message
|
||||
await addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions?.length === 3,
|
||||
);
|
||||
|
||||
// Be sure that the message has the reactions
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 3);
|
||||
@@ -35,7 +38,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
}
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions === undefined,
|
||||
);
|
||||
|
||||
// Check if the reactions has been deleted
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions, undefined);
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import {
|
||||
addReaction,
|
||||
cache,
|
||||
delay,
|
||||
removeReaction,
|
||||
sendMessage,
|
||||
} from "../../mod.ts";
|
||||
import { addReaction, cache, removeReaction, 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";
|
||||
|
||||
async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
@@ -14,7 +9,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -23,7 +18,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Add reactions to the message
|
||||
await addReaction(message.channelId, message.id, "❤");
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions?.length === 1,
|
||||
);
|
||||
|
||||
// Be sure that the message has the reactions
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1);
|
||||
@@ -35,7 +33,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
}
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions === undefined,
|
||||
);
|
||||
|
||||
// Check if the reactions has been deleted
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions, undefined);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import {
|
||||
addReaction,
|
||||
cache,
|
||||
delay,
|
||||
removeReaction,
|
||||
removeReactionEmoji,
|
||||
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";
|
||||
|
||||
async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
@@ -15,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -24,7 +23,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Add reactions to the message
|
||||
await addReaction(message.channelId, message.id, "❤");
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions?.length === 1,
|
||||
);
|
||||
|
||||
// Be sure that the message has the reactions
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1);
|
||||
@@ -36,7 +38,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
}
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions === undefined,
|
||||
);
|
||||
|
||||
// Check if the reactions has been deleted
|
||||
assertEquals(cache.messages.get(message.id)?.reactions, undefined);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import {
|
||||
addReaction,
|
||||
cache,
|
||||
delay,
|
||||
removeReaction,
|
||||
removeUserReaction,
|
||||
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";
|
||||
|
||||
async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||
@@ -15,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -24,7 +23,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
// Add reactions to the message
|
||||
await addReaction(message.channelId, message.id, "❤");
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions?.length === 1,
|
||||
);
|
||||
|
||||
// Be sure that the message has the reactions
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1);
|
||||
@@ -34,14 +36,17 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
message.channelId,
|
||||
message.id,
|
||||
"❤",
|
||||
message.author.id
|
||||
message.author.id,
|
||||
);
|
||||
} else {
|
||||
//await message.removeUserReaction("❤", message.author.id);
|
||||
}
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(
|
||||
3000,
|
||||
() => cache.messages.get(message.id)?.reactions === undefined,
|
||||
);
|
||||
|
||||
// Check if the reactions has been deleted
|
||||
assertEquals(await cache.messages.get(message.id)?.reactions, undefined);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { cache, delay, getPins, pin, sendMessage, unpin } from "../../mod.ts";
|
||||
import { cache, getPins, pin, sendMessage, unpin } 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!");
|
||||
@@ -10,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delay(3000);
|
||||
delayUntil(3000, () => 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.");
|
||||
@@ -22,7 +23,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
const pins = await getPins(tempData.channelId);
|
||||
assertEquals(
|
||||
pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length,
|
||||
1
|
||||
1,
|
||||
);
|
||||
|
||||
if (type === "raw") {
|
||||
@@ -36,7 +37,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||
assertEquals(
|
||||
removedPins.filter((msg: DiscordenoMessage) => msg.id === message.id)
|
||||
.length,
|
||||
0
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user