From a44f9687453c27fe6f4cf8730dee8c0395dc9e2b Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Fri, 9 Apr 2021 17:20:41 +0000 Subject: [PATCH 1/4] tests: add deleteChannel tests --- src/helpers/channels/create_channel.ts | 2 - tests/channels/create_channel.ts | 26 ++++++++++++ tests/channels/delete_channel.ts | 58 ++++++++++++++++++++++++++ tests/mod.ts | 6 +++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 tests/channels/create_channel.ts create mode 100644 tests/channels/delete_channel.ts diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index 57ebc3106..39d09b60f 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -14,7 +14,6 @@ import { /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function createChannel( guildId: string, - name: string, options?: CreateGuildChannel, ) { const requiredPerms: Set = new Set(["MANAGE_CHANNELS"]); @@ -31,7 +30,6 @@ export async function createChannel( endpoints.GUILD_CHANNELS(guildId), { ...options, - name, permission_overwrites: options?.permissionOverwrites?.map((perm) => ({ ...perm, diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts new file mode 100644 index 000000000..cb4fafcfb --- /dev/null +++ b/tests/channels/create_channel.ts @@ -0,0 +1,26 @@ +import { cache, createChannel, delay } from "../../mod.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; +import { assertEquals, assertExists } from "../deps.ts"; + +Deno.test({ + name: "[channel] create a new channel", + async fn() { + const channel = await createChannel(tempData.guildId, { + name: "Discordeno-test", + }); + + // Assertions + assertExists(channel); + + tempData.channelId = channel.id; + assertEquals(tempData.channelId, channel.id); + + // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed + await delay(5000); + + if (!cache.channels.has(channel.id)) { + throw new Error("The channel seemed to be created but it was not cached."); + } + }, + ...defaultTestOptions, +}); diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts new file mode 100644 index 000000000..3afbe5c4c --- /dev/null +++ b/tests/channels/delete_channel.ts @@ -0,0 +1,58 @@ +import { cache, createChannel, delay, deleteChannel } from "../../mod.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 delay(5000); + // 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(tempData.guildId, channel.id); + // wait 5 seconds to give it time for CHANNEL_DELETE event + await delay(5000); + // 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 delay(5000); + // 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(tempData.guildId, channel.id, "with a reason"); + // wait 5 seconds to give it time for CHANNEL_DELETE event + await delay(5000); + // 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, + }); \ No newline at end of file diff --git a/tests/mod.ts b/tests/mod.ts index ef2fafdd2..229a86911 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -10,5 +10,11 @@ import "./util/utils.ts"; // First initate the connection import "./ws/start_bot.ts"; import "./guilds/create_guild.ts"; + +// Channel tests +import "./channels/create_channel.ts"; +import "./channels/delete_channel.ts"; + +// Final cleanup import "./guilds/delete_server.ts"; import "./ws/ws_close.ts"; From c590c340b0f1f30a66ef11202ea5c4c689848d5e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 9 Apr 2021 19:30:59 +0200 Subject: [PATCH 2/4] Update tests/channels/delete_channel.ts --- tests/channels/delete_channel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts index 3afbe5c4c..8d91d13f5 100644 --- a/tests/channels/delete_channel.ts +++ b/tests/channels/delete_channel.ts @@ -55,4 +55,4 @@ Deno.test({ ); }, ...defaultTestOptions, - }); \ No newline at end of file + }); From 8b5e39f7960072bafb7e102af12c715c62fd71fa Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Fri, 9 Apr 2021 17:35:34 +0000 Subject: [PATCH 3/4] deno fmt --- tests/channels/create_channel.ts | 4 +- tests/channels/delete_channel.ts | 64 +++++++++++++++++--------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index cb4fafcfb..2e6e5012c 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -19,7 +19,9 @@ Deno.test({ await delay(5000); if (!cache.channels.has(channel.id)) { - throw new Error("The channel seemed to be created but it was not cached."); + throw new Error( + "The channel seemed to be created but it was not cached.", + ); } }, ...defaultTestOptions, diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts index 3afbe5c4c..401b91170 100644 --- a/tests/channels/delete_channel.ts +++ b/tests/channels/delete_channel.ts @@ -11,48 +11,52 @@ Deno.test({ // wait 5 seconds to give it time for CHANNEL_CREATE event await delay(5000); // Make sure the channel was created. - if (!cache.channels.has(channel.id)) + if (!cache.channels.has(channel.id)) { throw new Error( - "The channel should have been created but it is not in the cache." + "The channel should have been created but it is not in the cache.", ); + } // Delete the channel now without a reason await deleteChannel(tempData.guildId, channel.id); // wait 5 seconds to give it time for CHANNEL_DELETE event await delay(5000); // Make sure it is gone from cache - if (cache.channels.has(channel.id)) + if (cache.channels.has(channel.id)) { throw new Error( - "The channel should have been deleted but it is still in cache." + "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 delay(5000); - // 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(tempData.guildId, channel.id, "with a reason"); - // wait 5 seconds to give it time for CHANNEL_DELETE event - await delay(5000); - // 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, - }); \ No newline at end of file + 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 delay(5000); + // 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(tempData.guildId, channel.id, "with a reason"); + // wait 5 seconds to give it time for CHANNEL_DELETE event + await delay(5000); + // 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, +}); From 00a0d04b14e77be9f678e88206580e6024303409 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Fri, 9 Apr 2021 17:42:29 +0000 Subject: [PATCH 4/4] remove assert equals --- tests/channels/create_channel.ts | 3 +-- tests/guilds/create_guild.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index 2e6e5012c..7a0e8fdd0 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -1,6 +1,6 @@ import { cache, createChannel, delay } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; +import { assertExists } from "../deps.ts"; Deno.test({ name: "[channel] create a new channel", @@ -13,7 +13,6 @@ Deno.test({ assertExists(channel); tempData.channelId = channel.id; - assertEquals(tempData.channelId, channel.id); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed await delay(5000); diff --git a/tests/guilds/create_guild.ts b/tests/guilds/create_guild.ts index b63546e72..7da00835b 100644 --- a/tests/guilds/create_guild.ts +++ b/tests/guilds/create_guild.ts @@ -1,6 +1,6 @@ import { cache, createGuild, delay } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; +import { assertExists } from "../deps.ts"; Deno.test({ name: "[guild] create a new guild", @@ -13,7 +13,6 @@ Deno.test({ assertExists(guild); tempData.guildId = guild.id; - assertEquals(tempData.guildId, guild.id); // Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed await delay(5000);