From 5afa6f2c135905fdc2f29cc051fe0e3f84fc7934 Mon Sep 17 00:00:00 2001 From: itohatweb Date: Tue, 13 Apr 2021 07:26:23 +0000 Subject: [PATCH] --- .../channel_overwrite_has_permission.ts | 17 ++++-- tests/channels/edit_channel.ts | 15 +++-- tests/channels/edit_channel_overwrite.ts | 25 +++++--- tests/channels/get_channel.ts | 14 ++--- tests/channels/get_channels.ts | 14 ++--- tests/channels/get_pins.ts | 31 ++++++---- tests/channels/is_channel_synced.ts | 26 +++++---- tests/channels/start_typing.ts | 18 +++--- tests/channels/swap_channels.ts | 57 ++++++++++++------- tests/mod.ts | 1 - 10 files changed, 132 insertions(+), 86 deletions(-) diff --git a/tests/channels/channel_overwrite_has_permission.ts b/tests/channels/channel_overwrite_has_permission.ts index 3c31e13f6..d57532c20 100644 --- a/tests/channels/channel_overwrite_has_permission.ts +++ b/tests/channels/channel_overwrite_has_permission.ts @@ -8,9 +8,9 @@ import { delayUntil } from "../util/delay_until.ts"; import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; import { botId } from "../../src/bot.ts"; import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts"; -import {editChannelOverwrite} from "../../src/helpers/channels/edit_channel_overwrite.ts"; -import {channelOverwriteHasPermission} from "../../src/helpers/channels/channel_overwrite_has_permission.ts"; -import {DiscordBitwisePermissionFlags} from "../../src/types/permissions/bitwise_permission_flags.ts"; +import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts"; +import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts"; +import { DiscordBitwisePermissionFlags } from "../../src/types/permissions/bitwise_permission_flags.ts"; async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { const channel = await createChannel(tempData.guildId, options); @@ -36,9 +36,14 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { } assertEquals( - channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, options.permissionOverwrites ? options.permissionOverwrites[0].allow : []), - true - ) + channelOverwriteHasPermission( + channel.guildId, + botId, + cache.channels.get(channel.id)?.permissionOverwrites, + options.permissionOverwrites ? options.permissionOverwrites[0].allow : [], + ), + true, + ); } Deno.test({ diff --git a/tests/channels/edit_channel.ts b/tests/channels/edit_channel.ts index 1b7ffd430..5b158339f 100644 --- a/tests/channels/edit_channel.ts +++ b/tests/channels/edit_channel.ts @@ -2,8 +2,8 @@ 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"; +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 @@ -15,22 +15,25 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { // 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.", + "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" + name: "new-name", }, reason); } else { await channel.edit({ - name: "new-name" + 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"); + await delayUntil( + 3000, + () => cache.channels.get(channel.id)?.name === "new-name", + ); assertEquals(cache.channels.get(channel.id)?.name, "new-name"); } diff --git a/tests/channels/edit_channel_overwrite.ts b/tests/channels/edit_channel_overwrite.ts index 807350399..91af1e4d3 100644 --- a/tests/channels/edit_channel_overwrite.ts +++ b/tests/channels/edit_channel_overwrite.ts @@ -8,9 +8,9 @@ import { delayUntil } from "../util/delay_until.ts"; import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; import { botId } from "../../src/bot.ts"; import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts"; -import {editChannelOverwrite} from "../../src/helpers/channels/edit_channel_overwrite.ts"; -import {channelOverwriteHasPermission} from "../../src/helpers/channels/channel_overwrite_has_permission.ts"; -import {DiscordBitwisePermissionFlags} from "../../src/types/permissions/bitwise_permission_flags.ts"; +import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts"; +import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts"; +import { DiscordBitwisePermissionFlags } from "../../src/types/permissions/bitwise_permission_flags.ts"; async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { const channel = await createChannel(tempData.guildId, options); @@ -43,13 +43,24 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { await delayUntil( 10000, - () => channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, ["VIEW_CHANNEL", "ADD_REACTIONS"]), + () => + 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 - ) + channelOverwriteHasPermission( + channel.guildId, + botId, + cache.channels.get(channel.id)?.permissionOverwrites, + ["VIEW_CHANNEL", "ADD_REACTIONS"], + ), + true, + ); } Deno.test({ diff --git a/tests/channels/get_channel.ts b/tests/channels/get_channel.ts index 2fed1f2e6..05e835553 100644 --- a/tests/channels/get_channel.ts +++ b/tests/channels/get_channel.ts @@ -3,10 +3,10 @@ import { createChannel } from "../../src/helpers/channels/create_channel.ts"; import { deleteChannel } from "../../src/helpers/channels/delete_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"; -import {getChannel} from "../../src/helpers/channels/get_channel.ts"; -import {botId} from "../../src/bot.ts"; +import { editChannel } from "../../src/helpers/channels/edit_channel.ts"; +import { assertEquals } from "../deps.ts"; +import { getChannel } from "../../src/helpers/channels/get_channel.ts"; +import { botId } from "../../src/bot.ts"; Deno.test({ name: "[channel] get a channel", @@ -20,7 +20,7 @@ Deno.test({ // 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.", + "The channel should have been created but it is not in the cache.", ); } @@ -31,8 +31,8 @@ Deno.test({ await delayUntil(3000, () => cache.channels.has(channel.id)); assertEquals( - cache.channels.has(channel.id), - true, + cache.channels.has(channel.id), + true, ); }, ...defaultTestOptions, diff --git a/tests/channels/get_channels.ts b/tests/channels/get_channels.ts index b1d14e100..48a6e110d 100644 --- a/tests/channels/get_channels.ts +++ b/tests/channels/get_channels.ts @@ -3,11 +3,11 @@ import { createChannel } from "../../src/helpers/channels/create_channel.ts"; import { deleteChannel } from "../../src/helpers/channels/delete_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"; -import {getChannel} from "../../src/helpers/channels/get_channel.ts"; -import {botId} from "../../src/bot.ts"; -import {getChannels} from "../../src/helpers/channels/get_channels.ts"; +import { editChannel } from "../../src/helpers/channels/edit_channel.ts"; +import { assertEquals } from "../deps.ts"; +import { getChannel } from "../../src/helpers/channels/get_channel.ts"; +import { botId } from "../../src/bot.ts"; +import { getChannels } from "../../src/helpers/channels/get_channels.ts"; Deno.test({ name: "[channel] get channels.", @@ -19,8 +19,8 @@ Deno.test({ await delayUntil(3000, () => cache.channels.size > 0); assertEquals( - cache.channels.size > 0, - true, + cache.channels.size > 0, + true, ); }, ...defaultTestOptions, diff --git a/tests/channels/get_pins.ts b/tests/channels/get_pins.ts index 48df669a3..fd708c58f 100644 --- a/tests/channels/get_pins.ts +++ b/tests/channels/get_pins.ts @@ -2,17 +2,17 @@ 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 {assertEquals, assertExists} from "../deps.ts"; -import {getChannels} from "../../src/helpers/channels/get_channels.ts"; -import {sendMessage} from "../../src/helpers/messages/send_message.ts"; -import {getPins} from "../../src/helpers/channels/get_pins.ts"; -import {DiscordenoMessage} from "../../src/structures/message.ts"; +import { assertEquals, assertExists } from "../deps.ts"; +import { getChannels } from "../../src/helpers/channels/get_channels.ts"; +import { sendMessage } from "../../src/helpers/messages/send_message.ts"; +import { getPins } from "../../src/helpers/channels/get_pins.ts"; +import { DiscordenoMessage } from "../../src/structures/message.ts"; Deno.test({ name: "[channel] get pins.", async fn() { const channel = await createChannel(tempData.guildId, { - name: 'pins-channel' + name: "pins-channel", }); // Assertions @@ -22,14 +22,23 @@ Deno.test({ 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."); + 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!"); + 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 delayUntil( + 10000, + () => + cache.messages.has(message.id) && cache.messages.has(secondMessage.id), + ); await message.pin(); await secondMessage.pin(); @@ -37,8 +46,8 @@ Deno.test({ const pins = await getPins(tempData.channelId); assertEquals( - pins.length, - 2, + pins.length, + 2, ); }, ...defaultTestOptions, diff --git a/tests/channels/is_channel_synced.ts b/tests/channels/is_channel_synced.ts index eb3506a73..eac621f6a 100644 --- a/tests/channels/is_channel_synced.ts +++ b/tests/channels/is_channel_synced.ts @@ -2,11 +2,11 @@ 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 {assertEquals, assertExists} from "../deps.ts"; -import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts"; -import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts"; -import {botId} from "../../src/bot.ts"; -import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts"; +import { assertEquals, assertExists } from "../deps.ts"; +import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts"; +import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; +import { botId } from "../../src/bot.ts"; +import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; Deno.test({ name: "[channel] is channel synced.", @@ -31,12 +31,14 @@ Deno.test({ 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."); + 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 + name: "synced-channel", + parentId: category.id, }); // Assertions @@ -46,14 +48,16 @@ Deno.test({ 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."); + throw new Error( + "The channel seemed to be created but it was not cached.", + ); } const isSynced = await isChannelSynced(channel.id); assertEquals( - isSynced, - true, + isSynced, + true, ); }, ...defaultTestOptions, diff --git a/tests/channels/start_typing.ts b/tests/channels/start_typing.ts index 71026e88f..c3d5eff72 100644 --- a/tests/channels/start_typing.ts +++ b/tests/channels/start_typing.ts @@ -2,18 +2,18 @@ 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 {assertEquals, assertExists} from "../deps.ts"; -import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts"; -import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts"; -import {botId} from "../../src/bot.ts"; -import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts"; -import {startTyping} from "../../src/helpers/channels/start_typing.ts"; +import { assertEquals, assertExists } from "../deps.ts"; +import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts"; +import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; +import { botId } from "../../src/bot.ts"; +import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; +import { startTyping } from "../../src/helpers/channels/start_typing.ts"; Deno.test({ name: "[channel] is typing.", async fn() { const channel = await createChannel(tempData.guildId, { - name: 'typing-channel', + name: "typing-channel", }); // Assertions @@ -23,7 +23,9 @@ Deno.test({ 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."); + throw new Error( + "The channel seemed to be created but it was not cached.", + ); } await startTyping(channel.id); diff --git a/tests/channels/swap_channels.ts b/tests/channels/swap_channels.ts index 206c9a02c..8144a5a20 100644 --- a/tests/channels/swap_channels.ts +++ b/tests/channels/swap_channels.ts @@ -2,61 +2,74 @@ 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 {assertEquals, assertExists} from "../deps.ts"; -import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts"; -import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts"; -import {botId} from "../../src/bot.ts"; -import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts"; -import {startTyping} from "../../src/helpers/channels/start_typing.ts"; -import {swapChannels} from "../../src/helpers/channels/swap_channels.ts"; +import { assertEquals, assertExists } from "../deps.ts"; +import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts"; +import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; +import { botId } from "../../src/bot.ts"; +import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; +import { startTyping } from "../../src/helpers/channels/start_typing.ts"; +import { swapChannels } from "../../src/helpers/channels/swap_channels.ts"; Deno.test({ name: "[channel] swap channels", async fn() { const channel = await createChannel(tempData.guildId, { - name: 'channel-1', + name: "channel-1", }); // Assertions assertExists(channel); const secondChannel = await createChannel(tempData.guildId, { - name: 'channel-2', + 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)); + 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."); + 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, - position: secondChannel.position! + position: secondChannel.position!, }, { id: secondChannel.id, - position: channel.position! - } + 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); + 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 - ) + cache.channels.get(channel.id)?.position, + secondChannel.position, + ); assertEquals( - cache.channels.get(secondChannel.id)?.position, - channel.position - ) + cache.channels.get(secondChannel.id)?.position, + channel.position, + ); }, ...defaultTestOptions, }); diff --git a/tests/mod.ts b/tests/mod.ts index 401f083e9..3cf2a56f8 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -26,7 +26,6 @@ import "./channels/is_channel_synced.ts"; import "./channels/start_typing.ts"; import "./channels/swap_channels.ts"; - // Emojis tests import "./emojis/create_emoji.ts"; import "./emojis/delete_emoji.ts";