From 69230ae78e8c72509c24f445dc3f2211a213b541 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Thu, 2 Dec 2021 16:24:41 +0000 Subject: [PATCH] fix: tests with latest cache --- src/helpers/channels/deleteChannel.ts | 7 +- tests/channels/createChannel.ts | 148 ++++++++ tests/channels/deleteChannel.ts | 40 ++ tests/constants.ts | 2 +- tests/deps.ts | 2 +- tests/guilds/urls.ts | 41 +++ tests/helpers/channels/categoryChannels.ts | 4 +- .../channels/channelOverwriteHasPermission.ts | 5 +- tests/helpers/channels/cloneChannel.ts | 7 +- tests/helpers/channels/createChannel.ts | 4 +- tests/helpers/channels/deleteChannel.ts | 9 +- .../channels/deleteChannelOverwrite.ts | 5 +- tests/helpers/channels/editChannel.ts | 4 +- tests/helpers/emojis/createEmoji.ts | 2 +- tests/helpers/emojis/deleteEmoji.ts | 4 +- tests/helpers/emojis/editEmoji.ts | 4 +- tests/helpers/emojis/getEmoji.ts | 2 +- tests/helpers/emojis/getEmojis.ts | 2 +- tests/helpers/guilds/createGuild.ts | 6 +- tests/helpers/guilds/deleteGuild.ts | 6 +- tests/helpers/guilds/editGuild.ts | 7 +- tests/helpers/guilds/getAuditLogs.ts | 4 +- .../guilds/getAvailableVoiceRegions.ts | 6 +- tests/helpers/guilds/getBan.ts | 5 +- tests/helpers/guilds/getBans.ts | 10 +- tests/helpers/guilds/getGuild.ts | 5 +- tests/helpers/guilds/getVanityUrl.ts | 2 +- .../scheduledEvents/deleteScheduledEvent.ts | 4 +- .../scheduledEvents/editScheduledEvent.ts | 9 +- tests/helpers/invites/createInvite.ts | 2 +- tests/helpers/invites/deleteInvite.ts | 2 +- tests/helpers/invites/getChannelInvites.ts | 2 +- tests/helpers/invites/getInvite.ts | 2 +- tests/helpers/members/fetchMembers.ts | 4 +- tests/helpers/messages/deleteMessage.ts | 12 +- tests/helpers/messages/deleteMessages.ts | 12 +- tests/helpers/messages/editMessage.ts | 4 +- tests/helpers/messages/getMessage.ts | 3 +- tests/helpers/messages/getMessages.ts | 4 +- tests/helpers/messages/pin.ts | 6 +- tests/helpers/messages/reactions.ts | 11 +- tests/helpers/messages/sendMessage.ts | 16 +- tests/helpers/misc/user.ts | 2 +- tests/helpers/roles/createRole.ts | 4 +- tests/helpers/roles/editRole.ts | 2 +- tests/helpers/roles/getRoles.ts | 2 +- tests/members/getDmChannel.ts | 4 +- tests/messages/reactions.ts | 262 +++++++++++++ tests/mod.ts | 346 +++--------------- tests/role/createRoleWithReason.ts | 2 +- tests/role/createRoleWithoutReason.ts | 2 +- 51 files changed, 643 insertions(+), 419 deletions(-) create mode 100644 tests/channels/createChannel.ts create mode 100644 tests/channels/deleteChannel.ts create mode 100644 tests/guilds/urls.ts create mode 100644 tests/messages/reactions.ts diff --git a/src/helpers/channels/deleteChannel.ts b/src/helpers/channels/deleteChannel.ts index 2fa9eee12..d047582f4 100644 --- a/src/helpers/channels/deleteChannel.ts +++ b/src/helpers/channels/deleteChannel.ts @@ -3,7 +3,7 @@ import { Channel } from "../../types/channels/channel.ts"; /** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. Bot needs MANAGE_THREADS permissions in the server if deleting thread. */ export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string) { - const result = await bot.rest.runMethod( + await bot.rest.runMethod( bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(channelId), @@ -11,9 +11,4 @@ export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string reason, } ); - - return bot.transformers.channel(bot, { - channel: result, - guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined, - }); } diff --git a/tests/channels/createChannel.ts b/tests/channels/createChannel.ts new file mode 100644 index 000000000..c6f48f90b --- /dev/null +++ b/tests/channels/createChannel.ts @@ -0,0 +1,148 @@ +import { ChannelTypes, CreateGuildChannel, OverwriteTypes } from "../../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts"; +import { assertExists, assertEquals } from "../deps.ts"; +import { bot, guild } from "../mod.ts"; +import { delayUntil } from "../utils.ts"; + +async function createChannelTests(guildId: bigint, options: CreateGuildChannel, autoDelete: boolean) { + const channel = await bot.helpers.createChannel(guildId, options); + + // Assertions + assertExists(channel); + assertEquals(channel.type, options.type || ChannelTypes.GuildText); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => bot.channels.has(channel.id)); + + if (!bot.channels.has(channel.id)) { + throw new Error("The channel seemed to be created but it was not cached."); + } + + 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."); + } + + 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."); + } + + if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) { + throw new Error( + "The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites." + ); + } + + if (autoDelete) { + await bot.helpers.deleteChannel(channel.id); + } +} + +Deno.test({ + name: "[channel] create a new text channel", + async fn(t) { + await createChannelTests(guild.id, { name: "Discordeno-test" }, false); + }, +}); +Deno.test({ + name: "[channel] create a new category channel", + async fn(t) { + await createChannelTests( + guild.id, + { + name: "Discordeno-test", + type: ChannelTypes.GuildCategory, + }, + false + ); + }, +}); +Deno.test({ + name: "[channel] create a new news channel", + async fn(t) { + await createChannelTests( + CACHED_COMMUNITY_GUILD_ID, + { name: "Discordeno-test", type: ChannelTypes.GuildNews }, + true + ); + }, +}); +Deno.test({ + name: "[channel] create a new voice channel", + async fn(t) { + await createChannelTests( + guild.id, + { + name: "Discordeno-test", + type: ChannelTypes.GuildVoice, + }, + false + ); + }, +}); +Deno.test({ + name: "[channel] create a new voice channel with a bitrate", + async fn(t) { + await createChannelTests( + guild.id, + { + name: "discordeno-test", + type: ChannelTypes.GuildVoice, + bitrate: 32000, + }, + false + ); + }, +}); +Deno.test({ + name: "[channel] create a new voice channel with a user limit", + async fn(t) { + await createChannelTests( + guild.id, + { + name: "Discordeno-test", + type: ChannelTypes.GuildVoice, + userLimit: 32, + }, + false + ); + }, +}); +Deno.test({ + name: "[channel] create a new text channel with a rate limit per user", + async fn(t) { + await createChannelTests( + guild.id, + { + name: "Discordeno-test", + rateLimitPerUser: 2423, + }, + false + ); + }, +}); +Deno.test({ + name: "[channel] create a new text channel with NSFW", + async fn(t) { + await createChannelTests(guild.id, { name: "Discordeno-test", nsfw: true }, false); + }, +}); +Deno.test({ + name: "[channel] create a new text channel with permission overwrites", + async fn(t) { + await createChannelTests( + guild.id, + { + name: "Discordeno-test", + permissionOverwrites: [ + { + id: bot.id, + type: OverwriteTypes.Member, + allow: ["VIEW_CHANNEL"], + deny: [], + }, + ], + }, + false + ); + }, +}); diff --git a/tests/channels/deleteChannel.ts b/tests/channels/deleteChannel.ts new file mode 100644 index 000000000..a297aa358 --- /dev/null +++ b/tests/channels/deleteChannel.ts @@ -0,0 +1,40 @@ +import { bot, guild } from "../mod.ts"; +import { delayUntil } from "../utils.ts"; + +async function deleteChannelTests(guildId: bigint, options: { reason?: string }) { + // Create the necessary channels + const channel = await bot.helpers.createChannel(guildId, { + name: "delete-channel", + }); + + await delayUntil(10000, () => bot.channels.has(channel.id)); + // Make sure the channel was created. + if (!bot.channels.has(channel.id)) { + throw new Error("The channel should have been created but it is not in the cache."); + } + + // Delete the channel now without a reason + await bot.helpers.deleteChannel(channel.id, options.reason); + // wait to give it time for event + await delayUntil(10000, () => !bot.channels.has(channel.id)); + + // Make sure it is gone from cache + if (bot.channels.has(channel.id)) { + throw new Error("The channel should have been deleted but it is still in cache."); + } +} + +Deno.test({ + name: "[channel] delete a channel with a reason", + async fn(t) { + await deleteChannelTests(guild.id, { + reason: "with a reason", + }); + }, +}); +Deno.test({ + name: "[channel] delete a channel without a reason", + async fn(t) { + await deleteChannelTests(guild.id, {}); + }, +}); diff --git a/tests/constants.ts b/tests/constants.ts index 1a26d2f5a..8759a3bef 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -9,5 +9,5 @@ export const sanitizeMode = { // USED FOR ROLE CHANGE EVENTS export const roleChanges = new Map(); - export const banCounters = new Map(); +export const reactionCounters = new Map(); diff --git a/tests/deps.ts b/tests/deps.ts index d913a2991..f2a4ebdda 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -6,4 +6,4 @@ export { assertThrows, assertThrowsAsync } from "https://deno.land/std@0.115.1/testing/asserts.ts"; -export * from "https://deno.land/x/discordeno_cache_plugin@0.0.11/mod.ts"; +export * from "https://deno.land/x/discordeno_cache_plugin@0.0.13/mod.ts"; diff --git a/tests/guilds/urls.ts b/tests/guilds/urls.ts new file mode 100644 index 000000000..b37d3aa6c --- /dev/null +++ b/tests/guilds/urls.ts @@ -0,0 +1,41 @@ +import { assertEquals } from "../deps.ts"; +import { bot, guild } from "../mod.ts"; + +Deno.test({ + name: "[guild] format a guild's icon url", + fn: () => { + assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined); + assertEquals( + bot.helpers.guildIconURL(785384884197392384n, { + icon: 3837424427068676005442449262648382018748n, + }), + "https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" + ); + }, +}); + +Deno.test({ + name: "[guild] format a guild's banner url", + fn: () => { + assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined); + assertEquals( + bot.helpers.guildBannerURL(613425648685547541n, { + banner: 3919584870146358272366452115178209474142n, + }), + "https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128" + ); + }, +}); + +Deno.test({ + name: "[guild] format a guild's splash url", + fn: () => { + assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined); + assertEquals( + bot.helpers.guildSplashURL(785384884197392384n, { + splash: 3837424427068676005442449262648382018748n, + }), + "https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" + ); + }, +}); diff --git a/tests/helpers/channels/categoryChannels.ts b/tests/helpers/channels/categoryChannels.ts index a73f6f1c8..ff2272ab6 100644 --- a/tests/helpers/channels/categoryChannels.ts +++ b/tests/helpers/channels/categoryChannels.ts @@ -1,9 +1,9 @@ -import { Bot } from "../../../src/bot.ts"; import { ChannelTypes } from "../../../src/types/channels/channelTypes.ts"; import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function categoryChildrenTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function categoryChildrenTest(guildId: bigint) { const category = await bot.helpers.createChannel(guildId, { name: "Discordeno-test", type: ChannelTypes.GuildCategory, diff --git a/tests/helpers/channels/channelOverwriteHasPermission.ts b/tests/helpers/channels/channelOverwriteHasPermission.ts index 6749e14d5..3510a900f 100644 --- a/tests/helpers/channels/channelOverwriteHasPermission.ts +++ b/tests/helpers/channels/channelOverwriteHasPermission.ts @@ -1,8 +1,9 @@ -import { Bot, createChannel, ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts"; +import { ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts"; import { assertExists, assertEquals } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function channelOverwriteHasPermissionTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function channelOverwriteHasPermissionTest(guildId: bigint) { const channel = await bot.helpers.createChannel(guildId, { name: "Discordeno-test", permissionOverwrites: [ diff --git a/tests/helpers/channels/cloneChannel.ts b/tests/helpers/channels/cloneChannel.ts index 56e146df2..9ecaff3d0 100644 --- a/tests/helpers/channels/cloneChannel.ts +++ b/tests/helpers/channels/cloneChannel.ts @@ -1,15 +1,12 @@ -import { Bot } from "../../../src/bot.ts"; import { DiscordenoChannel } from "../../../src/transformers/channel.ts"; import { assertExists, assertEquals } from "../../deps.ts"; +import { bot, channel } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; export async function cloneChannelTests( - bot: Bot, - guildId: bigint, - channel: DiscordenoChannel, options: { reason?: string }, - t: Deno.TestContext ) { + // @ts-ignore for itoh const cloned = await bot.helpers.cloneChannel(channel, options.reason); //Assertations diff --git a/tests/helpers/channels/createChannel.ts b/tests/helpers/channels/createChannel.ts index 4165c21fc..4e94ee5be 100644 --- a/tests/helpers/channels/createChannel.ts +++ b/tests/helpers/channels/createChannel.ts @@ -1,15 +1,13 @@ -import { Bot } from "../../../src/bot.ts"; import { CreateGuildChannel } from "../../../src/types/guilds/createGuildChannel.ts"; import { ChannelTypes } from "../../../src/types/mod.ts"; import { assertExists, assertEquals } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; export async function createChannelTests( - bot: Bot, guildId: bigint, options: CreateGuildChannel, autoDelete: boolean, - t: Deno.TestContext ) { const channel = await bot.helpers.createChannel(guildId, options); diff --git a/tests/helpers/channels/deleteChannel.ts b/tests/helpers/channels/deleteChannel.ts index 2d8b0dde8..40edb4bb3 100644 --- a/tests/helpers/channels/deleteChannel.ts +++ b/tests/helpers/channels/deleteChannel.ts @@ -1,9 +1,7 @@ -import { Bot } from "../../../src/bot.ts"; -import { Channel } from "../../../src/types/channels/channel.ts"; -import { SnakeCasedPropertiesDeep } from "../../../src/types/util.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function deleteChannelTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) { +export async function deleteChannelTests(guildId: bigint, options: { reason?: string }) { // Create the necessary channels const channel = await bot.helpers.createChannel(guildId, { name: "delete-channel", @@ -15,12 +13,11 @@ export async function deleteChannelTests(bot: Bot, guildId: bigint, options: { r throw new Error("The channel should have been created but it is not in the cache."); } - const CHANNEL_DELETE = bot.handlers.CHANNEL_DELETE; - // Delete the channel now without a reason await bot.helpers.deleteChannel(channel.id, options.reason); // wait to give it time for event await delayUntil(10000, () => !bot.channels.has(channel.id)); + // Make sure it is gone from cache if (bot.channels.has(channel.id)) { throw new Error("The channel should have been deleted but it is still in cache."); diff --git a/tests/helpers/channels/deleteChannelOverwrite.ts b/tests/helpers/channels/deleteChannelOverwrite.ts index 5e3ec0fcc..b7baa9a1e 100644 --- a/tests/helpers/channels/deleteChannelOverwrite.ts +++ b/tests/helpers/channels/deleteChannelOverwrite.ts @@ -1,8 +1,9 @@ -import { Bot, ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts"; +import { ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts"; import { assertExists, assertEquals } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function deleteChannelOverwriteTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function deleteChannelOverwriteTests(guildId: bigint) { const channel = await bot.helpers.createChannel(guildId, { name: "Discordeno-test", permissionOverwrites: [ diff --git a/tests/helpers/channels/editChannel.ts b/tests/helpers/channels/editChannel.ts index 906d935d0..2aac35c7c 100644 --- a/tests/helpers/channels/editChannel.ts +++ b/tests/helpers/channels/editChannel.ts @@ -1,8 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; import { assertEquals } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function editChannelTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) { +export async function editChannelTests(guildId: bigint, options: { reason?: string }) { // Create the necessary channels const channel = await bot.helpers.createChannel(guildId, { name: "edit-channel", diff --git a/tests/helpers/emojis/createEmoji.ts b/tests/helpers/emojis/createEmoji.ts index b37381215..ffa9cc99e 100644 --- a/tests/helpers/emojis/createEmoji.ts +++ b/tests/helpers/emojis/createEmoji.ts @@ -2,7 +2,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; -export async function createEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function createEmojiTest(guildId: bigint) { const emoji = await bot.helpers.createEmoji(guildId, { name: "blamewolf", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", diff --git a/tests/helpers/emojis/deleteEmoji.ts b/tests/helpers/emojis/deleteEmoji.ts index 9ffacd639..dcdea4c26 100644 --- a/tests/helpers/emojis/deleteEmoji.ts +++ b/tests/helpers/emojis/deleteEmoji.ts @@ -28,10 +28,10 @@ export async function ifItFailsBlameWolf(bot: Bot, guildId: bigint, reason?: str // } } -export async function deleteEmojiWithReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function deleteEmojiWithReasonTest(guildId: bigint) { await ifItFailsBlameWolf(bot, guildId); } -export async function deleteEmojiWithoutReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function deleteEmojiWithoutReasonTest(guildId: bigint) { await ifItFailsBlameWolf(bot, guildId, "with a reason"); } diff --git a/tests/helpers/emojis/editEmoji.ts b/tests/helpers/emojis/editEmoji.ts index 95b0a7491..38b99c4de 100644 --- a/tests/helpers/emojis/editEmoji.ts +++ b/tests/helpers/emojis/editEmoji.ts @@ -2,6 +2,4 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; -export async function editEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - -} +export async function editEmojiTest(guildId: bigint) {} diff --git a/tests/helpers/emojis/getEmoji.ts b/tests/helpers/emojis/getEmoji.ts index 7e86e0938..58fa842ce 100644 --- a/tests/helpers/emojis/getEmoji.ts +++ b/tests/helpers/emojis/getEmoji.ts @@ -2,7 +2,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; -export async function getEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getEmojiTest(guildId: bigint) { const emoji = await bot.helpers.createEmoji(guildId, { name: "blamewolf", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", diff --git a/tests/helpers/emojis/getEmojis.ts b/tests/helpers/emojis/getEmojis.ts index e95d47c80..062e0ce4e 100644 --- a/tests/helpers/emojis/getEmojis.ts +++ b/tests/helpers/emojis/getEmojis.ts @@ -2,7 +2,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; -export async function getEmojisTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getEmojisTest(guildId: bigint) { const emoji = await bot.helpers.createEmoji(guildId, { name: "blamewolf", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", diff --git a/tests/helpers/guilds/createGuild.ts b/tests/helpers/guilds/createGuild.ts index 4f397f486..f38e55679 100644 --- a/tests/helpers/guilds/createGuild.ts +++ b/tests/helpers/guilds/createGuild.ts @@ -1,10 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; -import { CreateGuildChannel } from "../../../src/types/guilds/createGuildChannel.ts"; -import { ChannelTypes } from "../../../src/types/mod.ts"; import { assertExists, assertEquals } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function createGuildTests(bot: Bot, t: Deno.TestContext) { +export async function createGuildTests() { const guild = await bot.helpers.createGuild({ name: "Isekai Maid Fake Server", }); diff --git a/tests/helpers/guilds/deleteGuild.ts b/tests/helpers/guilds/deleteGuild.ts index 37af9a269..ab5ac70af 100644 --- a/tests/helpers/guilds/deleteGuild.ts +++ b/tests/helpers/guilds/deleteGuild.ts @@ -1,8 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; -import { assertExists, assertEquals } from "../../deps.ts"; +import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function deleteGuildTests(bot: Bot, t: Deno.TestContext) { +export async function deleteGuildTests() { const guild = await bot.helpers.createGuild({ name: "Isekai Maid Fake Server", }); diff --git a/tests/helpers/guilds/editGuild.ts b/tests/helpers/guilds/editGuild.ts index 25b5c9a1c..10abc63da 100644 --- a/tests/helpers/guilds/editGuild.ts +++ b/tests/helpers/guilds/editGuild.ts @@ -1,8 +1,7 @@ -import { Bot } from "../../../src/bot.ts"; -import { assertExists, assertEquals } from "../../deps.ts"; -import { delayUntil } from "../../utils.ts"; +import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; -export async function editGuildTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function editGuildTests(guildId: bigint) { const guild = await bot.helpers.editGuild( guildId, { diff --git a/tests/helpers/guilds/getAuditLogs.ts b/tests/helpers/guilds/getAuditLogs.ts index 4c5b3c942..c238ec818 100644 --- a/tests/helpers/guilds/getAuditLogs.ts +++ b/tests/helpers/guilds/getAuditLogs.ts @@ -1,7 +1,7 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; -export async function getAuditLogsTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getAuditLogsTests(guildId: bigint) { const logs = await bot.helpers.getAuditLogs(guildId); // Assertions diff --git a/tests/helpers/guilds/getAvailableVoiceRegions.ts b/tests/helpers/guilds/getAvailableVoiceRegions.ts index d63fa61c1..84f00a8e3 100644 --- a/tests/helpers/guilds/getAvailableVoiceRegions.ts +++ b/tests/helpers/guilds/getAvailableVoiceRegions.ts @@ -1,7 +1,7 @@ -import { Bot } from "../../../src/bot.ts"; -import { assertExists, assertEquals } from "../../deps.ts"; +import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; -export async function getAvailableVoiceRegionsTests(bot: Bot, t: Deno.TestContext) { +export async function getAvailableVoiceRegionsTests() { const regions = await bot.helpers.getAvailableVoiceRegions(); // Assertions diff --git a/tests/helpers/guilds/getBan.ts b/tests/helpers/guilds/getBan.ts index c8f31f5f0..222035b55 100644 --- a/tests/helpers/guilds/getBan.ts +++ b/tests/helpers/guilds/getBan.ts @@ -1,8 +1,7 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists, assertEquals } from "../../deps.ts"; -import { delayUntil } from "../../utils.ts"; +import { bot } from "../../mod.ts"; -export async function getBanTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getBanTests(guildId: bigint) { await bot.helpers.banMember(guildId, 379643682984296448n); const fetchedBan = await bot.helpers.getBan(guildId, 379643682984296448n); diff --git a/tests/helpers/guilds/getBans.ts b/tests/helpers/guilds/getBans.ts index ac1ca7061..672a9e5f4 100644 --- a/tests/helpers/guilds/getBans.ts +++ b/tests/helpers/guilds/getBans.ts @@ -1,11 +1,7 @@ -import { Bot } from "../../../src/bot.ts"; -import { CreateGuildChannel } from "../../../src/types/guilds/createGuildChannel.ts"; -import { ChannelTypes } from "../../../src/types/mod.ts"; -import { assertExists, assertEquals } from "../../deps.ts"; -import { delayUntil } from "../../utils.ts"; -import { getAvailableVoiceRegions } from "../../../src/helpers/guilds/getAvailableVoiceRegions.ts"; +import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; -export async function getBansTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getBansTests(guildId: bigint) { await bot.helpers.banMember(guildId, 416477607966670869n); await bot.helpers.banMember(guildId, 635383782576357407n); diff --git a/tests/helpers/guilds/getGuild.ts b/tests/helpers/guilds/getGuild.ts index e604ccb95..daa4acc83 100644 --- a/tests/helpers/guilds/getGuild.ts +++ b/tests/helpers/guilds/getGuild.ts @@ -1,8 +1,7 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists, assertEquals } from "../../deps.ts"; -import { delayUntil } from "../../utils.ts"; +import { bot } from "../../mod.ts"; -export async function getGuildTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getGuildTests(guildId: bigint) { const fetchedGuild = await bot.helpers.getGuild(guildId); // Assertions diff --git a/tests/helpers/guilds/getVanityUrl.ts b/tests/helpers/guilds/getVanityUrl.ts index ee80a5dab..dfd4cbabc 100644 --- a/tests/helpers/guilds/getVanityUrl.ts +++ b/tests/helpers/guilds/getVanityUrl.ts @@ -1,7 +1,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists, assertEquals } from "../../deps.ts"; -export async function getVanityURLTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getVanityURLTests(guildId: bigint) { // TODO: VANITY IS BROKEN ATM FROM DISCORDS SIDE return; // const fetchedVanityURL = await bot.helpers.getVanityURL(guildId); diff --git a/tests/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts b/tests/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts index 2d29f35b7..40ba5d230 100644 --- a/tests/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts +++ b/tests/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts @@ -1,6 +1,4 @@ import { Bot } from "../../../../src/bot.ts"; import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../../src/types/guilds/scheduledEvents.ts"; -export async function deleteScheduledEventTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { - -} +export async function deleteScheduledEventTests(guildId: bigint) {} diff --git a/tests/helpers/guilds/scheduledEvents/editScheduledEvent.ts b/tests/helpers/guilds/scheduledEvents/editScheduledEvent.ts index 1530caf40..416af9591 100644 --- a/tests/helpers/guilds/scheduledEvents/editScheduledEvent.ts +++ b/tests/helpers/guilds/scheduledEvents/editScheduledEvent.ts @@ -1,9 +1,12 @@ -import { Bot } from "../../../../src/bot.ts"; import { ChannelTypes } from "../../../../src/types/channels/channelTypes.ts"; -import { CreateScheduledEvent, ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../../src/types/guilds/scheduledEvents.ts"; +import { + ScheduledEventEntityType, + ScheduledEventPrivacyLevel, +} from "../../../../src/types/guilds/scheduledEvents.ts"; import { assertEquals } from "../../../deps.ts"; +import { bot } from "../../../mod.ts"; -export async function editScheduledEventTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function editScheduledEventTests(guildId: bigint) { const channel = await bot.helpers.createChannel(guildId, { name: "entity", type: ChannelTypes.GuildStageVoice, diff --git a/tests/helpers/invites/createInvite.ts b/tests/helpers/invites/createInvite.ts index f8864779e..b5f444e2a 100644 --- a/tests/helpers/invites/createInvite.ts +++ b/tests/helpers/invites/createInvite.ts @@ -1,7 +1,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; -export async function createInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function createInviteTest(channelId: bigint) { const invite = await bot.helpers.createInvite(channelId, { maxAge: 86400, maxUses: 0, diff --git a/tests/helpers/invites/deleteInvite.ts b/tests/helpers/invites/deleteInvite.ts index 8f0db9724..9c6a51746 100644 --- a/tests/helpers/invites/deleteInvite.ts +++ b/tests/helpers/invites/deleteInvite.ts @@ -1,7 +1,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; -export async function deleteInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function deleteInviteTest(channelId: bigint) { const invite = await bot.helpers.createInvite(channelId, { maxAge: 86400, maxUses: 0, diff --git a/tests/helpers/invites/getChannelInvites.ts b/tests/helpers/invites/getChannelInvites.ts index cb7f97db2..59dc44484 100644 --- a/tests/helpers/invites/getChannelInvites.ts +++ b/tests/helpers/invites/getChannelInvites.ts @@ -1,7 +1,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; -export async function getChannelInvitesTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function getChannelInvitesTest(channelId: bigint) { const invite = await bot.helpers.createInvite(channelId, { maxAge: 86400, maxUses: 0, diff --git a/tests/helpers/invites/getInvite.ts b/tests/helpers/invites/getInvite.ts index b78854093..2242e5af2 100644 --- a/tests/helpers/invites/getInvite.ts +++ b/tests/helpers/invites/getInvite.ts @@ -1,7 +1,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertEquals, assertExists } from "../../deps.ts"; -export async function getInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function getInviteTest(channelId: bigint) { const invite = await bot.helpers.createInvite(channelId, { maxAge: 86400, maxUses: 0, diff --git a/tests/helpers/members/fetchMembers.ts b/tests/helpers/members/fetchMembers.ts index 1bf018a87..9900fd272 100644 --- a/tests/helpers/members/fetchMembers.ts +++ b/tests/helpers/members/fetchMembers.ts @@ -1,6 +1,4 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; -export async function fetchSingleMemberTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - -} +export async function fetchSingleMemberTest(guildId: bigint) {} diff --git a/tests/helpers/messages/deleteMessage.ts b/tests/helpers/messages/deleteMessage.ts index e0ad6ae76..a6a718e55 100644 --- a/tests/helpers/messages/deleteMessage.ts +++ b/tests/helpers/messages/deleteMessage.ts @@ -1,8 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) { +async function ifItFailsBlameWolf(channelId: bigint, reason?: string) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); // Assertions @@ -25,10 +25,10 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) } } -export async function deleteMessageWithoutReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, channelId); +export async function deleteMessageWithoutReasonTest(channelId: bigint) { + await ifItFailsBlameWolf(channelId); } -export async function deleteMessageWithReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, channelId, "with a reason"); +export async function deleteMessageWithReasonTest(channelId: bigint) { + await ifItFailsBlameWolf(channelId, "with a reason"); } diff --git a/tests/helpers/messages/deleteMessages.ts b/tests/helpers/messages/deleteMessages.ts index 3a6235b9a..a285c6b5f 100644 --- a/tests/helpers/messages/deleteMessages.ts +++ b/tests/helpers/messages/deleteMessages.ts @@ -1,8 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) { +async function ifItFailsBlameWolf(channelId: bigint, reason?: string) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); const secondMessage = await bot.helpers.sendMessage(channelId, "Hello World 2!"); @@ -27,10 +27,10 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) } } -export async function deleteMessagesWithoutReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, channelId); +export async function deleteMessagesWithoutReasonTest(channelId: bigint) { + await ifItFailsBlameWolf(channelId); } -export async function deleteMessagesWithReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, channelId, "with a reason"); +export async function deleteMessagesWithReasonTest(channelId: bigint) { + await ifItFailsBlameWolf(channelId, "with a reason"); } diff --git a/tests/helpers/messages/editMessage.ts b/tests/helpers/messages/editMessage.ts index d6659273d..91100fb8e 100644 --- a/tests/helpers/messages/editMessage.ts +++ b/tests/helpers/messages/editMessage.ts @@ -1,8 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function editMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function editMessageTest(channelId: bigint) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); // Assertions diff --git a/tests/helpers/messages/getMessage.ts b/tests/helpers/messages/getMessage.ts index 5059788d5..578cc3982 100644 --- a/tests/helpers/messages/getMessage.ts +++ b/tests/helpers/messages/getMessage.ts @@ -1,8 +1,9 @@ import { Bot } from "../../../src/bot.ts"; import { assertEquals, assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function getMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function getMessageTest(channelId: bigint) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); // Assertions diff --git a/tests/helpers/messages/getMessages.ts b/tests/helpers/messages/getMessages.ts index 708af6e8f..c719eb271 100644 --- a/tests/helpers/messages/getMessages.ts +++ b/tests/helpers/messages/getMessages.ts @@ -1,8 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; import { assertEquals, assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function getMessagesTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function getMessagesTest(channelId: bigint) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); const secondMessage = await bot.helpers.sendMessage(channelId, "Hello World 2!"); const thirdMessage = await bot.helpers.sendMessage(channelId, "Hello World 3!"); diff --git a/tests/helpers/messages/pin.ts b/tests/helpers/messages/pin.ts index a3bdec9de..dfafc6db5 100644 --- a/tests/helpers/messages/pin.ts +++ b/tests/helpers/messages/pin.ts @@ -1,11 +1,11 @@ -import { Bot } from "../../../src/bot.ts"; import { assertEquals } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function pinMessageTests(bot: Bot, channelId: bigint, messageId: bigint, t: Deno.TestContext) { +export async function pinMessageTests(channelId: bigint, messageId: bigint) { let pinned = false; - bot.events.channelPinsUpdate = function (bot, payload) { + bot.events.channelPinsUpdate = function (_, payload) { if (payload.channelId === channelId) pinned = !pinned; }; diff --git a/tests/helpers/messages/reactions.ts b/tests/helpers/messages/reactions.ts index cba6a1087..c891f96cd 100644 --- a/tests/helpers/messages/reactions.ts +++ b/tests/helpers/messages/reactions.ts @@ -1,15 +1,14 @@ import { Bot } from "../../../src/bot.ts"; import { assertEquals, assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; const reactionCounters = new Map(); export async function addReactionTest( - bot: Bot, guildId: bigint, channelId: bigint, - options: { custom: boolean; single: boolean; ordered: boolean }, - t: Deno.TestContext + options: { custom: boolean; single: boolean; ordered: boolean } ) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); @@ -76,7 +75,7 @@ export async function addReactionTest( assertEquals(reactionCounters.get(message.id), options.single ? 1 : emojiIds.length); } -export async function removeAllReactionTests(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function removeAllReactionTests(channelId: bigint) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); // Assertions @@ -117,7 +116,7 @@ export async function removeAllReactionTests(bot: Bot, channelId: bigint, t: Den assertEquals(reactionCounters.get(message.id), 0); } -export async function removeReactionTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function removeReactionTest(channelId: bigint) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); // Assertions @@ -159,7 +158,7 @@ export async function removeReactionTest(bot: Bot, channelId: bigint, t: Deno.Te assertEquals(reactionCounters.get(message.id), 2); } -export async function removeReactionEmojiTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { +export async function removeReactionEmojiTest(channelId: bigint) { const message = await bot.helpers.sendMessage(channelId, "Hello World!"); // Assertions diff --git a/tests/helpers/messages/sendMessage.ts b/tests/helpers/messages/sendMessage.ts index d0c63287b..05792e0c4 100644 --- a/tests/helpers/messages/sendMessage.ts +++ b/tests/helpers/messages/sendMessage.ts @@ -1,11 +1,11 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; import { CreateMessage } from "../../../src/types/messages/createMessage.ts"; import { MessageComponentTypes } from "../../../src/types/messages/components/messageComponentTypes.ts"; import { ButtonStyles } from "../../../src/types/messages/components/buttonStyles.ts"; +import { bot } from "../../mod.ts"; -async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, content: string | CreateMessage) { +async function ifItFailsBlameWolf(channelId: bigint, content: string | CreateMessage) { const message = await bot.helpers.sendMessage(channelId, content); // Assertions assertExists(message); @@ -17,12 +17,12 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, content: string | } } -export async function sendMessageWithTextTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, channelId, "Hello World!"); +export async function sendMessageWithTextTest(channelId: bigint) { + await ifItFailsBlameWolf(channelId, "Hello World!"); } -export async function sendMessageWithComponents(bot: Bot, channelId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, channelId, { +export async function sendMessageWithComponents(channelId: bigint) { + await ifItFailsBlameWolf(channelId, { content: "Hello World!", components: [ { @@ -57,8 +57,8 @@ export async function sendMessageWithComponents(bot: Bot, channelId: bigint, t: }); } -export async function sendMessageWithEmbedsTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, channelId, { +export async function sendMessageWithEmbedsTest(channelId: bigint) { + await ifItFailsBlameWolf(channelId, { embeds: [ { title: "Hello World", diff --git a/tests/helpers/misc/user.ts b/tests/helpers/misc/user.ts index 1937bd024..f66dc2c3a 100644 --- a/tests/helpers/misc/user.ts +++ b/tests/helpers/misc/user.ts @@ -1,6 +1,6 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; -export async function getUserTests(bot: Bot, t: Deno.TestContext) { +export async function getUserTests() { } diff --git a/tests/helpers/roles/createRole.ts b/tests/helpers/roles/createRole.ts index 05dae1692..f38ab2600 100644 --- a/tests/helpers/roles/createRole.ts +++ b/tests/helpers/roles/createRole.ts @@ -1,8 +1,8 @@ -import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; +import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; -export async function createRoleTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) { +export async function createRoleTests(guildId: bigint, options: { reason?: string }) { const role = await bot.helpers.createRole(guildId, { name: "hoti" }, options.reason); assertExists(role); diff --git a/tests/helpers/roles/editRole.ts b/tests/helpers/roles/editRole.ts index 1a82361af..85044631d 100644 --- a/tests/helpers/roles/editRole.ts +++ b/tests/helpers/roles/editRole.ts @@ -2,7 +2,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertEquals, assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; -export async function editRoleTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function editRoleTests(guildId: bigint) { const role = await bot.helpers.createRole(guildId, { name: "hoti", }); diff --git a/tests/helpers/roles/getRoles.ts b/tests/helpers/roles/getRoles.ts index bf0f30761..edb381500 100644 --- a/tests/helpers/roles/getRoles.ts +++ b/tests/helpers/roles/getRoles.ts @@ -1,7 +1,7 @@ import { Bot } from "../../../src/bot.ts"; import { assertEquals } from "../../deps.ts"; -export async function getRolesTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { +export async function getRolesTest(guildId: bigint) { const roles = await bot.helpers.getRoles(guildId); assertEquals(bot.guilds.get(guildId)?.roles.size, roles.size); diff --git a/tests/members/getDmChannel.ts b/tests/members/getDmChannel.ts index f1809db14..fd6e4b232 100644 --- a/tests/members/getDmChannel.ts +++ b/tests/members/getDmChannel.ts @@ -1,7 +1,7 @@ import { bot } from "../mod.ts"; Deno.test("[member] get dm channel and send a message", async () => { - // Skillz ID - const channel = await bot.helpers.getDmChannel(130136895395987456n); + // Itoh Alt ID + const channel = await bot.helpers.getDmChannel(750661528360845322n); await bot.helpers.sendMessage(channel.id, "https://i.imgur.com/doG55NR.png"); }); diff --git a/tests/messages/reactions.ts b/tests/messages/reactions.ts new file mode 100644 index 000000000..7bd762fdd --- /dev/null +++ b/tests/messages/reactions.ts @@ -0,0 +1,262 @@ +import { Bot } from "../../mod.ts"; +import { reactionCounters } from "../constants.ts"; +import { assertExists, assertEquals } from "../deps.ts"; +// import { +// addReactionTest, +// removeReactionTest, +// removeAllReactionTests, +// removeReactionEmojiTest, +// } from "../helpers/messages/reactions.ts"; +import { bot, guild, channel } from "../mod.ts"; +import { delayUntil } from "../utils.ts"; + +export async function addReactionTest( + guildId: bigint, + channelId: bigint, + options: { custom: boolean; single: boolean; ordered: boolean }, +) { + const message = await bot.helpers.sendMessage(channelId, "Hello World!"); + + // Assertions + assertExists(message); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => bot.messages.has(message.id)); + + if (!bot.messages.has(message.id)) { + throw new Error("The message seemed to be sent but it was not cached."); + } + + let emojiId = "❤"; + let emojiIds = ["❤", "😃"]; + + if (options.custom) { + if (options.single) { + emojiId = `<:blamewolf:${ + ( + await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + // roles: [], + }) + ).id + }>`; + } else { + emojiIds = [ + `<:blamewolf:${ + ( + await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + // roles: [], + }) + ).id + }>`, + `<:blamewolf2:${ + ( + await bot.helpers.createEmoji(guildId, { + name: "blamewolf2", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + // roles: [], + }) + ).id + }>`, + ]; + } + } + + reactionCounters.set(message.id, 0); + + bot.events.reactionAdd = function (bot, payload) { + const current = reactionCounters.get(payload.messageId) || 0; + reactionCounters.set(payload.messageId, current + 1); + }; + + if (options.single) await bot.helpers.addReaction(message.channelId, message.id, emojiId); + else await bot.helpers.addReactions(message.channelId, message.id, emojiIds, options.ordered); + + await delayUntil(10000, () => reactionCounters.get(message.id) === (options.single ? 1 : emojiIds.length)); + + assertEquals(reactionCounters.get(message.id), options.single ? 1 : emojiIds.length); +} + +export async function removeAllReactionTests(channelId: bigint) { + const message = await bot.helpers.sendMessage(channelId, "Hello World!"); + + // Assertions + assertExists(message); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => bot.messages.has(message.id)); + + if (!bot.messages.has(message.id)) { + throw new Error("The message seemed to be sent but it was not cached."); + } + + reactionCounters.set(message.id, 0); + + bot.events.reactionRemoveAll = function (_, payload) { + reactionCounters.set(payload.messageId, 0); + }; + + bot.events.reactionAdd = function (_, payload) { + const current = reactionCounters.get(payload.messageId) || 0; + reactionCounters.set(payload.messageId, current + 1); + }; + + // Add reactions to the message + await bot.helpers.addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]); + // Delay the execution to allow event to be processed + await delayUntil(10000, () => reactionCounters.get(message.id) === 3); + + // Be sure that the message has the reactions + assertEquals(reactionCounters.get(message.id), 3); + + await bot.helpers.removeAllReactions(message.channelId, message.id); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => reactionCounters.get(message.id) === 0); + + // Check if the reactions has been deleted + assertEquals(reactionCounters.get(message.id), 0); +} + +export async function removeReactionTest(channelId: bigint) { + const message = await bot.helpers.sendMessage(channelId, "Hello World!"); + + // Assertions + assertExists(message); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => bot.messages.has(message.id)); + + if (!bot.messages.has(message.id)) { + throw new Error("The message seemed to be sent but it was not cached."); + } + + reactionCounters.set(message.id, 0); + + bot.events.reactionRemove = function (bot, payload) { + const current = reactionCounters.get(message.id); + reactionCounters.set(payload.messageId, (current || 0) - 1); + }; + + bot.events.reactionAdd = function (bot, payload) { + const current = reactionCounters.get(payload.messageId) || 0; + reactionCounters.set(payload.messageId, current + 1); + }; + + // Add reactions to the message + await bot.helpers.addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]); + // Delay the execution to allow event to be processed + await delayUntil(10000, () => reactionCounters.get(message.id) === 3); + + // Be sure that the message has the reactions + assertEquals(reactionCounters.get(message.id), 3); + + await bot.helpers.removeReaction(message.channelId, message.id, "😃"); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => reactionCounters.get(message.id) === 2); + + // Check if the reactions has been deleted + assertEquals(reactionCounters.get(message.id), 2); +} + +export async function removeReactionEmojiTest(channelId: bigint) { + const message = await bot.helpers.sendMessage(channelId, "Hello World!"); + + // Assertions + assertExists(message); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => bot.messages.has(message.id)); + + if (!bot.messages.has(message.id)) { + throw new Error("The message seemed to be sent but it was not cached."); + } + + reactionCounters.set(message.id, 0); + + bot.events.reactionAdd; + + bot.events.reactionRemoveEmoji = function (bot, payload) { + reactionCounters.set(payload.messageId, 0); + }; + + bot.events.reactionAdd = function (bot, payload) { + const current = reactionCounters.get(payload.messageId) || 0; + reactionCounters.set(payload.messageId, current + 1); + }; + + // Add reactions to the message + await bot.helpers.addReactions(message.channelId, message.id, ["❤", "😃"]); + // Delay the execution to allow event to be processed + await delayUntil(10000, () => reactionCounters.get(message.id) === 2); + + // Be sure that the message has the reactions + assertEquals(reactionCounters.get(message.id), 2); + + await bot.helpers.removeReactionEmoji(message.channelId, message.id, "😃"); + + // Delay the execution to allow event to be processed + await delayUntil(10000, () => reactionCounters.get(message.id) === 0); + + // Check if the reactions has been deleted + assertEquals(reactionCounters.get(message.id), 0); +} + +Deno.test({ + name: "[message] add a reaction", + fn: async (t) => { + await addReactionTest(guild.id, channel.id, { custom: false, single: true, ordered: false }); + }, +}); +Deno.test({ + name: "[message] add a custom reaction", + fn: async (t) => { + await addReactionTest(guild.id, channel.id, { custom: true, single: true, ordered: false }); + }, +}); +Deno.test({ + name: "[message] add multiple reactions", + fn: async (t) => { + await addReactionTest(guild.id, channel.id, { custom: false, single: false, ordered: false }); + }, +}); +Deno.test({ + name: "[message] add multiple custom reactions", + fn: async (t) => { + await addReactionTest(guild.id, channel.id, { custom: true, single: false, ordered: false }); + }, +}); +Deno.test({ + name: "[message] add multiple reactions in order", + fn: async (t) => { + await addReactionTest(guild.id, channel.id, { custom: false, single: false, ordered: true }); + }, +}); +Deno.test({ + name: "[message] add multiple custom reactions in order", + fn: async (t) => { + await addReactionTest(guild.id, channel.id, { custom: true, single: false, ordered: true }); + }, +}); +Deno.test({ + name: "[message] remove a reaction.", + fn: async (t) => { + await removeReactionTest(channel.id); + }, +}); +Deno.test({ + name: "[message] remove all reactions.", + fn: async (t) => { + await removeAllReactionTests(channel.id); + }, +}); +Deno.test({ + name: "[message] remove emoji reactions.", + fn: async (t) => { + await removeReactionEmojiTest(channel.id); + }, +}); diff --git a/tests/mod.ts b/tests/mod.ts index 965a0bfb5..8c4ba289a 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -63,7 +63,9 @@ const baseBot = createBot({ ], }); -const bot = enableCachePlugin(baseBot); +// @ts-ignore +export const bot = enableCachePlugin(baseBot); +// @ts-ignore await startBot(bot); // Delay the execution to allow READY events to be processed @@ -71,7 +73,7 @@ await delayUntil(10000, () => Boolean(startedAt)); console.log("Bot online"); // DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE -if (bot.guilds.size() <= 10) { +if (bot.guilds.size <= 10) { bot.guilds.forEach(async (guild) => { // DO NOT DELETE OUR CACHED TEST SERVER FOR COMMUNITY FEATURES if (guild.id === CACHED_COMMUNITY_GUILD_ID) return; @@ -107,105 +109,66 @@ export const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz") import "./benchmark.ts"; -Deno.test({ - name: "[guild] format a guild's icon url", - fn: async (t) => { - assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined); - assertEquals( - bot.helpers.guildIconURL(785384884197392384n, { - icon: 3837424427068676005442449262648382018748n, - }), - "https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[guild] format a guild's banner url", - fn: async (t) => { - assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined); - assertEquals( - bot.helpers.guildBannerURL(613425648685547541n, { - banner: 3919584870146358272366452115178209474142n, - }), - "https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128" - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[guild] format a guild's splash url", - fn: async (t) => { - assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined); - assertEquals( - bot.helpers.guildSplashURL(785384884197392384n, { - splash: 3837424427068676005442449262648382018748n, - }), - "https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" - ); - }, - ...sanitizeMode, -}); Deno.test({ name: "[guild] create a guild", fn: async (t) => { - await createGuildTests(bot, t); + await createGuildTests(); }, ...sanitizeMode, }); Deno.test({ name: "[guild] delete a guild", fn: async (t) => { - await deleteGuildTests(bot, t); + await deleteGuildTests(); }, ...sanitizeMode, }); Deno.test({ name: "[guild] edit a guild", fn: async (t) => { - await editGuildTests(bot, guild.id, t); + await editGuildTests(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[guild] get audit logs", fn: async (t) => { - await getAuditLogsTests(bot, guild.id, t); + await getAuditLogsTests(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[guild] get available voice regions", fn: async (t) => { - await getAvailableVoiceRegionsTests(bot, t); + await getAvailableVoiceRegionsTests(); }, ...sanitizeMode, }); Deno.test({ name: "[guild] get a ban", fn: async (t) => { - await getBanTests(bot, guild.id, t); + await getBanTests(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[guild] get bans", fn: async (t) => { - await getBansTests(bot, guild.id, t); + await getBansTests(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[guild] get guilds", fn: async (t) => { - await getGuildTests(bot, guild.id, t); + await getGuildTests(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[guild] get vanity url", fn: async (t) => { - await getVanityURLTests(bot, guild.id, t); + await getVanityURLTests(guild.id); }, ...sanitizeMode, }); @@ -213,140 +176,78 @@ Deno.test({ Deno.test({ name: "[message] send message with text", fn: async (t) => { - await sendMessageWithTextTest(bot, channel.id, t); + await sendMessageWithTextTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] send message with embeds", fn: async (t) => { - await sendMessageWithEmbedsTest(bot, channel.id, t); + await sendMessageWithEmbedsTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] send message with components", fn: async (t) => { - await sendMessageWithComponents(bot, channel.id, t); + await sendMessageWithComponents(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] edit message", fn: async (t) => { - await editMessageTest(bot, channel.id, t); + await editMessageTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] delete message without a reason", fn: async (t) => { - await deleteMessageWithoutReasonTest(bot, channel.id, t); + await deleteMessageWithoutReasonTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] delete message with a reason", fn: async (t) => { - await deleteMessageWithReasonTest(bot, channel.id, t); + await deleteMessageWithReasonTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] delete messages without a reason", fn: async (t) => { - await deleteMessagesWithoutReasonTest(bot, channel.id, t); + await deleteMessagesWithoutReasonTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] delete messages with a reason", fn: async (t) => { - await deleteMessagesWithReasonTest(bot, channel.id, t); + await deleteMessagesWithReasonTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] fetch a message", fn: async (t) => { - await getMessageTest(bot, channel.id, t); + await getMessageTest(channel.id); }, ...sanitizeMode, }); Deno.test({ name: "[message] fetch messages", fn: async (t) => { - await getMessagesTest(bot, channel.id, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] add a reaction", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] add a custom reaction", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] add multiple reactions", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] add multiple custom reactions", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] add multiple reactions in order", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] add multiple custom reactions in order", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] remove a reaction.", - fn: async (t) => { - await removeReactionTest(bot, channel.id, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] remove all reactions.", - fn: async (t) => { - await removeAllReactionTests(bot, channel.id, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[message] remove emoji reactions.", - fn: async (t) => { - await removeReactionEmojiTest(bot, channel.id, t); + await getMessagesTest(channel.id); }, ...sanitizeMode, }); + Deno.test({ name: "[message] pin a message", fn: async (t) => { - await pinMessageTests(bot, channel.id, message.id, t); + await pinMessageTests(channel.id, message.id); }, ...sanitizeMode, }); @@ -354,221 +255,72 @@ Deno.test({ Deno.test({ name: "[channel] send message with text", fn: async (t) => { - await sendMessageWithTextTest(bot, channel.id, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new text channel", - async fn(t) { - await createChannelTests(bot, guild.id, { name: "Discordeno-test" }, false, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new category channel", - async fn(t) { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - type: ChannelTypes.GuildCategory, - }, - false, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new news channel", - async fn(t) { - await createChannelTests( - bot, - CACHED_COMMUNITY_GUILD_ID, - { name: "Discordeno-test", type: ChannelTypes.GuildNews }, - true, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new voice channel", - async fn(t) { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - type: ChannelTypes.GuildVoice, - }, - false, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new voice channel with a bitrate", - async fn(t) { - await createChannelTests( - bot, - guild.id, - { - name: "discordeno-test", - type: ChannelTypes.GuildVoice, - bitrate: 32000, - }, - false, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new voice channel with a user limit", - async fn(t) { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - type: ChannelTypes.GuildVoice, - userLimit: 32, - }, - false, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new text channel with a rate limit per user", - async fn(t) { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - rateLimitPerUser: 2423, - }, - false, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new text channel with NSFW", - async fn(t) { - await createChannelTests(bot, guild.id, { name: "Discordeno-test", nsfw: true }, false, t); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] create a new text channel with permission overwrites", - async fn(t) { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - permissionOverwrites: [ - { - id: bot.id, - type: OverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - false, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] delete a channel with a reason", - async fn(t) { - await deleteChannelTests( - bot, - guild.id, - { - reason: "with a reason", - }, - t - ); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] delete a channel without a reason", - async fn(t) { - await deleteChannelTests(bot, guild.id, {}, t); + await sendMessageWithTextTest(channel.id); }, ...sanitizeMode, }); + + Deno.test({ name: "[channel] filter all category channels", async fn(t) { - await categoryChildrenTest(bot, guild.id, t); + await categoryChildrenTest(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[channel] edit a channel permission overwrite", async fn(t) { - await channelOverwriteHasPermissionTest(bot, guild.id, t); + await channelOverwriteHasPermissionTest(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[channel] clone a channel w/o a reason", async fn(t) { - await cloneChannelTests(bot, guild.id, channel, {}, t); + await cloneChannelTests({}); }, ...sanitizeMode, }); Deno.test({ name: "[channel] clone a channel w/ a reason", async fn(t) { - await cloneChannelTests(bot, guild.id, channel, { reason: "Blame wolf" }, t); + await cloneChannelTests({ reason: "Blame wolf" }); }, ...sanitizeMode, }); Deno.test({ name: "[channel] delete a channel overwrite", async fn(t) { - await deleteChannelOverwriteTests(bot, guild.id, t); + await deleteChannelOverwriteTests(guild.id); }, ...sanitizeMode, }); Deno.test({ name: "[channel] edit a channel w/o a reason", async fn(t) { - await editChannelTests(bot, guild.id, {}, t); + await editChannelTests(guild.id, {}); }, ...sanitizeMode, }); Deno.test({ name: "[channel] edit a channel w/ a reason", async fn(t) { - await editChannelTests(bot, guild.id, { reason: "Blame wolf" }, t); + await editChannelTests(guild.id, { reason: "Blame wolf" }); }, ...sanitizeMode, }); -//channels +// channels import "./channels/connectToVoice.ts"; +import "./channels/createChannel.ts"; +import "./channels/deleteChannel.ts"; import "./channels/getChannel.ts"; import "./channels/getChannels.ts"; import "./channels/stageInstances.ts"; import "./channels/threads.ts"; -//emoji +// emoji import "./emoji/createEmoji.ts"; import "./emoji/deleteEmojiWithReason.ts"; import "./emoji/deleteEmojiWithoutReason.ts"; @@ -577,21 +329,27 @@ import "./emoji/emojiUrl.ts"; import "./emoji/getEmoji.ts"; import "./emoji/getMultipleEmojis.ts"; -//invite +// guilds +import "./guilds/urls.ts"; + +// invite import "./invite/createInvite.ts"; import "./invite/deleteInvite.ts"; import "./invite/getChannelInvites.ts"; import "./invite/getInvite.ts"; import "./invite/getInvites.ts"; -//members +// members import "./members/avatarlUrl.ts"; import "./members/ban.ts"; import "./members/editBotNickname.ts"; import "./members/getDmChannel.ts"; import "./members/getMember.ts"; -//misc +// messages +import "./messages/reactions.ts"; + +// misc import "./misc/getApplicationInfo.ts"; import "./misc/getDiscoveryCategories.ts"; import "./misc/getUser.ts"; @@ -601,7 +359,7 @@ import "./misc/typing.ts"; import "./misc/validateDiscovery.ts"; import "./misc/editBotStatus.ts"; -//role +// role import "./role/addRole.ts"; import "./role/createRoleWithoutReason.ts"; import "./role/createRoleWithReason.ts"; @@ -611,7 +369,7 @@ import "./role/editRole.ts"; import "./role/getAllRoles.ts"; import "./role/removeRole.ts"; -//scheduledEvents +// scheduledEvents import "./scheduledEvents/createExternalEventWithEndtime.ts"; import "./scheduledEvents/createExternalEventWithoutEndtime.ts"; import "./scheduledEvents/createStageEventWithEndtime.ts"; @@ -621,11 +379,9 @@ import "./scheduledEvents/createVoiceEventWithoutEndtime.ts"; import "./scheduledEvents/deleteEvent.ts"; import "./scheduledEvents/editEvent.ts"; -//webhooks +// webhooks import "./webhooks/deleteWebhook.ts"; import "./webhooks/deleteWebhookWithToken.ts"; import "./webhooks/sendWebhook.ts"; import "./webhooks/webhooks.ts"; -// await bot.helpers.deleteGuild(guild.id); -// await stopBot(bot); diff --git a/tests/role/createRoleWithReason.ts b/tests/role/createRoleWithReason.ts index 1b73c0de7..34066d80d 100644 --- a/tests/role/createRoleWithReason.ts +++ b/tests/role/createRoleWithReason.ts @@ -6,7 +6,7 @@ import { delayUntil } from "../utils.ts"; Deno.test({ name: "[Role] create a role with a reason", fn: async (t) => { - await createRoleTests(bot, guild.id, { reason: "Blame wolfy" }, t); + await createRoleTests(guild.id, { reason: "Blame wolfy" }); const role = await bot.helpers.createRole(guild.id, { name: "hoti" }, "Blame wolfy"); diff --git a/tests/role/createRoleWithoutReason.ts b/tests/role/createRoleWithoutReason.ts index 58f51562a..079831ab2 100644 --- a/tests/role/createRoleWithoutReason.ts +++ b/tests/role/createRoleWithoutReason.ts @@ -6,7 +6,7 @@ import { delayUntil } from "../utils.ts"; Deno.test({ name: "[Role] create a role without a reason", fn: async (t) => { - await createRoleTests(bot, guild.id, {}, t); + await createRoleTests(guild.id, {}); const role = await bot.helpers.createRole(guild.id, { name: "hoti" });