From 7da023690b7b13fe546051621bf59a0af0ed87ca Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 8 May 2022 16:52:02 +0000 Subject: [PATCH] fix: cleanup tests and add get channel test --- tests/channels/createChannel.ts | 148 -------------------------------- tests/channels/deleteChannel.ts | 40 --------- testss/channels.test.ts | 15 ++++ 3 files changed, 15 insertions(+), 188 deletions(-) delete mode 100644 tests/channels/createChannel.ts delete mode 100644 tests/channels/deleteChannel.ts diff --git a/tests/channels/createChannel.ts b/tests/channels/createChannel.ts deleted file mode 100644 index dee06f225..000000000 --- a/tests/channels/createChannel.ts +++ /dev/null @@ -1,148 +0,0 @@ -import { ChannelTypes, CreateGuildChannel, OverwriteTypes } from "../../mod.ts"; -import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -async function createChannelTests(guildId: bigint, options: CreateGuildChannel, autoDelete: boolean) { - const channel = await bot.helpers.createChannel(guildId, options); - - // Assertions - assertExists(channel); - assertEquals(channel.type, options.type || ChannelTypes.GuildText); - - // Delay the execution to allow event to be processed - await delayUntil(10000, () => bot.channels.has(channel.id)); - - if (!bot.channels.has(channel.id)) { - throw new Error("The channel seemed to be created but it was not cached."); - } - - if (options.topic && channel.topic !== options.topic) { - throw new Error("The channel was supposed to have a topic but it does not appear to be the same topic."); - } - - if (options.bitrate && channel.bitrate !== options.bitrate) { - throw new Error("The channel was supposed to have a bitrate but it does not appear to be the same bitrate."); - } - - if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) { - throw new Error( - "The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites.", - ); - } - - if (autoDelete) { - await bot.helpers.deleteChannel(channel.id); - } -} - -Deno.test({ - name: "[channel] create a new text channel", - async fn(t) { - await createChannelTests(guild.id, { name: "Discordeno-test" }, false); - }, -}); -Deno.test({ - name: "[channel] create a new category channel", - async fn(t) { - await createChannelTests( - guild.id, - { - name: "Discordeno-test", - type: ChannelTypes.GuildCategory, - }, - false, - ); - }, -}); -Deno.test({ - name: "[channel] create a new news channel", - async fn(t) { - await createChannelTests( - CACHED_COMMUNITY_GUILD_ID, - { name: "Discordeno-test", type: ChannelTypes.GuildNews }, - true, - ); - }, -}); -Deno.test({ - name: "[channel] create a new voice channel", - async fn(t) { - await createChannelTests( - guild.id, - { - name: "Discordeno-test", - type: ChannelTypes.GuildVoice, - }, - false, - ); - }, -}); -Deno.test({ - name: "[channel] create a new voice channel with a bitrate", - async fn(t) { - await createChannelTests( - guild.id, - { - name: "discordeno-test", - type: ChannelTypes.GuildVoice, - bitrate: 32000, - }, - false, - ); - }, -}); -Deno.test({ - name: "[channel] create a new voice channel with a user limit", - async fn(t) { - await createChannelTests( - guild.id, - { - name: "Discordeno-test", - type: ChannelTypes.GuildVoice, - userLimit: 32, - }, - false, - ); - }, -}); -Deno.test({ - name: "[channel] create a new text channel with a rate limit per user", - async fn(t) { - await createChannelTests( - guild.id, - { - name: "Discordeno-test", - rateLimitPerUser: 2423, - }, - false, - ); - }, -}); -Deno.test({ - name: "[channel] create a new text channel with NSFW", - async fn(t) { - await createChannelTests(guild.id, { name: "Discordeno-test", nsfw: true }, false); - }, -}); -Deno.test({ - name: "[channel] create a new text channel with permission overwrites", - async fn(t) { - await createChannelTests( - guild.id, - { - name: "Discordeno-test", - permissionOverwrites: [ - { - id: bot.id, - type: OverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - false, - ); - }, -}); diff --git a/tests/channels/deleteChannel.ts b/tests/channels/deleteChannel.ts deleted file mode 100644 index a297aa358..000000000 --- a/tests/channels/deleteChannel.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -async function deleteChannelTests(guildId: bigint, options: { reason?: string }) { - // Create the necessary channels - const channel = await bot.helpers.createChannel(guildId, { - name: "delete-channel", - }); - - await delayUntil(10000, () => bot.channels.has(channel.id)); - // Make sure the channel was created. - if (!bot.channels.has(channel.id)) { - throw new Error("The channel should have been created but it is not in the cache."); - } - - // Delete the channel now without a reason - await bot.helpers.deleteChannel(channel.id, options.reason); - // wait to give it time for event - await delayUntil(10000, () => !bot.channels.has(channel.id)); - - // Make sure it is gone from cache - if (bot.channels.has(channel.id)) { - throw new Error("The channel should have been deleted but it is still in cache."); - } -} - -Deno.test({ - name: "[channel] delete a channel with a reason", - async fn(t) { - await deleteChannelTests(guild.id, { - reason: "with a reason", - }); - }, -}); -Deno.test({ - name: "[channel] delete a channel without a reason", - async fn(t) { - await deleteChannelTests(guild.id, {}); - }, -}); diff --git a/testss/channels.test.ts b/testss/channels.test.ts index 973d3955d..854b8e737 100644 --- a/testss/channels.test.ts +++ b/testss/channels.test.ts @@ -3,6 +3,21 @@ import { assertEquals, assertExists } from "./deps.ts"; import { loadBot } from "./mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "./utils.ts"; +Deno.test({ + name: "[channel] Get a channel", + async fn(t) { + const bot = loadBot(); + const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { + name: "fetching", + }); + + const fetched = await bot.helpers.getChannel(channel.id); + assertExists(fetched); + assertEquals(channel.id, fetched.id); + assertEquals(channel.name, fetched.name); + }, +}); + Deno.test({ name: "[channel] delete a channel without a reason", async fn(t) {