From 35920b56cf36650627d322577c2fad61ef912644 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 31 May 2022 13:15:52 +0000 Subject: [PATCH] fix(tests): remaining channel unit tests --- tests/mod.ts | 25 ---------- testss/channels/editChannelWithReason.test.ts | 50 +++++++++++++++++++ .../deleteChannelOverwrite.test.ts | 36 +++++++++++++ 3 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 testss/channels/editChannelWithReason.test.ts create mode 100644 testss/channels/permissions/deleteChannelOverwrite.test.ts diff --git a/tests/mod.ts b/tests/mod.ts index 716c03a82..d114b9631 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -1,28 +1,3 @@ -import { deleteChannelOverwriteTests } from "./helpers/channels/deleteChannelOverwrite.ts"; -import { editChannelTests } from "./helpers/channels/editChannel.ts"; - -Deno.test({ - name: "[channel] delete a channel overwrite", - async fn(t) { - await deleteChannelOverwriteTests(guild.id); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] edit a channel w/o a reason", - async fn(t) { - await editChannelTests(guild.id, {}); - }, - ...sanitizeMode, -}); -Deno.test({ - name: "[channel] edit a channel w/ a reason", - async fn(t) { - await editChannelTests(guild.id, { reason: "Blame wolf" }); - }, - ...sanitizeMode, -}); - // import "./channels/connectToVoice.ts"; // import "./misc/editBotStatus.ts"; diff --git a/testss/channels/editChannelWithReason.test.ts b/testss/channels/editChannelWithReason.test.ts new file mode 100644 index 000000000..912bb0162 --- /dev/null +++ b/testss/channels/editChannelWithReason.test.ts @@ -0,0 +1,50 @@ +import { ChannelTypes } from "../../mod.ts"; +import { assertEquals } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; + +Deno.test({ + name: "[channel] edit a channel", + async fn(t) { + const bot = loadBot(); + const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "editChannel" }); + + // Edit a channel name without a reason + await t.step("[channel] edit a channel name without a reason", async () => { + const editedChannel = await bot.helpers.editChannel(channel.id, { name: "editedchannel" }); + assertEquals(editedChannel.name, "editedchannel"); + }); + + // Edit a channel topic + await t.step("[channel] edit a channel topic with a reason", async () => { + const editedChannel = await bot.helpers.editChannel(channel.id, { topic: "editedChannel" }); + assertEquals(editedChannel.topic, "editedChannel"); + }); + + // Change the channel to a news channel + await t.step("[channel] change the channel to a news channel with a reason", async () => { + const editedChannel = await bot.helpers.editChannel(channel.id, { type: ChannelTypes.GuildNews }, "reason"); + assertEquals(editedChannel.type, ChannelTypes.GuildNews); + }); + + // Change from a news channel to a text channel + await t.step("[channel] change from a news channel to a text channel", async () => { + const editedChannel = await bot.helpers.editChannel(channel.id, { type: ChannelTypes.GuildText }); + assertEquals(editedChannel.type, ChannelTypes.GuildText); + }); + + // Enable nsfw + await t.step("[channel] enable nsfw", async () => { + const editedChannel = await bot.helpers.editChannel(channel.id, { nsfw: true }); + assertEquals(editedChannel.nsfw, true); + }); + + // Disable nsfw + await t.step("[channel] disable nsfw", async () => { + const editedChannel = await bot.helpers.editChannel(channel.id, { nsfw: false }); + assertEquals(editedChannel.nsfw, false); + }); + + await bot.helpers.deleteChannel(channel.id); + }, +}); diff --git a/testss/channels/permissions/deleteChannelOverwrite.test.ts b/testss/channels/permissions/deleteChannelOverwrite.test.ts new file mode 100644 index 000000000..b57a2f99a --- /dev/null +++ b/testss/channels/permissions/deleteChannelOverwrite.test.ts @@ -0,0 +1,36 @@ +import { ChannelTypes, OverwriteTypes } from "../../../types/shared.ts"; +import { assertEquals, assertExists } from "../../deps.ts"; +import { loadBot } from "../../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; + +Deno.test({ + name: "[channel] Delete a channel overwrite", + async fn(t) { + const bot = loadBot(); + const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { + name: "deleteChannelOverwrite", + permissionOverwrites: [ + { + id: bot.id, + type: OverwriteTypes.Member, + allow: ["VIEW_CHANNEL"], + deny: [], + }, + ], + }); + + // Assertions + assertExists(channel); + assertEquals(channel.type, ChannelTypes.GuildText); + assertEquals(channel.permissionOverwrites.length, 1); + + await bot.helpers.deleteChannelOverwrite(channel.id, bot.id); + + // Fetch the channel again to validate + const fetchedChannel = await bot.helpers.getChannel(channel.id); + assertExists(fetchedChannel?.id); + assertEquals(fetchedChannel.permissionOverwrites.length, 0); + + await bot.helpers.deleteChannel(channel.id); + }, +});