From 3d43d7eedfee006b0f90cfec061d6095119d4956 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:26:16 +0000 Subject: [PATCH] remove old tests --- tests/channels/category_children.ts | 48 -- .../channel_overwrite_has_permission.ts | 60 --- tests/channels/clone_channel.ts | 474 ------------------ tests/channels/create_channel.ts | 169 ------- tests/channels/delete_channel.ts | 57 --- tests/channels/delete_channel_overwrite.ts | 61 --- tests/channels/edit_channel.ts | 69 --- tests/channels/edit_channel_overwrite.ts | 72 --- tests/channels/get_channel.ts | 31 -- tests/channels/get_channels.ts | 19 - tests/channels/get_pins.ts | 40 -- tests/channels/is_channel_synced.ts | 58 --- tests/channels/start_typing.ts | 28 -- tests/channels/swap_channels.ts | 56 --- tests/deps.ts | 2 +- tests/discoveries/get_discovery_categories.ts | 13 - tests/discoveries/valid_discovery_term.ts | 13 - tests/emojis/create_emoji.ts | 28 -- tests/emojis/delete_emoji.ts | 45 -- tests/emojis/edit_emoji.ts | 38 -- tests/emojis/get_emoji.ts | 35 -- tests/emojis/get_emojis.ts | 19 - tests/guilds/create_guild.ts | 28 -- tests/guilds/delete_guild.ts | 24 - tests/invites/create_invite.ts | 39 -- tests/invites/delete_invite.ts | 42 -- tests/invites/get_channel_invites.ts | 49 -- tests/invites/get_invite.ts | 43 -- tests/invites/get_invites.ts | 33 -- tests/members/search_members.ts | 25 - tests/messages/add_reaction.ts | 83 --- tests/messages/add_reactions.ts | 122 ----- tests/messages/create_message.ts | 136 ----- tests/messages/delete_message.ts | 65 --- tests/messages/delete_messages.ts | 54 -- tests/messages/edit_message.ts | 47 -- tests/messages/get_message.ts | 27 - tests/messages/get_messages.ts | 41 -- tests/messages/get_reactions.ts | 28 -- tests/messages/pin_message.ts | 44 -- tests/messages/remove_all_reactions.ts | 53 -- tests/messages/remove_reaction.ts | 69 --- tests/messages/remove_reaction_emoji.ts | 53 -- tests/messages/unpin_message.ts | 52 -- tests/roles/add_role.ts | 65 --- tests/roles/create_role.ts | 40 -- tests/roles/delete_role.ts | 50 -- tests/roles/edit_role.ts | 34 -- tests/roles/get_roles.ts | 20 - tests/roles/remove_role.ts | 75 --- tests/util/delay_until.ts | 14 - tests/util/utils.ts | 274 ---------- tests/util/validate_length.ts | 44 -- tests/ws/start_bot.ts | 58 --- tests/ws/ws_close.ts | 17 - 55 files changed, 1 insertion(+), 3282 deletions(-) delete mode 100644 tests/channels/category_children.ts delete mode 100644 tests/channels/channel_overwrite_has_permission.ts delete mode 100644 tests/channels/clone_channel.ts delete mode 100644 tests/channels/create_channel.ts delete mode 100644 tests/channels/delete_channel.ts delete mode 100644 tests/channels/delete_channel_overwrite.ts delete mode 100644 tests/channels/edit_channel.ts delete mode 100644 tests/channels/edit_channel_overwrite.ts delete mode 100644 tests/channels/get_channel.ts delete mode 100644 tests/channels/get_channels.ts delete mode 100644 tests/channels/get_pins.ts delete mode 100644 tests/channels/is_channel_synced.ts delete mode 100644 tests/channels/start_typing.ts delete mode 100644 tests/channels/swap_channels.ts delete mode 100644 tests/discoveries/get_discovery_categories.ts delete mode 100644 tests/discoveries/valid_discovery_term.ts delete mode 100644 tests/emojis/create_emoji.ts delete mode 100644 tests/emojis/delete_emoji.ts delete mode 100644 tests/emojis/edit_emoji.ts delete mode 100644 tests/emojis/get_emoji.ts delete mode 100644 tests/emojis/get_emojis.ts delete mode 100644 tests/guilds/create_guild.ts delete mode 100644 tests/guilds/delete_guild.ts delete mode 100644 tests/invites/create_invite.ts delete mode 100644 tests/invites/delete_invite.ts delete mode 100644 tests/invites/get_channel_invites.ts delete mode 100644 tests/invites/get_invite.ts delete mode 100644 tests/invites/get_invites.ts delete mode 100644 tests/members/search_members.ts delete mode 100644 tests/messages/add_reaction.ts delete mode 100644 tests/messages/add_reactions.ts delete mode 100644 tests/messages/create_message.ts delete mode 100644 tests/messages/delete_message.ts delete mode 100644 tests/messages/delete_messages.ts delete mode 100644 tests/messages/edit_message.ts delete mode 100644 tests/messages/get_message.ts delete mode 100644 tests/messages/get_messages.ts delete mode 100644 tests/messages/get_reactions.ts delete mode 100644 tests/messages/pin_message.ts delete mode 100644 tests/messages/remove_all_reactions.ts delete mode 100644 tests/messages/remove_reaction.ts delete mode 100644 tests/messages/remove_reaction_emoji.ts delete mode 100644 tests/messages/unpin_message.ts delete mode 100644 tests/roles/add_role.ts delete mode 100644 tests/roles/create_role.ts delete mode 100644 tests/roles/delete_role.ts delete mode 100644 tests/roles/edit_role.ts delete mode 100644 tests/roles/get_roles.ts delete mode 100644 tests/roles/remove_role.ts delete mode 100644 tests/util/delay_until.ts delete mode 100644 tests/util/utils.ts delete mode 100644 tests/util/validate_length.ts delete mode 100644 tests/ws/start_bot.ts delete mode 100644 tests/ws/ws_close.ts diff --git a/tests/channels/category_children.ts b/tests/channels/category_children.ts deleted file mode 100644 index eabac74f2..000000000 --- a/tests/channels/category_children.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { categoryChildren, createChannel } from "../../src/helpers/mod.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] category channel ids", - async fn() { - const category = await createChannel(tempData.guildId, { - name: "Discordeno-test", - type: DiscordChannelTypes.GuildCategory, - }); - - // Assertions - assertExists(category); - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const channelsToCreate = [1, 2, 3, 4, 5]; - const channels = await Promise.all( - channelsToCreate.map((num) => - createChannel(tempData.guildId, { - name: `Discordeno-test-${num}`, - parentId: category.id, - }) - ) - ); - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const ids = await categoryChildren(category.id); - if (ids.size !== channelsToCreate.length || !channels.every((c) => ids.has(c.id))) { - throw new Error("The category channel ids did not match with the category channels."); - } - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/channel_overwrite_has_permission.ts b/tests/channels/channel_overwrite_has_permission.ts deleted file mode 100644 index b76c11bcf..000000000 --- a/tests/channels/channel_overwrite_has_permission.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { botId } from "../../src/bot.ts"; -import { cache } from "../../src/cache.ts"; -import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; -import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; -import { bigintToSnowflake } from "../../src/util/bigint.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(options: CreateGuildChannel) { - const channel = await createChannel(tempData.guildId, options); - - // Assertions - assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - 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." - ); - } - - assertEquals( - channelOverwriteHasPermission( - channel.guildId, - botId, - cache.channels.get(channel.id)?.permissionOverwrites || [], - options.permissionOverwrites ? options.permissionOverwrites[0].allow : [] - ), - true - ); -} - -Deno.test({ - name: "[channel] edit channel permission overwrites", - async fn() { - await ifItFailsBlameWolf({ - name: "Discordeno-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/clone_channel.ts b/tests/channels/clone_channel.ts deleted file mode 100644 index a3874537f..000000000 --- a/tests/channels/clone_channel.ts +++ /dev/null @@ -1,474 +0,0 @@ -import { botId } from "../../src/bot.ts"; -import { cache } from "../../src/cache.ts"; -import { cloneChannel } from "../../src/helpers/channels/clone_channel.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; -import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; -import { bigintToSnowflake } from "../../src/util/bigint.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(options: CreateGuildChannel, useGetter = false, reason?: string) { - const channel = await createChannel(tempData.guildId, options); - - const cloned = useGetter ? await channel.clone(reason) : await cloneChannel(channel.id, reason); - - //Assertations - assertExists(cloned); - assertEquals(cloned.type, channel.type); - - // Delay the execution to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => cache.channels.has(cloned.id)); - - if (!cache.channels.has(cloned.id)) { - throw new Error(`The channel seemed to be cloned but was not cached.`); - } - - if (channel.topic && cloned.topic !== channel.topic) { - throw new Error("The clone was supposed to have a topic but it does not appear to be the same topic."); - } - - if (channel.bitrate && cloned.bitrate !== channel.bitrate) { - throw new Error("The clone was supposed to have a bitrate but it does not appear to be the same bitrate."); - } - - if (channel.permissionOverwrites && cloned.permissionOverwrites?.length !== channel.permissionOverwrites.length) { - throw new Error( - "The clone was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites." - ); - } -} - -Deno.test({ - name: "[channel] clone a new text channel", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new text channel w/reason", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, false, "w/reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new category channel", - async fn() { - await ifItFailsBlameWolf({ - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildCategory, - }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new category channel w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildCategory, - }, - false, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new voice channel", - async fn() { - await ifItFailsBlameWolf({ - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new voice channel w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - }, - false, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new voice channel with a bitrate", - async fn() { - await ifItFailsBlameWolf({ - name: "discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - bitrate: 32000, - }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new voice channel with a bitrate w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - bitrate: 32000, - }, - false, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new voice channel with a user limit", - async fn() { - await ifItFailsBlameWolf({ - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - userLimit: 32, - }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new voice channel with a user limit w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - userLimit: 32, - }, - false, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new text channel with a rate limit per user", - async fn() { - await ifItFailsBlameWolf({ - name: "Discordeno-clone-test", - rateLimitPerUser: 2423, - }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new text channel with a rate limit per user w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - rateLimitPerUser: 2423, - }, - false, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new text channel with NSFW", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new text channel with NSFW w/reason", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true }, false, "w/reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new text channel with permission overwrites", - async fn() { - await ifItFailsBlameWolf({ - name: "Discordeno-clone-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone a new text channel with permission overwrites", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - false, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -// GETTERS - -Deno.test({ - name: "[channel] clone() a new text channel", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new text channel w/reason", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, true, "w/reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new category channel", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildCategory, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new category channel w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildCategory, - }, - true, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new voice channel", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new voice channel w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - }, - true, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new voice channel with a bitrate", - async fn() { - await ifItFailsBlameWolf( - { - name: "discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - bitrate: 32000, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new voice channel with a bitrate w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - bitrate: 32000, - }, - true, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new voice channel with a user limit", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - userLimit: 32, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new voice channel with a user limit w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - type: DiscordChannelTypes.GuildVoice, - userLimit: 32, - }, - true, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new text channel with a rate limit per user", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - rateLimitPerUser: 2423, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new text channel with a rate limit per user w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - rateLimitPerUser: 2423, - }, - true, - "w/reason" - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new text channel with NSFW", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true }, true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new text channel with NSFW w/reason", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true }, true, "w/reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new text channel with permission overwrites", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] clone() a new text channel with permission overwrites w/reason", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-clone-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - true, - "w/reason" - ); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts deleted file mode 100644 index 02cbb6dfe..000000000 --- a/tests/channels/create_channel.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { botId } from "../../src/bot.ts"; -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; -import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; -import { bigintToSnowflake } from "../../src/util/bigint.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { - const channel = await createChannel(tempData.guildId, options); - - // Assertions - assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); - - if (save) tempData.channelId = channel.id; - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - 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." - ); - } -} - -Deno.test({ - name: "[channel] create a new text channel", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-test" }, true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] create a new category channel", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-test", - type: DiscordChannelTypes.GuildCategory, - }, - true - ); - }, - ...defaultTestOptions, -}); - -// Deno.test({ -// name: "[channel] create a new news channel", -// async fn() { -// await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_NEWS}, true); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[channel] create a new store channel", -// async fn() { -// await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_STORE}, true); -// }, -// ...defaultTestOptions, -// }); - -Deno.test({ - name: "[channel] create a new voice channel", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-test", - type: DiscordChannelTypes.GuildVoice, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] create a new voice channel with a bitrate", - async fn() { - await ifItFailsBlameWolf( - { - name: "discordeno-test", - type: DiscordChannelTypes.GuildVoice, - bitrate: 32000, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] create a new voice channel with a user limit", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-test", - type: DiscordChannelTypes.GuildVoice, - userLimit: 32, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] create a new text channel with a rate limit per user", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-test", - rateLimitPerUser: 2423, - }, - true - ); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] create a new text channel with NSFW", - async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-test", nsfw: true }, true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] create a new text channel with permission overwrites", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - true - ); - }, - ...defaultTestOptions, -}); -// TODO: Need to validate tests for these options -// /** Sorting position of the channel */ -// position?: number; diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts deleted file mode 100644 index 3ca704d21..000000000 --- a/tests/channels/delete_channel.ts +++ /dev/null @@ -1,57 +0,0 @@ -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 { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] delete a channel without a reason.", - async fn() { - // Create the necessary channels - const channel = await createChannel(tempData.guildId, { - name: "delete-channel", - }); - // wait 5 seconds to give it time for CHANNEL_CREATE event - await 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."); - } - - // Delete the channel now without a reason - await deleteChannel(channel.id); - // wait 5 seconds to give it time for CHANNEL_DELETE event - await 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."); - } - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] delete a channel with a reason.", - async fn() { - // Create the necessary channels - const channel = await createChannel(tempData.guildId, { - name: "delete-channel", - }); - // wait 5 seconds to give it time for CHANNEL_CREATE event - await delayUntil(10000, () => 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."); - } - - // Delete the channel now without a reason - await deleteChannel(channel.id, "with a reason"); - // wait 5 seconds to give it time for CHANNEL_DELETE event - await delayUntil(10000, () => !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."); - } - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/delete_channel_overwrite.ts b/tests/channels/delete_channel_overwrite.ts deleted file mode 100644 index 5da33c086..000000000 --- a/tests/channels/delete_channel_overwrite.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { botId } from "../../src/bot.ts"; -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; -import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; -import { bigintToSnowflake } from "../../src/util/bigint.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { - const channel = await createChannel(tempData.guildId, options); - - // Assertions - assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - 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." - ); - } - - await deleteChannelOverwrite(channel.guildId, channel.id, botId); - - await delayUntil(10000, () => cache.channels.get(channel.id)?.permissionOverwrites?.length === 0); - - if (cache.channels.get(channel.id)?.permissionOverwrites?.length !== 0) { - throw new Error("The channel permission overwrite was supposed to be deleted but it does not appear to be."); - } -} - -Deno.test({ - name: "[channel] create a new text channel with permission overwrites", - async fn() { - await ifItFailsBlameWolf( - { - name: "Discordeno-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - true - ); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/edit_channel.ts b/tests/channels/edit_channel.ts deleted file mode 100644 index 1d5670f4b..000000000 --- a/tests/channels/edit_channel.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { editChannel } from "../../src/helpers/channels/edit_channel.ts"; -import { assertEquals } from "../deps.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { - // Create the necessary channels - const channel = await createChannel(tempData.guildId, { - name: "edit-channel", - }); - // wait 5 seconds to give it time for CHANNEL_CREATE event - await 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."); - } - - // Edit the channel now - if (type === "raw") { - await editChannel( - channel.id, - { - name: "new-name", - }, - reason - ); - } else { - await channel.edit({ - name: "new-name", - }); - } - // wait 5 seconds to give it time for CHANNEL_UPDATE event - await delayUntil(3000, () => cache.channels.get(channel.id)?.name === "new-name"); - assertEquals(cache.channels.get(channel.id)?.name, "new-name"); -} - -Deno.test({ - name: "[channel] edit a channel without a reason.", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] edit a channel with a reason.", - async fn() { - await ifItFailsBlameWolf("raw", "with a reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] channel.edit() without a reason.", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[channel] channel.edit() with a reason.", - async fn() { - await ifItFailsBlameWolf("getter", "with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/edit_channel_overwrite.ts b/tests/channels/edit_channel_overwrite.ts deleted file mode 100644 index a388688d0..000000000 --- a/tests/channels/edit_channel_overwrite.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { botId } from "../../src/bot.ts"; -import { cache } from "../../src/cache.ts"; -import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; -import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; -import { bigintToSnowflake } from "../../src/util/bigint.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(options: CreateGuildChannel) { - const channel = await createChannel(tempData.guildId, options); - - // Assertions - assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - 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." - ); - } - - await editChannelOverwrite(channel.guildId, channel.id, botId, { - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL", "ADD_REACTIONS"], - deny: [], - }); - - await delayUntil(10000, () => - channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites || [], [ - "VIEW_CHANNEL", - "ADD_REACTIONS", - ]) - ); - - assertEquals( - channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites || [], [ - "VIEW_CHANNEL", - "ADD_REACTIONS", - ]), - true - ); -} - -Deno.test({ - name: "[channel] edit channel permission overwrites", - async fn() { - await ifItFailsBlameWolf({ - name: "Discordeno-test", - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/get_channel.ts b/tests/channels/get_channel.ts deleted file mode 100644 index 97e80b897..000000000 --- a/tests/channels/get_channel.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { getChannel } from "../../src/helpers/channels/get_channel.ts"; -import { assertEquals } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] get a channel", - async fn() { - // Create the necessary channels - const channel = await createChannel(tempData.guildId, { - name: "get-channel", - }); - // wait 5 seconds to give it time for CHANNEL_CREATE event - await 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."); - } - - cache.channels.delete(channel.id); - - // Delete the channel now without a reason - await getChannel(channel.id); - await delayUntil(3000, () => cache.channels.has(channel.id)); - - assertEquals(cache.channels.has(channel.id), true); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/get_channels.ts b/tests/channels/get_channels.ts deleted file mode 100644 index 14270fd82..000000000 --- a/tests/channels/get_channels.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { getChannels } from "../../src/helpers/channels/get_channels.ts"; -import { assertEquals } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] get channels.", - async fn() { - cache.channels.clear(); - - // Delete the channel now without a reason - await getChannels(tempData.guildId); - await delayUntil(3000, () => cache.channels.size > 0); - - assertEquals(cache.channels.size > 0, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/get_pins.ts b/tests/channels/get_pins.ts deleted file mode 100644 index 4f15a0829..000000000 --- a/tests/channels/get_pins.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { getPins } from "../../src/helpers/channels/get_pins.ts"; -import { sendMessage } from "../../src/helpers/messages/send_message.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] get pins.", - async fn() { - const channel = await createChannel(tempData.guildId, { - name: "pins-channel", - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const message = await sendMessage(tempData.channelId, "Hello World!"); - const secondMessage = await sendMessage(tempData.channelId, "Goodbye World!"); - - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id) && cache.messages.has(secondMessage.id)); - - await message.pin(); - await secondMessage.pin(); - - const pins = await getPins(tempData.channelId); - - assertEquals(pins.length, 2); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/is_channel_synced.ts b/tests/channels/is_channel_synced.ts deleted file mode 100644 index 61473b65b..000000000 --- a/tests/channels/is_channel_synced.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { botId } from "../../src/bot.ts"; -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; -import { bigintToSnowflake } from "../../src/util/bigint.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] is channel synced.", - async fn() { - const category = await createChannel(tempData.guildId, { - name: "synced-category", - type: DiscordChannelTypes.GuildCategory, - permissionOverwrites: [ - { - id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }); - - // Assertions - assertExists(category); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const channel = await createChannel(tempData.guildId, { - name: "synced-channel", - parentId: category.id, - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const isSynced = await isChannelSynced(channel.id); - - assertEquals(isSynced, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/start_typing.ts b/tests/channels/start_typing.ts deleted file mode 100644 index e9897fc9b..000000000 --- a/tests/channels/start_typing.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { startTyping } from "../../src/helpers/channels/start_typing.ts"; -import { assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] is typing.", - async fn() { - const channel = await createChannel(tempData.guildId, { - name: "typing-channel", - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - await startTyping(channel.id); - }, - ...defaultTestOptions, -}); diff --git a/tests/channels/swap_channels.ts b/tests/channels/swap_channels.ts deleted file mode 100644 index ba369e103..000000000 --- a/tests/channels/swap_channels.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { swapChannels } from "../../src/helpers/channels/swap_channels.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[channel] swap channels", - async fn() { - const channel = await createChannel(tempData.guildId, { - name: "channel-1", - }); - - // Assertions - assertExists(channel); - - const secondChannel = await createChannel(tempData.guildId, { - name: "channel-2", - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => cache.channels.has(channel.id) && cache.channels.has(secondChannel.id)); - - if (!cache.channels.has(channel.id) || !cache.channels.has(secondChannel.id)) { - throw new Error("The channel seemed to be created but it was not cached."); - } - - await swapChannels(tempData.guildId, [ - { - id: channel.id.toString(), - position: secondChannel.position!, - }, - { - id: secondChannel.id.toString(), - position: channel.position!, - }, - ]); - - // Delay the execution by 5 seconds to allow CHANNEL_UPDATE event to be processed - await delayUntil( - 10000, - () => - cache.channels.get(channel.id)?.position === secondChannel.position && - cache.channels.get(secondChannel.id)?.position === channel.position - ); - - assertEquals(cache.channels.get(channel.id)?.position, secondChannel.position); - - assertEquals(cache.channels.get(secondChannel.id)?.position, channel.position); - }, - ...defaultTestOptions, -}); diff --git a/tests/deps.ts b/tests/deps.ts index 75cad4b41..6c7cb054d 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -3,4 +3,4 @@ export { assertEquals, assertExists, assertThrows, -} from "https://deno.land/std@0.97.0/testing/asserts.ts"; +} from "https://deno.land/std@0.113.0/testing/asserts.ts"; diff --git a/tests/discoveries/get_discovery_categories.ts b/tests/discoveries/get_discovery_categories.ts deleted file mode 100644 index 90cf2dd36..000000000 --- a/tests/discoveries/get_discovery_categories.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defaultTestOptions } from "../ws/start_bot.ts"; -import { assertEquals } from "../deps.ts"; -import { getDiscoveryCategories } from "../../src/helpers/discovery/get_discovery_categories.ts"; - -Deno.test({ - name: "[discovery] get categories", - async fn() { - const categories = await getDiscoveryCategories(); - - assertEquals(categories.size > 0, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/discoveries/valid_discovery_term.ts b/tests/discoveries/valid_discovery_term.ts deleted file mode 100644 index 3832b224d..000000000 --- a/tests/discoveries/valid_discovery_term.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defaultTestOptions } from "../ws/start_bot.ts"; -import { assertEquals } from "../deps.ts"; -import { validDiscoveryTerm } from "../../src/helpers/discovery/valid_discovery_term.ts"; - -Deno.test({ - name: "[discovery] get categories", - async fn() { - const valid = await validDiscoveryTerm("Bots"); - - assertEquals(valid, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/emojis/create_emoji.ts b/tests/emojis/create_emoji.ts deleted file mode 100644 index 98cc6626a..000000000 --- a/tests/emojis/create_emoji.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts"; -import { delayUntil } from "../util/delay_until.ts"; - -Deno.test({ - name: "[emoji] create an emoji", - async fn() { - const emoji = await createEmoji( - tempData.guildId, - "blamewolf", - "https://cdn.discordapp.com/emojis/814955268123000832.png", - { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - } - ); - - assertExists(emoji); - - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!)); - - assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!), true); - }, - ...defaultTestOptions, -}); diff --git a/tests/emojis/delete_emoji.ts b/tests/emojis/delete_emoji.ts deleted file mode 100644 index 03cd114d9..000000000 --- a/tests/emojis/delete_emoji.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { deleteEmoji } from "../../src/helpers/emojis/delete_emoji.ts"; - -async function ifItFailsBlameWolf(reason?: string) { - const emoji = await createEmoji( - tempData.guildId, - "blamewolf", - "https://cdn.discordapp.com/emojis/814955268123000832.png", - { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - } - ); - - assertExists(emoji); - - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!)); - - await deleteEmoji(tempData.guildId, emoji.id!, reason); - - await delayUntil(10000, () => !cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!)); - - assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!), false); -} - -Deno.test({ - name: "[emoji] delete an emoji without a reason", - async fn() { - await ifItFailsBlameWolf(); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[emoji] delete an emoji with a reason", - async fn() { - await ifItFailsBlameWolf("with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/emojis/edit_emoji.ts b/tests/emojis/edit_emoji.ts deleted file mode 100644 index 6f481e4a4..000000000 --- a/tests/emojis/edit_emoji.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { editEmoji } from "../../src/helpers/emojis/edit_emoji.ts"; - -Deno.test({ - name: "[emoji] edit an emoji", - async fn() { - const emoji = await createEmoji( - tempData.guildId, - "blamewolf", - "https://cdn.discordapp.com/emojis/814955268123000832.png", - { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - } - ); - - assertExists(emoji); - - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!)); - - await editEmoji(tempData.guildId, emoji.id!, { - name: "blamewolf_infinite", - }); - - await delayUntil( - 10000, - () => cache.guilds.get(tempData.guildId)?.emojis?.get(emoji.id!)?.name === "blamewolf_infinite" - ); - - assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.get(emoji.id!)?.name, "blamewolf_infinite"); - }, - ...defaultTestOptions, -}); diff --git a/tests/emojis/get_emoji.ts b/tests/emojis/get_emoji.ts deleted file mode 100644 index 8cfc5694e..000000000 --- a/tests/emojis/get_emoji.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { getEmoji } from "../../src/helpers/emojis/get_emoji.ts"; - -Deno.test({ - name: "[emoji] get an emoji", - async fn() { - const emoji = await createEmoji( - tempData.guildId, - "blamewolf", - "https://cdn.discordapp.com/emojis/814955268123000832.png", - { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - } - ); - - assertExists(emoji); - - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!)); - - cache.guilds.get(tempData.guildId)?.emojis?.delete(emoji.id!); - - await getEmoji(tempData.guildId, emoji.id!); - - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!)); - - assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!), true); - }, - ...defaultTestOptions, -}); diff --git a/tests/emojis/get_emojis.ts b/tests/emojis/get_emojis.ts deleted file mode 100644 index 60f7544c4..000000000 --- a/tests/emojis/get_emojis.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { getEmojis } from "../../src/helpers/mod.ts"; - -Deno.test({ - name: "[emoji] get emojis", - async fn() { - cache.guilds.get(tempData.guildId)?.emojis?.clear(); - - await getEmojis(tempData.guildId); - - await delayUntil(10000, () => (cache.guilds.get(tempData.guildId)?.emojis?.size || 0) > 0); - - assertEquals((cache.guilds.get(tempData.guildId)?.emojis?.size || 0) > 0, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/guilds/create_guild.ts b/tests/guilds/create_guild.ts deleted file mode 100644 index b2d1978c9..000000000 --- a/tests/guilds/create_guild.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.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", - async fn() { - const guild = await createGuild({ - name: "Discordeno Test", - }); - - // Assertions - assertExists(guild); - assertExists(guild.id); - - tempData.guildId = guild.id; - - // Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed - await delayUntil(10000, () => 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. ${JSON.stringify(guild)}`); - } - }, - ...defaultTestOptions, -}); diff --git a/tests/guilds/delete_guild.ts b/tests/guilds/delete_guild.ts deleted file mode 100644 index 52c2b9955..000000000 --- a/tests/guilds/delete_guild.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[guild] delete a guild", - async fn() { - if (!tempData.guildId) { - throw new Error("The guild id was not available to be deleted."); - } - if (!cache.guilds.has(tempData.guildId)) { - throw new Error("The guild was not cached so impossible to delete."); - } - - await deleteGuild(tempData.guildId); - await delayUntil(10000, () => !cache.guilds.has(tempData.guildId)); - - if (cache.guilds.has(tempData.guildId)) { - throw new Error("The guild was not able to be deleted."); - } - }, - ...defaultTestOptions, -}); diff --git a/tests/invites/create_invite.ts b/tests/invites/create_invite.ts deleted file mode 100644 index 03413ef9e..000000000 --- a/tests/invites/create_invite.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { createInvite } from "../../src/helpers/invites/create_invite.ts"; -import { getInvite } from "../../src/helpers/invites/get_invite.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[invite] create invite", - async fn() { - const channel = await createChannel(tempData.guildId, { - name: "invite-channel", - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const invite = await createInvite(channel.id, { - maxAge: 86400, - maxUses: 0, - temporary: false, - unique: false, - }); - - // Assertions - assertExists(invite); - - assertEquals((await getInvite(invite.code)) !== undefined, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/invites/delete_invite.ts b/tests/invites/delete_invite.ts deleted file mode 100644 index c92b77cf9..000000000 --- a/tests/invites/delete_invite.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { createInvite } from "../../src/helpers/invites/create_invite.ts"; -import { deleteInvite } from "../../src/helpers/invites/delete_invite.ts"; -import { getChannelInvites } from "../../src/helpers/invites/get_channel_invites.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[invite] delete invite", - async fn() { - const channel = await createChannel(tempData.guildId, { - name: "invite-channel", - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const invite = await createInvite(channel.id, { - maxAge: 86400, - maxUses: 0, - temporary: false, - unique: false, - }); - - // Assertions - assertExists(invite); - - await deleteInvite(channel.id, invite.code); - - assertEquals((await getChannelInvites(channel.id))?.size, 0); - }, - ...defaultTestOptions, -}); diff --git a/tests/invites/get_channel_invites.ts b/tests/invites/get_channel_invites.ts deleted file mode 100644 index 80e80c8dd..000000000 --- a/tests/invites/get_channel_invites.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { createInvite } from "../../src/helpers/invites/create_invite.ts"; -import { getChannelInvites } from "../../src/helpers/invites/get_channel_invites.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[invite] get channel invites", - async fn() { - const channel = await createChannel(tempData.guildId, { - name: "invite-channel", - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const invite = await createInvite(channel.id, { - maxAge: 86400, - maxUses: 0, - temporary: false, - unique: false, - }); - - // Assertions - assertExists(invite); - - const secondInvite = await createInvite(channel.id, { - maxAge: 32400, - maxUses: 5, - temporary: true, - unique: true, - }); - - // Assertions - assertExists(secondInvite); - - assertEquals((await getChannelInvites(channel.id))?.size, 2); - }, - ...defaultTestOptions, -}); diff --git a/tests/invites/get_invite.ts b/tests/invites/get_invite.ts deleted file mode 100644 index 018b61379..000000000 --- a/tests/invites/get_invite.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { createInvite } from "../../src/helpers/invites/create_invite.ts"; -import { getInvite } from "../../src/helpers/invites/get_invite.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -Deno.test({ - name: "[invite] get invite", - async fn() { - const channel = await createChannel(tempData.guildId, { - name: "invite-channel", - }); - - // Assertions - assertExists(channel); - - // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - const invite = await createInvite(channel.id, { - maxAge: 86400, - maxUses: 0, - temporary: false, - unique: false, - }); - - // Assertions - assertExists(invite); - - const fetchedInvite = await getInvite(invite.code); - - assertExists(fetchedInvite); - - assertEquals(fetchedInvite.code, invite.code); - }, - ...defaultTestOptions, -}); diff --git a/tests/invites/get_invites.ts b/tests/invites/get_invites.ts deleted file mode 100644 index 26acefbe8..000000000 --- a/tests/invites/get_invites.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals } from "../deps.ts"; -import { getInvites } from "../../src/helpers/invites/get_invites.ts"; -import { cache } from "../../src/cache.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw") { - let invites; - - if (type === "raw") { - invites = await getInvites(tempData.guildId); - } else { - const guild = cache.guilds.get(tempData.guildId); - invites = await guild?.invites(); - } - - assertEquals((invites?.size || 0) >= 0, true); -} - -Deno.test({ - name: "[invite] get invites", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[invite] guild.invites()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); diff --git a/tests/members/search_members.ts b/tests/members/search_members.ts deleted file mode 100644 index 26cf35902..000000000 --- a/tests/members/search_members.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { searchMembers } from "../../src/helpers/members/search_members.ts"; -import { botId, cache } from "../../mod.ts"; - -async function ifItFailsBlameWolf() { - const botMember = cache.members.get(botId); - - // Assertions - assertExists(botMember); - - const foundMembers = await searchMembers(tempData.guildId, botMember!.username.substring(0, 4), { - limit: 1, - }); - - assertEquals(foundMembers.size, 1); -} - -Deno.test({ - name: "[members] search guild members", - async fn() { - await ifItFailsBlameWolf(); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/add_reaction.ts b/tests/messages/add_reaction.ts deleted file mode 100644 index f5418ce8b..000000000 --- a/tests/messages/add_reaction.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.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"; -import { Reaction } from "../../src/types/messages/reaction.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - - if (!cache.messages.has(message.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - let emojiId = "❤"; - - if (custom) { - emojiId = `<:blamewolf:${ - ( - await createEmoji(tempData.guildId, "blamewolf", "https://cdn.discordapp.com/emojis/814955268123000832.png", { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - }) - ).id - }>`; - } - - if (type === "raw") { - await addReaction(message.channelId, message.id, emojiId); - } else { - await message.addReaction(emojiId); - } - - await delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 1); - - assertEquals( - await cache.messages - .get(message.id) - ?.reactions?.filter((reaction: Reaction) => reaction.emoji?.name === (custom ? "blamewolf" : "❤")).length, - 1 - ); -} - -Deno.test({ - name: "[message] add a reaction", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.addReaction()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] add a custom reaction", - async fn() { - await ifItFailsBlameWolf("raw", true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.addReaction() with a custom reaction", - async fn() { - await ifItFailsBlameWolf("getter", true); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/add_reactions.ts b/tests/messages/add_reactions.ts deleted file mode 100644 index 884e7d932..000000000 --- a/tests/messages/add_reactions.ts +++ /dev/null @@ -1,122 +0,0 @@ -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) { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - - if (!cache.messages.has(message.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - let emojiIds = ["❤", "😃"]; - - if (custom) { - emojiIds = [ - `<:blamewolf:${ - ( - await createEmoji(tempData.guildId, "blamewolf", "https://cdn.discordapp.com/emojis/814955268123000832.png", { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - }) - ).id - }>`, - `<:blamewolf2:${ - ( - await createEmoji( - tempData.guildId, - "blamewolf2", - "https://cdn.discordapp.com/emojis/814955268123000832.png", - { - name: "blamewolf2", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - } - ) - ).id - }>`, - ]; - } - - if (type === "raw") { - await addReactions(message.channelId, message.id, emojiIds, ordered); - } else { - await message.addReactions(emojiIds, ordered); - } - - await delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 2); - - assertEquals(await cache.messages.get(message.id)?.reactions?.length, 2); -} - -Deno.test({ - name: "[message] add reactions", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.addReactions()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] add custom reactions", - async fn() { - await ifItFailsBlameWolf("raw", true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.addReactions() with custom reactions", - async fn() { - await ifItFailsBlameWolf("getter", true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] add ordered reactions", - async fn() { - await ifItFailsBlameWolf("raw", false, true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.addReactions() ordered", - async fn() { - await ifItFailsBlameWolf("getter", false, true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] add ordered custom reactions", - async fn() { - await ifItFailsBlameWolf("raw", true, true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.addReactions() with ordered custom reactions", - async fn() { - await ifItFailsBlameWolf("getter", true, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/create_message.ts b/tests/messages/create_message.ts deleted file mode 100644 index e14d240e4..000000000 --- a/tests/messages/create_message.ts +++ /dev/null @@ -1,136 +0,0 @@ -import { cache } from "../../src/cache.ts"; -import { sendMessage } from "../../src/helpers/messages/send_message.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw", content: "string" | "embed" | "reply" = "string") { - const channel = cache.channels.get(tempData.channelId); - assertExists(channel); - - // deno-lint-ignore no-explicit-any - let messageContent: any = "Hello World!"; - let secondMessageId = undefined; - if (content === "embed") { - messageContent = { - content: "Hello World!", - embed: { - title: "Hello, Embed!", - description: "This is an embedded message.", - color: 0x41ebf4, - fields: [], - }, - }; - } else if (content === "reply") { - const message = await sendMessage(channel!.id, "Test Message"); - assertExists(message); - // Wait few seconds for the channel create event to arrive and cache it - await delayUntil(10000, () => cache.messages.has(message.id)); - - secondMessageId = message.id; - - messageContent = { - content: "Hi", - allowedMentions: { - repliedUser: true, - }, - messageReference: { - messageId: message.id, - channelId: channel?.id, - guildId: tempData.guildId, - failIfNotExists: true, - }, - }; - } - - const message = type === "raw" ? await sendMessage(channel!.id, messageContent) : await channel?.send(messageContent); - - // Assertions - assertExists(message); - - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message!.id)); - - if (!cache.messages.has(message!.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - if (content === "string") { - assertEquals(cache.messages.get(message!.id)?.content, messageContent); - } else if (content === "embed") { - assertEquals(cache.messages.get(message!.id)?.embeds?.length, 1); - } else { - assertEquals(cache.messages.get(message!.id)?.messageReference?.messageId, secondMessageId); - } -} - -Deno.test({ - name: "[message] send a new message", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] channel.send()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] send a new message with an embed", - async fn() { - await ifItFailsBlameWolf("raw", "embed"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] channel.send() with an embed", - async fn() { - await ifItFailsBlameWolf("getter", "embed"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] send a message with a reply", - async fn() { - await ifItFailsBlameWolf("raw", "reply"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] channel.send() with a reply", - async fn() { - await ifItFailsBlameWolf("getter", "reply"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.reply()", - async fn() { - const channel = cache.channels.get(tempData.channelId); - assertExists(channel); - - const message = await sendMessage(channel!.id, "Test Message"); - assertExists(message); - // Wait few seconds for the channel create event to arrive and cache it - await delayUntil(10000, () => cache.messages.has(message!.id)); - - const reply = await message.reply("Welcome!"); - await delayUntil(10000, () => cache.messages.has(reply!.id)); - - if (!cache.messages.has(reply!.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - assertEquals(cache.messages.get(reply.id)?.messageReference?.messageId, message.id); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/delete_message.ts b/tests/messages/delete_message.ts deleted file mode 100644 index e01de30b7..000000000 --- a/tests/messages/delete_message.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.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!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - // Delete the message now - if (type === "raw") { - await deleteMessage(tempData.channelId, message.id, reason); - } else { - await message.delete(reason); - } - - // Wait 5 seconds to give it time for MESSAGE_DELETE event - await delayUntil(10000, () => !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."); - } -} - -Deno.test({ - name: "[message] delete a message without a reason.", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] delete a message with a reason.", - async fn() { - await ifItFailsBlameWolf("raw", "with a reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.delete() without a reason.", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.delete() with a reason.", - async fn() { - await ifItFailsBlameWolf("getter", "with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/delete_messages.ts b/tests/messages/delete_messages.ts deleted file mode 100644 index 69fc6b702..000000000 --- a/tests/messages/delete_messages.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { cache, deleteMessages, sendMessage } from "../../mod.ts"; -import { assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(reason?: string) { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - const secondMessage = await sendMessage(tempData.channelId, "Hello World 2!"); - - // Assertions - assertExists(secondMessage); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => 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."); - } - - // Delete the message now - await deleteMessages(tempData.channelId, [message.id, secondMessage.id], reason); - - // Wait 5 seconds to give it time for MESSAGE_DELETE event - await delayUntil(10000, () => !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."); - } -} - -Deno.test({ - name: "[message] delete messages without a reason.", - async fn() { - await ifItFailsBlameWolf(); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] delete messages with a reason.", - async fn() { - await ifItFailsBlameWolf("with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/edit_message.ts b/tests/messages/edit_message.ts deleted file mode 100644 index d107c2953..000000000 --- a/tests/messages/edit_message.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.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!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - // Edit the message now - if (type === "raw") { - await editMessage(message.channelId, message.id, "Goodbye World!"); - } else { - await message.edit("Goodbye World!"); - } - // Wait 5 seconds to give it time for MESSAGE_UPDATE event - await delayUntil(10000, () => 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!"); -} - -Deno.test({ - name: "[message] edit a message", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.edit()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/get_message.ts b/tests/messages/get_message.ts deleted file mode 100644 index 2faff1485..000000000 --- a/tests/messages/get_message.ts +++ /dev/null @@ -1,27 +0,0 @@ -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", - async fn() { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - // Fetch the message - const fetchedMessage = await getMessage(tempData.channelId, message.id); - // Check if getMessage has worked - assertEquals(fetchedMessage.id, message.id); - assertEquals(fetchedMessage.content, message.content); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/get_messages.ts b/tests/messages/get_messages.ts deleted file mode 100644 index 06e75d75b..000000000 --- a/tests/messages/get_messages.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { cache, getMessages, sendMessage } from "../../mod.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; - -Deno.test({ - name: "[message] fetch messages", - async fn() { - const message = await sendMessage(tempData.channelId, "Hello World!"); - const secondMessage = await sendMessage(tempData.channelId, "Hello World 2!"); - const thirdMessage = await sendMessage(tempData.channelId, "Hello World 3!"); - - // Assertions - assertExists(message); - assertExists(secondMessage); - assertExists(thirdMessage); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil( - 10000, - () => - cache.messages.has(message.id) && cache.messages.has(secondMessage.id) && cache.messages.has(thirdMessage.id) - ); - // Make sure the message was created. - if ( - !cache.messages.has(message.id) || - !cache.messages.has(secondMessage.id) || - !cache.messages.has(thirdMessage.id) - ) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - // Fetch the messages - const fetchedMessages = await getMessages(tempData.channelId, { - after: message.id, - limit: 2, - }); - // Check if getMessages has worked - assertEquals(fetchedMessages?.length, 2); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/get_reactions.ts b/tests/messages/get_reactions.ts deleted file mode 100644 index d5f24dfb5..000000000 --- a/tests/messages/get_reactions.ts +++ /dev/null @@ -1,28 +0,0 @@ -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", - async fn() { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - await addReaction(message.channelId, message.id, "❤"); - - // Fetch the message - const fetchedReactions = await getReactions(tempData.channelId, message.id, "❤"); - // Check if getMessage has worked - assertEquals(fetchedReactions.size, 1); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/pin_message.ts b/tests/messages/pin_message.ts deleted file mode 100644 index 746082122..000000000 --- a/tests/messages/pin_message.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { cache, getPins, pin, sendMessage } from "../../mod.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { DiscordenoMessage } from "../../src/structures/message.ts"; -import { delayUntil } from "../util/delay_until.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw") { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - - if (!cache.messages.has(message.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - if (type === "raw") { - await pin(message.channelId, message.id); - } else { - await message.pin(); - } - - const pins = await getPins(tempData.channelId); - assertEquals(pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, 1); -} - -Deno.test({ - name: "[message] pin a message", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.pin()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/remove_all_reactions.ts b/tests/messages/remove_all_reactions.ts deleted file mode 100644 index 1409d8d67..000000000 --- a/tests/messages/remove_all_reactions.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { addReactions, cache, 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!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - // 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 delayUntil(10000, () => 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); - - if (type === "raw") { - await removeAllReactions(message.channelId, message.id); - } else { - await message.removeAllReactions(); - } - - // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delayUntil(10000, () => cache.messages.get(message.id)?.reactions === undefined); - - // Check if the reactions has been deleted - assertEquals(await cache.messages.get(message.id)?.reactions, undefined); -} - -Deno.test({ - name: "[message] remove all reactions", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.removeAllReactions()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/remove_reaction.ts b/tests/messages/remove_reaction.ts deleted file mode 100644 index 109e0a63b..000000000 --- a/tests/messages/remove_reaction.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { addReaction, cache, removeReaction, sendMessage } from "../../mod.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw", user = false) { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - // 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 delayUntil(10000, () => 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); - - if (type === "raw") { - await removeReaction(message.channelId, message.id, "❤", user ? { userId: message.authorId } : undefined); - } else { - await message.removeReaction("❤", user ? message.authorId : undefined); - } - - // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delayUntil(10000, () => cache.messages.get(message.id)?.reactions === undefined); - - // Check if the reactions has been deleted - assertEquals(await cache.messages.get(message.id)?.reactions, undefined); -} - -Deno.test({ - name: "[message] remove a reaction", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.removeReaction()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] remove a user reaction", - async fn() { - await ifItFailsBlameWolf("raw", true); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.removeReaction with user", - async fn() { - await ifItFailsBlameWolf("getter", true); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/remove_reaction_emoji.ts b/tests/messages/remove_reaction_emoji.ts deleted file mode 100644 index b38d2d211..000000000 --- a/tests/messages/remove_reaction_emoji.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { addReaction, cache, 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!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // 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."); - } - - // 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 delayUntil(10000, () => 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); - - if (type === "raw") { - await removeReactionEmoji(message.channelId, message.id, "❤"); - } else { - await message.removeReactionEmoji("❤"); - } - - // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delayUntil(10000, () => cache.messages.get(message.id)?.reactions === undefined); - - // Check if the reactions has been deleted - assertEquals(cache.messages.get(message.id)?.reactions, undefined); -} - -Deno.test({ - name: "[message] remove a reaction emoji", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[message] message.removeReactionEmoji()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); diff --git a/tests/messages/unpin_message.ts b/tests/messages/unpin_message.ts deleted file mode 100644 index b952728b4..000000000 --- a/tests/messages/unpin_message.ts +++ /dev/null @@ -1,52 +0,0 @@ -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!"); - - // Assertions - assertExists(message); - - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - - if (!cache.messages.has(message.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - await pin(message.channelId, message.id); - - // Be sure that the pin got added - const pins = await getPins(tempData.channelId); - assertEquals(pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, 1); - - if (type === "raw") { - await unpin(message.channelId, message.id); - } else { - //await message.unpin(); - } - - // Be sure that the pin got removed - const removedPins = await getPins(tempData.channelId); - assertEquals(removedPins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, 0); -} - -Deno.test({ - name: "[message] unpin a message", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -/* -Deno.test({ - name: "[message] message.unpin()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -});*/ diff --git a/tests/roles/add_role.ts b/tests/roles/add_role.ts deleted file mode 100644 index f2d9f715b..000000000 --- a/tests/roles/add_role.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { addRole } from "../../src/helpers/roles/add_role.ts"; -import { createRole } from "../../src/helpers/roles/create_role.ts"; -import { botId } from "../../src/bot.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { - const role = await createRole(tempData.guildId, { - name: "hoti", - }); - - assertExists(role); - - // Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id)); - - if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) { - throw new Error(`The role seemed to be created but it was not cached.`); - } - - if (type === "raw") { - await addRole(tempData.guildId, botId, role.id, reason); - } else { - await cache.members.get(botId)!.addRole(tempData.guildId, role.id, reason); - } - - // Delay the execution by 5 seconds to allow GUILD_MEMBER_UPDATE event to be processed - await delayUntil(10000, () => cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id)); - - assertEquals(cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id), true); -} - -Deno.test({ - name: "[role] add a role without a reason", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] add a role with a reason", - async fn() { - await ifItFailsBlameWolf("raw", "with a reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] member.addRole() without a reason", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] member.addRole() with a reason", - async fn() { - await ifItFailsBlameWolf("getter", "with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/roles/create_role.ts b/tests/roles/create_role.ts deleted file mode 100644 index 1308d00d7..000000000 --- a/tests/roles/create_role.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { createRole } from "../../src/helpers/roles/create_role.ts"; - -async function ifItFailsBlameWolf(reason?: string) { - const role = await createRole( - tempData.guildId, - { - name: "hoti", - }, - reason - ); - - assertExists(role); - - // Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id)); - - if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) { - throw new Error(`The role seemed to be created but it was not cached.`); - } -} - -Deno.test({ - name: "[role] create a role without a reason", - async fn() { - await ifItFailsBlameWolf(); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] create a role with a reason", - async fn() { - await ifItFailsBlameWolf("with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/roles/delete_role.ts b/tests/roles/delete_role.ts deleted file mode 100644 index 8de77fbfe..000000000 --- a/tests/roles/delete_role.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { createRole } from "../../src/helpers/roles/create_role.ts"; -import { deleteRole } from "../../src/helpers/roles/delete_role.ts"; - -async function ifItFailsBlameWolf(reason?: string) { - const role = await createRole( - tempData.guildId, - { - name: "hoti", - }, - reason - ); - - assertExists(role); - - // Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id)); - - if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) { - throw new Error(`The role seemed to be created but it was not cached.`); - } - - await deleteRole(tempData.guildId, role.id); - - // Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed - await delayUntil(10000, () => !cache.guilds.get(tempData.guildId)?.roles.has(role.id)); - - if (cache.guilds.get(tempData.guildId)?.roles.has(role.id)) { - throw new Error(`The role should have been deleted but it is still in cache.`); - } -} - -Deno.test({ - name: "[role] delete a role without a reason", - async fn() { - await ifItFailsBlameWolf(); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] delete a role with a reason", - async fn() { - await ifItFailsBlameWolf("with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/roles/edit_role.ts b/tests/roles/edit_role.ts deleted file mode 100644 index 20b4461ab..000000000 --- a/tests/roles/edit_role.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { createRole } from "../../src/helpers/roles/create_role.ts"; -import { editRole } from "../../src/helpers/roles/edit_role.ts"; - -Deno.test({ - name: "[role] edit a role", - async fn() { - const role = await createRole(tempData.guildId, { - name: "hoti", - }); - - assertExists(role); - - // Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id)); - - if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) { - throw new Error(`The role seemed to be created but it was not cached.`); - } - - await editRole(tempData.guildId, role.id, { - name: "#rememberAyntee", - }); - - // Delay the execution by 5 seconds to allow GUILD_ROLE_UPDATE event to be processed - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.get(role.id)?.name === "#rememberAyntee"); - - assertEquals(cache.guilds.get(tempData.guildId)?.roles.get(role.id)?.name === "#rememberAyntee", true); - }, - ...defaultTestOptions, -}); diff --git a/tests/roles/get_roles.ts b/tests/roles/get_roles.ts deleted file mode 100644 index f19e53866..000000000 --- a/tests/roles/get_roles.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { botId } from "../../src/bot.ts"; -import { getRoles } from "../../src/helpers/roles/get_roles.ts"; - -Deno.test({ - name: "[role] get roles", - async fn() { - cache.guilds.get(tempData.guildId)?.roles.clear(); - - await getRoles(tempData.guildId); - - await delayUntil(10000, () => cache.members.get(botId)?.guilds.get(tempData.guildId).roles.length > 0); - - assertEquals(cache.members.get(botId)?.guilds.get(tempData.guildId).roles.length > 0, true); - }, - ...defaultTestOptions, -}); diff --git a/tests/roles/remove_role.ts b/tests/roles/remove_role.ts deleted file mode 100644 index 37e969867..000000000 --- a/tests/roles/remove_role.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { addRole } from "../../src/helpers/roles/add_role.ts"; -import { createRole } from "../../src/helpers/roles/create_role.ts"; -import { botId } from "../../src/bot.ts"; -import { removeRole } from "../../src/helpers/roles/remove_role.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { - const role = await createRole(tempData.guildId, { - name: "hoti", - }); - - assertExists(role); - - // Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed - await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id)); - - if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) { - throw new Error(`The role seemed to be created but it was not cached.`); - } - - if (type === "raw") { - await addRole(tempData.guildId, botId, role.id, reason); - } else { - await cache.members.get(botId)!.addRole(tempData.guildId, role.id, reason); - } - - // Delay the execution by 5 seconds to allow GUILD_MEMBER_UPDATE event to be processed - await delayUntil(10000, () => cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id)); - - if (type === "raw") { - await removeRole(tempData.guildId, botId, role.id, reason); - } else { - await cache.members.get(botId)!.removeRole(tempData.guildId, role.id, reason); - } - - // Delay the execution by 5 seconds to allow GUILD_MEMBER_UPDATE event to be processed - await delayUntil(10000, () => !cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id)); - - assertEquals(cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id), false); -} - -Deno.test({ - name: "[role] remove a role without a reason", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] remove a role with a reason", - async fn() { - await ifItFailsBlameWolf("raw", "with a reason"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] member.removeRole() without a reason", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -}); - -Deno.test({ - name: "[role] member.removeRole() with a reason", - async fn() { - await ifItFailsBlameWolf("getter", "with a reason"); - }, - ...defaultTestOptions, -}); diff --git a/tests/util/delay_until.ts b/tests/util/delay_until.ts deleted file mode 100644 index 51f69732d..000000000 --- a/tests/util/delay_until.ts +++ /dev/null @@ -1,14 +0,0 @@ -// deno-lint-ignore require-await -export async function delayUntil(maxMs: number, isReady: () => boolean | undefined, timeoutTime = 100): Promise { - const maxTime = Date.now() + maxMs; - - function hackyFix(resolve: () => void) { - if (isReady() || Date.now() >= maxTime) { - resolve(); - } else { - setTimeout(() => hackyFix(resolve), timeoutTime); - } - } - - return new Promise((resolve) => hackyFix(resolve)); -} diff --git a/tests/util/utils.ts b/tests/util/utils.ts deleted file mode 100644 index 7d65308c4..000000000 --- a/tests/util/utils.ts +++ /dev/null @@ -1,274 +0,0 @@ -import { ApplicationCommandOption } from "../../src/types/interactions/commands/application_command_option.ts"; -import { ApplicationCommandOptionChoice } from "../../src/types/interactions/commands/application_command_option_choice.ts"; -import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/commands/application_command_option_types.ts"; -import { validateSlashCommands } from "../../src/util/utils.ts"; -import { assertThrows } from "../deps.ts"; - -Deno.test({ - name: "[utils] validateSlashCommands(): application command name", - fn() { - assertThrows(() => - validateSlashCommands([ - { - // The maximum length of the name of an application command is 32. - name: "a".repeat(33), - }, - ]) - ); - - validateSlashCommands([ - { - name: "workingname", - }, - ]); - }, -}); - -Deno.test({ - name: "[utils] validateSlashCommands(): application command description", - fn() { - assertThrows(() => - // The maximum length of the description of an application command is 100. - validateSlashCommands([{ description: "a".repeat(101) }]) - ); - - validateSlashCommands([ - { - description: "valid description (should not throw)", - }, - ]); - }, -}); - -Deno.test({ - name: "[utils] validateSlashCommands(): number of options", - fn() { - const option = { - name: "optionname", - description: "The description of the option.", - type: DiscordApplicationCommandOptionTypes.String, - }; - // The maximum number of options an application command can "accomodate" is 25. - const options: ApplicationCommandOption[] = Array(26).fill(option); - - assertThrows(() => validateSlashCommands([{ options }])); - - validateSlashCommands([ - { - options: [option], - }, - ]); - }, -}); - -Deno.test({ - name: "[utils] validateSlashCommands(): number of option choices", - fn() { - const choice: ApplicationCommandOptionChoice = { - name: "choicename", - value: "choicevalue", - }; - // The maximum number of application command option choices is 25. - const choices = Array(26).fill(choice); - - assertThrows(() => - validateSlashCommands([ - { - options: [ - { - name: "optionname", - type: DiscordApplicationCommandOptionTypes.String, - description: "The description of the option.", - choices, - }, - ], - }, - ]) - ); - - validateSlashCommands([ - { - options: [ - { - name: "optionname", - type: DiscordApplicationCommandOptionTypes.String, - description: "The description of the option.", - choices: [choice], - }, - ], - }, - ]); - }, -}); - -Deno.test({ - name: "[utils] validateSlashCommands(): option name", - fn() { - assertThrows(() => - validateSlashCommands([ - { - options: [ - { - // The maximum length of application command option name is 32. - name: "a".repeat(33), - description: "The description of the option.", - type: DiscordApplicationCommandOptionTypes.String, - }, - ], - }, - ]) - ); - - validateSlashCommands([ - { - options: [ - { - name: "optionname", - description: "The description of the option.", - type: DiscordApplicationCommandOptionTypes.String, - }, - ], - }, - ]); - }, -}); - -Deno.test({ - name: "[utils] validateSlashCommands(): option description", - fn() { - assertThrows(() => - validateSlashCommands([ - { - options: [ - { - name: "optionname", - // The maximum length of application command option description is 100. - description: "a".repeat(101), - type: DiscordApplicationCommandOptionTypes.String, - }, - ], - }, - ]) - ); - - validateSlashCommands([ - { - options: [ - { - name: "optionname", - description: "The description of the option.", - type: DiscordApplicationCommandOptionTypes.String, - }, - ], - }, - ]); - }, -}); - -Deno.test({ - name: "[utils] validateSlashCommands(): the option choice name", - fn() { - assertThrows(() => - validateSlashCommands([ - { - options: [ - { - name: "optionname", - choices: [ - { - // The maximum length of an option choice name is 100. - name: "a".repeat(101), - value: "choicevalue", - }, - ], - description: "The description of the option.", - type: DiscordApplicationCommandOptionTypes.String, - }, - ], - }, - ]) - ); - - validateSlashCommands([ - { - options: [ - { - name: "optionname", - description: "The description of the option.", - type: DiscordApplicationCommandOptionTypes.String, - choices: [ - { - name: "choicename", - value: "choicevalue", - }, - ], - }, - ], - }, - ]); - }, -}); - -Deno.test({ - name: "[utils] validateSlashCommands(): option choice value", - fn() { - assertThrows(() => - validateSlashCommands([ - { - options: [ - { - type: DiscordApplicationCommandOptionTypes.String, - description: "The description of the option.", - name: "optionname", - choices: [ - { - name: "choicename", - value: 123, - }, - ], - }, - ], - }, - ]) - ); - - assertThrows(() => { - validateSlashCommands([ - { - options: [ - { - description: "The description of the option.", - name: "optionname", - type: DiscordApplicationCommandOptionTypes.String, - choices: [ - { - name: "choicename", - // The maximum length of an option choice value is 100. - value: "a".repeat(101), - }, - ], - }, - ], - }, - ]); - }); - - validateSlashCommands([ - { - options: [ - { - type: DiscordApplicationCommandOptionTypes.String, - description: "The description of the option.", - name: "optionname", - choices: [ - { - name: "choicename", - value: "choicevalue", - }, - ], - }, - ], - }, - ]); - }, -}); diff --git a/tests/util/validate_length.ts b/tests/util/validate_length.ts deleted file mode 100644 index aab8eeb19..000000000 --- a/tests/util/validate_length.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { validateLength } from "../../src/util/validate_length.ts"; -import { assertEquals } from "../deps.ts"; - -Deno.test({ - name: "[utils] Validate length is too low", - fn() { - assertEquals(validateLength("test", { min: 5 }), false); - }, -}); - -Deno.test({ - name: "[utils] Validate length is too high", - fn() { - assertEquals(validateLength("test", { max: 3 }), false); - }, -}); - -Deno.test({ - name: "[utils] Validate length is NOT just right in between.", - fn() { - assertEquals(validateLength("test", { min: 5, max: 3 }), false); - }, -}); - -Deno.test({ - name: "[utils] Validate length is NOT too low", - fn() { - assertEquals(validateLength("test", { min: 3 }), true); - }, -}); - -Deno.test({ - name: "[utils] Validate length is NOT too high", - fn() { - assertEquals(validateLength("test", { max: 5 }), true); - }, -}); - -Deno.test({ - name: "[utils] Validate length is just right in between.", - fn() { - assertEquals(validateLength("test", { min: 3, max: 6 }), true); - }, -}); diff --git a/tests/ws/start_bot.ts b/tests/ws/start_bot.ts deleted file mode 100644 index 149cadc4c..000000000 --- a/tests/ws/start_bot.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { botId, startBot } from "../../src/bot.ts"; -import { cache } from "../../src/cache.ts"; -import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts"; -import { delay } from "../../src/util/utils.ts"; -import { ws } from "../../src/ws/ws.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; - -// Set necessary settings -// Disables the logger which logs everything -ws.log = function (_x: string, _d: unknown) { - // if (["RAW", "GUILD_CREATE", "HEARTBEATING_DETAILS"].includes(_x)) - // return console.log(_x); - // console.log(_x, _d); -}; - -// Default options for tests -export const defaultTestOptions: Partial = { - sanitizeOps: false, - sanitizeResources: false, -}; - -// Temporary data -export const tempData = { - guildId: 0n, - roleId: 0n, - channelId: 0n, - messageId: 0n, -}; - -Deno.test({ - name: "[ws] connect to gateway", - async fn() { - const token = Deno.env.get("DISCORD_TOKEN"); - if (!token) throw new Error("Token is not provided"); - - await startBot({ - token, - eventHandlers: {}, - intents: ["GuildMessages", "Guilds", "GuildEmojis", "GuildMessageReactions"], - }); - - // Delay the execution by 5 seconds - await delay(3000); - - await delayUntil(10000, () => cache.isReady); - - // DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE - if (cache.guilds.size <= 10) { - for (const guild of cache.guilds.values()) await deleteGuild(guild.id); - } - - // Assertions - assertExists(botId); - assertEquals(true, cache.isReady); - }, - ...defaultTestOptions, -}); diff --git a/tests/ws/ws_close.ts b/tests/ws/ws_close.ts deleted file mode 100644 index fdc7d2493..000000000 --- a/tests/ws/ws_close.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { delay } from "../../src/util/utils.ts"; -import { ws } from "../../src/ws/ws.ts"; -import { defaultTestOptions } from "./start_bot.ts"; - -// Exit the Deno process once all tests are done. -Deno.test({ - name: "[ws] Close all shards manually.", - async fn() { - ws.shards.forEach((shard) => { - clearInterval(shard.heartbeat.intervalId); - ws.closeWS(shard.ws, 3061, "Discordeno Testing Finished! Do Not RESUME!"); - }); - - await delay(3000); - }, - ...defaultTestOptions, -});