From 12e21084a674739a541b5f3f8a409b118354c1a3 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 10 Apr 2021 20:24:38 +0200 Subject: [PATCH] fix(tests): fix reactions tests --- tests/channels/category_children.ts | 16 +++++++------ tests/channels/create_channel.ts | 32 ++++++++++++++++++------- tests/messages/add_reaction.ts | 8 +++---- tests/messages/add_reactions.ts | 5 +--- tests/messages/create_message.ts | 7 +++--- tests/messages/remove_all_reactions.ts | 4 ++-- tests/messages/remove_reaction.ts | 4 ++-- tests/messages/remove_reaction_emoji.ts | 4 ++-- tests/messages/remove_user_reaction.ts | 4 ++-- tests/util/utils.ts | 5 +++- 10 files changed, 53 insertions(+), 36 deletions(-) diff --git a/tests/channels/category_children.ts b/tests/channels/category_children.ts index 76300a2fb..55412d2fb 100644 --- a/tests/channels/category_children.ts +++ b/tests/channels/category_children.ts @@ -1,7 +1,7 @@ import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; -import { createChannel, categoryChildren } from "../../src/helpers/mod.ts"; +import { categoryChildren, createChannel } from "../../src/helpers/mod.ts"; import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; import { delay } from "../../src/util/utils.ts"; @@ -20,7 +20,7 @@ Deno.test({ if (!cache.channels.has(category.id)) { throw new Error( - "The channel seemed to be created but it was not cached." + "The channel seemed to be created but it was not cached.", ); } @@ -31,25 +31,27 @@ Deno.test({ name: `Discordeno-test-${num}`, parentId: category.id, }) - ) + ), ); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed await delay(5000); // If every channel is not present in the cache, error out - if (!channels.every((c) => cache.channels.has(c.id))) + if (!channels.every((c) => cache.channels.has(c.id))) { throw new Error( - "The channels seemed to be created but it was not cached." + "The channels seemed to be created but it was not cached.", ); + } const ids = await categoryChildren(category.id); if ( ids.size !== channelsToCreate.length || !channels.every((c) => ids.has(c.id)) - ) + ) { throw new Error( - "The category channel ids did not match with the category channels." + "The category channel ids did not match with the category channels.", ); + } }, ...defaultTestOptions, }); diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index 78032eb3b..1865050e4 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -40,7 +40,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { Deno.test({ name: "[channel] create a new text channel", async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-test"}, true); + await ifItFailsBlameWolf({ name: "Discordeno-test" }, true); }, ...defaultTestOptions, }); @@ -48,7 +48,10 @@ Deno.test({ Deno.test({ name: "[channel] create a new category channel", async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_CATEGORY}, true); + await ifItFailsBlameWolf({ + name: "Discordeno-test", + type: DiscordChannelTypes.GUILD_CATEGORY, + }, true); }, ...defaultTestOptions, }); @@ -72,7 +75,10 @@ Deno.test({ Deno.test({ name: "[channel] create a new voice channel", async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_VOICE}, true); + await ifItFailsBlameWolf({ + name: "Discordeno-test", + type: DiscordChannelTypes.GUILD_VOICE, + }, true); }, ...defaultTestOptions, }); @@ -80,7 +86,11 @@ Deno.test({ Deno.test({ name: "[channel] create a new voice channel with a bitrate", async fn() { - await ifItFailsBlameWolf({ name: "discordeno-test", type: DiscordChannelTypes.GUILD_VOICE, bitrate: 32000 }, true); + await ifItFailsBlameWolf({ + name: "discordeno-test", + type: DiscordChannelTypes.GUILD_VOICE, + bitrate: 32000, + }, true); }, ...defaultTestOptions, }); @@ -88,7 +98,11 @@ Deno.test({ Deno.test({ name: "[channel] create a new voice channel with a user limit", async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_VOICE, userLimit: 32 }, true); + await ifItFailsBlameWolf({ + name: "Discordeno-test", + type: DiscordChannelTypes.GUILD_VOICE, + userLimit: 32, + }, true); }, ...defaultTestOptions, }); @@ -96,7 +110,10 @@ Deno.test({ Deno.test({ name: "[channel] create a new text channel with a rate limit per user", async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-test", rateLimitPerUser: 2423 }, true); + await ifItFailsBlameWolf({ + name: "Discordeno-test", + rateLimitPerUser: 2423, + }, true); }, ...defaultTestOptions, }); @@ -109,9 +126,8 @@ Deno.test({ ...defaultTestOptions, }); - // TODO: Need to validate tests for these options // /** Sorting position of the channel */ // position?: number; // /** The channel's permission overwrites */ -// permissionOverwrites?: Overwrite[]; \ No newline at end of file +// permissionOverwrites?: Overwrite[]; diff --git a/tests/messages/add_reaction.ts b/tests/messages/add_reaction.ts index 30f4cd88a..81870877e 100644 --- a/tests/messages/add_reaction.ts +++ b/tests/messages/add_reaction.ts @@ -5,7 +5,7 @@ import { DiscordReaction } from "../../src/types/messages/reaction.ts"; import { delay } from "../../src/util/utils.ts"; import { sendMessage } from "../../src/helpers/messages/send_message.ts"; import { addReaction } from "../../src/helpers/messages/add_reaction.ts"; -import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts" +import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -33,7 +33,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { name: "blamewolf", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", roles: [], - } + }, ) ).id }>`; @@ -52,9 +52,9 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { .get(message.id) ?.reactions?.filter( (reaction: DiscordReaction) => - reaction.emoji?.name === (custom ? "blamewolf" : "❤") + reaction.emoji?.name === (custom ? "blamewolf" : "❤"), ).length, - 1 + 1, ); } diff --git a/tests/messages/add_reactions.ts b/tests/messages/add_reactions.ts index d4c52cb68..6c8304b51 100644 --- a/tests/messages/add_reactions.ts +++ b/tests/messages/add_reactions.ts @@ -3,7 +3,6 @@ import { cache, createEmoji, delay, - DiscordReaction, sendMessage, } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; @@ -68,9 +67,7 @@ async function ifItFailsBlameWolf( await delay(5000); assertEquals( - await cache.messages.get(message.id)?.reactions?.filter(( - reaction: DiscordReaction, - ) => emojiIds.includes(reaction.emoji?.name)).length, + await cache.messages.get(message.id)?.reactions?.length, 2, ); } diff --git a/tests/messages/create_message.ts b/tests/messages/create_message.ts index 4db40aff1..60ad0a39e 100644 --- a/tests/messages/create_message.ts +++ b/tests/messages/create_message.ts @@ -14,10 +14,9 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Wait few seconds for the channel create event to arrive and cache it await delay(5000); - const message = - type === "raw" - ? await sendMessage(channel.id, "Hello World!") - : await channel.send("Hello World!"); + const message = type === "raw" + ? await sendMessage(channel.id, "Hello World!") + : await channel.send("Hello World!"); // Assertions assertExists(message); diff --git a/tests/messages/remove_all_reactions.ts b/tests/messages/remove_all_reactions.ts index 72454a5ba..8413ca185 100644 --- a/tests/messages/remove_all_reactions.ts +++ b/tests/messages/remove_all_reactions.ts @@ -44,8 +44,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Check if the reactions has been deleted assertEquals( - await cache.messages.get(message.id)?.reactions?.length, - 0, + await cache.messages.get(message.id)?.reactions, + undefined, ); } diff --git a/tests/messages/remove_reaction.ts b/tests/messages/remove_reaction.ts index 50f1e549f..db03da756 100644 --- a/tests/messages/remove_reaction.ts +++ b/tests/messages/remove_reaction.ts @@ -44,8 +44,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Check if the reactions has been deleted assertEquals( - await cache.messages.get(message.id)?.reactions?.length, - 0, + await cache.messages.get(message.id)?.reactions, + undefined, ); } diff --git a/tests/messages/remove_reaction_emoji.ts b/tests/messages/remove_reaction_emoji.ts index 7d4814806..ed9194f04 100644 --- a/tests/messages/remove_reaction_emoji.ts +++ b/tests/messages/remove_reaction_emoji.ts @@ -45,8 +45,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Check if the reactions has been deleted assertEquals( - await cache.messages.get(message.id)?.reactions?.length, - 0, + await cache.messages.get(message.id)?.reactions, + undefined, ); } diff --git a/tests/messages/remove_user_reaction.ts b/tests/messages/remove_user_reaction.ts index 5cdd48e1b..cd22ea735 100644 --- a/tests/messages/remove_user_reaction.ts +++ b/tests/messages/remove_user_reaction.ts @@ -50,8 +50,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Check if the reactions has been deleted assertEquals( - await cache.messages.get(message.id)?.reactions?.length, - 0, + await cache.messages.get(message.id)?.reactions, + undefined, ); } diff --git a/tests/util/utils.ts b/tests/util/utils.ts index 77e3b8aef..c8a0fb686 100644 --- a/tests/util/utils.ts +++ b/tests/util/utils.ts @@ -1,4 +1,7 @@ -import { snakeKeysToCamelCase,camelKeysToSnakeCase } from "../../src/util/utils.ts"; +import { + camelKeysToSnakeCase, + snakeKeysToCamelCase, +} from "../../src/util/utils.ts"; import { assertEquals } from "../deps.ts"; const testSnakeObject = {