From 06a893af082db9a6cd63e2845a6c3717f3d1c7e8 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 31 Oct 2021 19:29:24 +0000 Subject: [PATCH] delete channel tests Closes #1192 --- tests/helpers/channels/deleteChannel.ts | 24 +++++++++++++++++++ tests/mod.ts | 31 ++++++++++++++++++------- 2 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 tests/helpers/channels/deleteChannel.ts diff --git a/tests/helpers/channels/deleteChannel.ts b/tests/helpers/channels/deleteChannel.ts new file mode 100644 index 000000000..537754e4c --- /dev/null +++ b/tests/helpers/channels/deleteChannel.ts @@ -0,0 +1,24 @@ +import { Bot } from "../../../src/bot.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function deleteChannelTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) { + // Create the necessary channels + const channel = await bot.helpers.createChannel(guildId, { + name: "delete-channel", + }); + + await delayUntil(10000, () => bot.cache.channels.has(channel.id)); + // Make sure the channel was created. + if (!bot.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 bot.helpers.deleteChannel(channel.id, options.reason); + // wait 5 seconds to give it time for CHANNEL_DELETE event + await delayUntil(10000, () => !bot.cache.channels.has(channel.id)); + // Make sure it is gone from cache + if (bot.cache.channels.has(channel.id)) { + throw new Error("The channel should have been deleted but it is still in cache."); + } +} diff --git a/tests/mod.ts b/tests/mod.ts index 101a976a2..3c15b9e5b 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -27,6 +27,7 @@ import { fetchSingleMemberTest } from "./helpers/members/fetchMembers.ts"; import { pinMessageTests } from "./helpers/messages/pin.ts"; import { removeAllReactionTests, removeReactionEmojiTest, removeReactionTest } from "./helpers/messages/reactions.ts"; import { createChannelTests } from "./helpers/channels/createChannel.ts"; +import { deleteChannelTests } from "./helpers/channels/deleteChannel.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS @@ -255,7 +256,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ name: "[channel] create a new text channel", async fn() { @@ -263,7 +263,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ name: "[channel] create a new category channel", async fn() { @@ -279,7 +278,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - // t.step({ // name: "[channel] create a new news channel", // async fn() { @@ -295,7 +293,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { // }, // ...sanitizeMode, // }), - t.step({ name: "[channel] create a new voice channel", async fn() { @@ -311,7 +308,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ name: "[channel] create a new voice channel with a bitrate", async fn() { @@ -328,7 +324,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ name: "[channel] create a new voice channel with a user limit", async fn() { @@ -345,7 +340,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ name: "[channel] create a new text channel with a rate limit per user", async fn() { @@ -361,7 +355,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ name: "[channel] create a new text channel with NSFW", async fn() { @@ -369,7 +362,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ name: "[channel] create a new text channel with permission overwrites", async fn() { @@ -392,6 +384,27 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), + t.step({ + name: "[channel] delete a channel with a reason", + async fn() { + await deleteChannelTests( + bot, + guild.id, + { + reason: "with a reason", + }, + t + ); + }, + ...sanitizeMode, + }), + t.step({ + name: "[channel] delete a channel without a reason", + async fn() { + await deleteChannelTests(bot, guild.id, {}, t); + }, + ...sanitizeMode, + }), ]); });