From 059614e69576e20ea25e822ff5642542cc42be1a Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Mon, 1 Nov 2021 08:30:55 +0100 Subject: [PATCH 1/8] [Unit Tests] Helpers: emojis --- tests/helpers/emojis/createEmoji.ts | 21 +++++++++++ tests/helpers/emojis/deleteEmoji.ts | 37 +++++++++++++++++++ tests/helpers/emojis/editEmoji.ts | 31 ++++++++++++++++ tests/helpers/emojis/getEmoji.ts | 35 ++++++++++++++++++ tests/helpers/emojis/getEmojis.ts | 27 ++++++++++++++ tests/mod.ts | 55 ++++++++++++++++++++++++++++- 6 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 tests/helpers/emojis/createEmoji.ts create mode 100644 tests/helpers/emojis/deleteEmoji.ts create mode 100644 tests/helpers/emojis/editEmoji.ts create mode 100644 tests/helpers/emojis/getEmoji.ts create mode 100644 tests/helpers/emojis/getEmojis.ts diff --git a/tests/helpers/emojis/createEmoji.ts b/tests/helpers/emojis/createEmoji.ts new file mode 100644 index 000000000..8b85278f4 --- /dev/null +++ b/tests/helpers/emojis/createEmoji.ts @@ -0,0 +1,21 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function createEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji); + + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } +} diff --git a/tests/helpers/emojis/deleteEmoji.ts b/tests/helpers/emojis/deleteEmoji.ts new file mode 100644 index 000000000..5c98cf782 --- /dev/null +++ b/tests/helpers/emojis/deleteEmoji.ts @@ -0,0 +1,37 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function ifItFailsBlameWolf(bot: Bot, guildId: bigint, reason?: string) { + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji); + + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } + + await bot.helpers.deleteEmoji(guildId, emoji.id, reason); + + await delayUntil(10000, async () => !(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + + if ((await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be deleted but it's still cached."); + } +} + +export async function deleteEmojiWithReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { + await ifItFailsBlameWolf(bot, guildId); +} + +export async function deleteEmojiWithoutReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { + await ifItFailsBlameWolf(bot, guildId, "with a reason"); +} diff --git a/tests/helpers/emojis/editEmoji.ts b/tests/helpers/emojis/editEmoji.ts new file mode 100644 index 000000000..bf07a907f --- /dev/null +++ b/tests/helpers/emojis/editEmoji.ts @@ -0,0 +1,31 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function editEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji); + + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } + + await bot.helpers.editEmoji(guildId, emoji.id, { + name: "blamewolf_infinite", + }); + + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.get(emoji.id)?.name === "blamewolf_infinite"); + + if ((await bot.cache.guilds.get(guildId))?.emojis?.get(emoji.id)?.name !== "blamewolf_infinite") { + throw new Error("The emoji seemed to be edited but the cache was not updated."); + } +} diff --git a/tests/helpers/emojis/getEmoji.ts b/tests/helpers/emojis/getEmoji.ts new file mode 100644 index 000000000..496014d83 --- /dev/null +++ b/tests/helpers/emojis/getEmoji.ts @@ -0,0 +1,35 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function getEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji); + + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } + + (await bot.cache.guilds.get(guildId))?.emojis?.delete(emoji.id); + + const getEmoji = await bot.helpers.getEmoji(guildId, emoji.id, true); + + // Assertions + assertExists(getEmoji); + + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji didn't got added to cache after using the getEmoji function."); + } +} diff --git a/tests/helpers/emojis/getEmojis.ts b/tests/helpers/emojis/getEmojis.ts new file mode 100644 index 000000000..c00c33879 --- /dev/null +++ b/tests/helpers/emojis/getEmojis.ts @@ -0,0 +1,27 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function getEmojisTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji); + + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } + + const emojis = await bot.helpers.getEmojis(guildId); + + if (emojis.size === 0) { + throw new Error("The getEmojis function returned 0 emojis."); + } +} diff --git a/tests/mod.ts b/tests/mod.ts index 22d8117dd..b385c878e 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -28,6 +28,11 @@ 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"; +import {createEmojiTest} from "./helpers/emojis/createEmoji.ts"; +import {deleteEmojiWithoutReasonTest, deleteEmojiWithReasonTest} from "./helpers/emojis/deleteEmoji.ts"; +import {editEmojiTest} from "./helpers/emojis/editEmoji.ts"; +import {getEmojiTest} from "./helpers/emojis/getEmoji.ts"; +import {getEmojisTest} from "./helpers/emojis/getEmojis.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS @@ -51,7 +56,7 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, // debug: console.log, }), - intents: ["Guilds", "GuildMessages", "GuildMessageReactions"], + intents: ["Guilds", "GuildEmojis", "GuildMessages", "GuildMessageReactions"], cache: { isAsync: false, }, @@ -473,5 +478,53 @@ Deno.test("[Bot] - Starting Tests", async (t) => { ]); }); + // EMOJIS TESTS GROUPED + await t.step("Emojis related tests", async (t) => { + await Promise.all([ + t.step({ + name: "[emoji] create an emoji", + fn: async (t) => { + await createEmojiTest(bot, guild.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[emoji] delete an emoji without a reason", + fn: async (t) => { + await deleteEmojiWithoutReasonTest(bot, guild.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[emoji] delete an emoji with a reason", + fn: async (t) => { + await deleteEmojiWithReasonTest(bot, guild.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[emoji] edit an emoji", + fn: async (t) => { + await editEmojiTest(bot, guild.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[emoji] get an emoji", + fn: async (t) => { + await getEmojiTest(bot, guild.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[emoji] get multiple emojis", + fn: async (t) => { + await getEmojisTest(bot, guild.id, t); + }, + ...sanitizeMode, + }) + ]); + }) + await stopBot(bot); }); From 30e34a7aba0442929412f5679a9549dd304bab92 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Mon, 1 Nov 2021 07:32:01 +0000 Subject: [PATCH 2/8] change: prettier code --- tests/helpers/emojis/createEmoji.ts | 24 ++++++++--------- tests/helpers/emojis/deleteEmoji.ts | 38 +++++++++++++------------- tests/helpers/emojis/editEmoji.ts | 41 +++++++++++++++------------- tests/helpers/emojis/getEmoji.ts | 42 ++++++++++++++--------------- tests/helpers/emojis/getEmojis.ts | 32 +++++++++++----------- tests/mod.ts | 28 +++++++++---------- 6 files changed, 104 insertions(+), 101 deletions(-) diff --git a/tests/helpers/emojis/createEmoji.ts b/tests/helpers/emojis/createEmoji.ts index 8b85278f4..5ad7581a9 100644 --- a/tests/helpers/emojis/createEmoji.ts +++ b/tests/helpers/emojis/createEmoji.ts @@ -3,19 +3,19 @@ import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; export async function createEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - const emoji = await bot.helpers.createEmoji(guildId, { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - }); + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); - // Assertions - assertExists(emoji); + // Assertions + assertExists(emoji); - // Delay the execution to allow event to be processed - await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); - if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } } diff --git a/tests/helpers/emojis/deleteEmoji.ts b/tests/helpers/emojis/deleteEmoji.ts index 5c98cf782..3cb3cdde5 100644 --- a/tests/helpers/emojis/deleteEmoji.ts +++ b/tests/helpers/emojis/deleteEmoji.ts @@ -3,35 +3,35 @@ import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; export async function ifItFailsBlameWolf(bot: Bot, guildId: bigint, reason?: string) { - const emoji = await bot.helpers.createEmoji(guildId, { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - }); + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); - // Assertions - assertExists(emoji); + // Assertions + assertExists(emoji); - // Delay the execution to allow event to be processed - await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); - if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } - await bot.helpers.deleteEmoji(guildId, emoji.id, reason); + await bot.helpers.deleteEmoji(guildId, emoji.id, reason); - await delayUntil(10000, async () => !(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + await delayUntil(10000, async () => !(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); - if ((await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be deleted but it's still cached."); - } + if ((await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be deleted but it's still cached."); + } } export async function deleteEmojiWithReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, guildId); + await ifItFailsBlameWolf(bot, guildId); } export async function deleteEmojiWithoutReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - await ifItFailsBlameWolf(bot, guildId, "with a reason"); + await ifItFailsBlameWolf(bot, guildId, "with a reason"); } diff --git a/tests/helpers/emojis/editEmoji.ts b/tests/helpers/emojis/editEmoji.ts index bf07a907f..b0ecab94c 100644 --- a/tests/helpers/emojis/editEmoji.ts +++ b/tests/helpers/emojis/editEmoji.ts @@ -3,29 +3,32 @@ import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; export async function editEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - const emoji = await bot.helpers.createEmoji(guildId, { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - }); + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); - // Assertions - assertExists(emoji); + // Assertions + assertExists(emoji); - // Delay the execution to allow event to be processed - await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); - if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } - await bot.helpers.editEmoji(guildId, emoji.id, { - name: "blamewolf_infinite", - }); + await bot.helpers.editEmoji(guildId, emoji.id, { + name: "blamewolf_infinite", + }); - await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.get(emoji.id)?.name === "blamewolf_infinite"); + await delayUntil( + 10000, + async () => (await bot.cache.guilds.get(guildId))?.emojis?.get(emoji.id)?.name === "blamewolf_infinite" + ); - if ((await bot.cache.guilds.get(guildId))?.emojis?.get(emoji.id)?.name !== "blamewolf_infinite") { - throw new Error("The emoji seemed to be edited but the cache was not updated."); - } + if ((await bot.cache.guilds.get(guildId))?.emojis?.get(emoji.id)?.name !== "blamewolf_infinite") { + throw new Error("The emoji seemed to be edited but the cache was not updated."); + } } diff --git a/tests/helpers/emojis/getEmoji.ts b/tests/helpers/emojis/getEmoji.ts index 496014d83..ea94ad6a7 100644 --- a/tests/helpers/emojis/getEmoji.ts +++ b/tests/helpers/emojis/getEmoji.ts @@ -3,33 +3,33 @@ import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; export async function getEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - const emoji = await bot.helpers.createEmoji(guildId, { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - }); + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); - // Assertions - assertExists(emoji); + // Assertions + assertExists(emoji); - // Delay the execution to allow event to be processed - await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); - if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } - (await bot.cache.guilds.get(guildId))?.emojis?.delete(emoji.id); + (await bot.cache.guilds.get(guildId))?.emojis?.delete(emoji.id); - const getEmoji = await bot.helpers.getEmoji(guildId, emoji.id, true); + const getEmoji = await bot.helpers.getEmoji(guildId, emoji.id, true); - // Assertions - assertExists(getEmoji); + // Assertions + assertExists(getEmoji); - // Delay the execution to allow event to be processed - await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); - if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { - throw new Error("The emoji didn't got added to cache after using the getEmoji function."); - } + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji didn't got added to cache after using the getEmoji function."); + } } diff --git a/tests/helpers/emojis/getEmojis.ts b/tests/helpers/emojis/getEmojis.ts index c00c33879..b9e1a1bbc 100644 --- a/tests/helpers/emojis/getEmojis.ts +++ b/tests/helpers/emojis/getEmojis.ts @@ -3,25 +3,25 @@ import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; export async function getEmojisTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { - const emoji = await bot.helpers.createEmoji(guildId, { - name: "blamewolf", - image: "https://cdn.discordapp.com/emojis/814955268123000832.png", - roles: [], - }); + const emoji = await bot.helpers.createEmoji(guildId, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); - // Assertions - assertExists(emoji); + // Assertions + assertExists(emoji); - // Delay the execution to allow event to be processed - await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); + // Delay the execution to allow event to be processed + await delayUntil(10000, async () => (await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)); - if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } + if (!(await bot.cache.guilds.get(guildId))?.emojis?.has(emoji.id)) { + throw new Error("The emoji seemed to be created but it was not cached."); + } - const emojis = await bot.helpers.getEmojis(guildId); + const emojis = await bot.helpers.getEmojis(guildId); - if (emojis.size === 0) { - throw new Error("The getEmojis function returned 0 emojis."); - } + if (emojis.size === 0) { + throw new Error("The getEmojis function returned 0 emojis."); + } } diff --git a/tests/mod.ts b/tests/mod.ts index b385c878e..72294f8c7 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -28,11 +28,11 @@ 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"; -import {createEmojiTest} from "./helpers/emojis/createEmoji.ts"; -import {deleteEmojiWithoutReasonTest, deleteEmojiWithReasonTest} from "./helpers/emojis/deleteEmoji.ts"; -import {editEmojiTest} from "./helpers/emojis/editEmoji.ts"; -import {getEmojiTest} from "./helpers/emojis/getEmoji.ts"; -import {getEmojisTest} from "./helpers/emojis/getEmojis.ts"; +import { createEmojiTest } from "./helpers/emojis/createEmoji.ts"; +import { deleteEmojiWithoutReasonTest, deleteEmojiWithReasonTest } from "./helpers/emojis/deleteEmoji.ts"; +import { editEmojiTest } from "./helpers/emojis/editEmoji.ts"; +import { getEmojiTest } from "./helpers/emojis/getEmoji.ts"; +import { getEmojisTest } from "./helpers/emojis/getEmojis.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS @@ -481,13 +481,13 @@ Deno.test("[Bot] - Starting Tests", async (t) => { // EMOJIS TESTS GROUPED await t.step("Emojis related tests", async (t) => { await Promise.all([ - t.step({ - name: "[emoji] create an emoji", - fn: async (t) => { - await createEmojiTest(bot, guild.id, t); - }, - ...sanitizeMode, - }), + t.step({ + name: "[emoji] create an emoji", + fn: async (t) => { + await createEmojiTest(bot, guild.id, t); + }, + ...sanitizeMode, + }), t.step({ name: "[emoji] delete an emoji without a reason", fn: async (t) => { @@ -522,9 +522,9 @@ Deno.test("[Bot] - Starting Tests", async (t) => { await getEmojisTest(bot, guild.id, t); }, ...sanitizeMode, - }) + }), ]); - }) + }); await stopBot(bot); }); From 8bffe996c4e7a37d3fb1688bdd80402d06660eaf Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Mon, 1 Nov 2021 10:06:34 +0100 Subject: [PATCH 3/8] Follow snake_case convention --- .../helpers/emojis/{createEmoji.ts => create_emoji.ts} | 0 .../helpers/emojis/{deleteEmoji.ts => delete_emoji.ts} | 0 tests/helpers/emojis/{editEmoji.ts => edit_emoji.ts} | 0 tests/helpers/emojis/{getEmoji.ts => get_emoji.ts} | 0 tests/helpers/emojis/{getEmojis.ts => get_emojis.ts} | 0 tests/mod.ts | 10 +++++----- 6 files changed, 5 insertions(+), 5 deletions(-) rename tests/helpers/emojis/{createEmoji.ts => create_emoji.ts} (100%) rename tests/helpers/emojis/{deleteEmoji.ts => delete_emoji.ts} (100%) rename tests/helpers/emojis/{editEmoji.ts => edit_emoji.ts} (100%) rename tests/helpers/emojis/{getEmoji.ts => get_emoji.ts} (100%) rename tests/helpers/emojis/{getEmojis.ts => get_emojis.ts} (100%) diff --git a/tests/helpers/emojis/createEmoji.ts b/tests/helpers/emojis/create_emoji.ts similarity index 100% rename from tests/helpers/emojis/createEmoji.ts rename to tests/helpers/emojis/create_emoji.ts diff --git a/tests/helpers/emojis/deleteEmoji.ts b/tests/helpers/emojis/delete_emoji.ts similarity index 100% rename from tests/helpers/emojis/deleteEmoji.ts rename to tests/helpers/emojis/delete_emoji.ts diff --git a/tests/helpers/emojis/editEmoji.ts b/tests/helpers/emojis/edit_emoji.ts similarity index 100% rename from tests/helpers/emojis/editEmoji.ts rename to tests/helpers/emojis/edit_emoji.ts diff --git a/tests/helpers/emojis/getEmoji.ts b/tests/helpers/emojis/get_emoji.ts similarity index 100% rename from tests/helpers/emojis/getEmoji.ts rename to tests/helpers/emojis/get_emoji.ts diff --git a/tests/helpers/emojis/getEmojis.ts b/tests/helpers/emojis/get_emojis.ts similarity index 100% rename from tests/helpers/emojis/getEmojis.ts rename to tests/helpers/emojis/get_emojis.ts diff --git a/tests/mod.ts b/tests/mod.ts index 72294f8c7..967f02101 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -28,11 +28,11 @@ 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"; -import { createEmojiTest } from "./helpers/emojis/createEmoji.ts"; -import { deleteEmojiWithoutReasonTest, deleteEmojiWithReasonTest } from "./helpers/emojis/deleteEmoji.ts"; -import { editEmojiTest } from "./helpers/emojis/editEmoji.ts"; -import { getEmojiTest } from "./helpers/emojis/getEmoji.ts"; -import { getEmojisTest } from "./helpers/emojis/getEmojis.ts"; +import { createEmojiTest } from "./helpers/emojis/create_emoji.ts"; +import { deleteEmojiWithoutReasonTest, deleteEmojiWithReasonTest } from "./helpers/emojis/delete_emoji.ts"; +import { editEmojiTest } from "./helpers/emojis/edit_emoji.ts"; +import { getEmojiTest } from "./helpers/emojis/get_emoji.ts"; +import { getEmojisTest } from "./helpers/emojis/get_emojis.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS From 5d554c9d173d222166c8d7ba38d409cd4b85e0b0 Mon Sep 17 00:00:00 2001 From: lts372005 <87189679+lts372005@users.noreply.github.com> Date: Mon, 1 Nov 2021 16:23:29 +0700 Subject: [PATCH 4/8] snakelize and therefore fix tests/mod.ts imports --- .../{createChannel.ts => create_channel.ts} | 0 .../{deleteChannel.ts => delete_channel.ts} | 0 .../{fetchMembers.ts => fetch_members.ts} | 0 .../{deleteMessage.ts => delete_message.ts} | 0 .../{deleteMessages.ts => delete_messages.ts} | 0 .../{editMessage.ts => edit_message.ts} | 0 .../messages/{getMessage.ts => get_message.ts} | 0 .../{getMessages.ts => get_messages.ts} | 0 .../{sendMessage.ts => send_message.ts} | 0 tests/mod.ts | 18 +++++++++--------- tests/util/{formatUrls.ts => format_urls.ts} | 0 11 files changed, 9 insertions(+), 9 deletions(-) rename tests/helpers/channels/{createChannel.ts => create_channel.ts} (100%) rename tests/helpers/channels/{deleteChannel.ts => delete_channel.ts} (100%) rename tests/helpers/members/{fetchMembers.ts => fetch_members.ts} (100%) rename tests/helpers/messages/{deleteMessage.ts => delete_message.ts} (100%) rename tests/helpers/messages/{deleteMessages.ts => delete_messages.ts} (100%) rename tests/helpers/messages/{editMessage.ts => edit_message.ts} (100%) rename tests/helpers/messages/{getMessage.ts => get_message.ts} (100%) rename tests/helpers/messages/{getMessages.ts => get_messages.ts} (100%) rename tests/helpers/messages/{sendMessage.ts => send_message.ts} (100%) rename tests/util/{formatUrls.ts => format_urls.ts} (100%) diff --git a/tests/helpers/channels/createChannel.ts b/tests/helpers/channels/create_channel.ts similarity index 100% rename from tests/helpers/channels/createChannel.ts rename to tests/helpers/channels/create_channel.ts diff --git a/tests/helpers/channels/deleteChannel.ts b/tests/helpers/channels/delete_channel.ts similarity index 100% rename from tests/helpers/channels/deleteChannel.ts rename to tests/helpers/channels/delete_channel.ts diff --git a/tests/helpers/members/fetchMembers.ts b/tests/helpers/members/fetch_members.ts similarity index 100% rename from tests/helpers/members/fetchMembers.ts rename to tests/helpers/members/fetch_members.ts diff --git a/tests/helpers/messages/deleteMessage.ts b/tests/helpers/messages/delete_message.ts similarity index 100% rename from tests/helpers/messages/deleteMessage.ts rename to tests/helpers/messages/delete_message.ts diff --git a/tests/helpers/messages/deleteMessages.ts b/tests/helpers/messages/delete_messages.ts similarity index 100% rename from tests/helpers/messages/deleteMessages.ts rename to tests/helpers/messages/delete_messages.ts diff --git a/tests/helpers/messages/editMessage.ts b/tests/helpers/messages/edit_message.ts similarity index 100% rename from tests/helpers/messages/editMessage.ts rename to tests/helpers/messages/edit_message.ts diff --git a/tests/helpers/messages/getMessage.ts b/tests/helpers/messages/get_message.ts similarity index 100% rename from tests/helpers/messages/getMessage.ts rename to tests/helpers/messages/get_message.ts diff --git a/tests/helpers/messages/getMessages.ts b/tests/helpers/messages/get_messages.ts similarity index 100% rename from tests/helpers/messages/getMessages.ts rename to tests/helpers/messages/get_messages.ts diff --git a/tests/helpers/messages/sendMessage.ts b/tests/helpers/messages/send_message.ts similarity index 100% rename from tests/helpers/messages/sendMessage.ts rename to tests/helpers/messages/send_message.ts diff --git a/tests/mod.ts b/tests/mod.ts index 22d8117dd..cfa267a35 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -8,26 +8,26 @@ import { stopBot, } from "../mod.ts"; import { assertEquals, assertExists } from "./deps.ts"; -import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts"; -import { getMessagesTest } from "./helpers/messages/getMessages.ts"; -import { deleteMessagesWithoutReasonTest, deleteMessagesWithReasonTest } from "./helpers/messages/deleteMessages.ts"; +import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/delete_message.ts"; +import { getMessagesTest } from "./helpers/messages/get_messages.ts"; +import { deleteMessagesWithoutReasonTest, deleteMessagesWithReasonTest } from "./helpers/messages/delete_messages.ts"; import { delayUntil } from "./utils.ts"; import { sendMessageWithComponents, sendMessageWithEmbedsTest, sendMessageWithTextTest, -} from "./helpers/messages/sendMessage.ts"; +} from "./helpers/messages/send_message.ts"; // CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST import "./local.ts"; -import { getMessageTest } from "./helpers/messages/getMessage.ts"; +import { getMessageTest } from "./helpers/messages/get_message.ts"; import { addReactionTest } from "./helpers/messages/reactions.ts"; -import { editMessageTest } from "./helpers/messages/editMessage.ts"; -import { fetchSingleMemberTest } from "./helpers/members/fetchMembers.ts"; +import { editMessageTest } from "./helpers/messages/edit_message.ts"; +import { fetchSingleMemberTest } from "./helpers/members/fetch_members.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"; +import { createChannelTests } from "./helpers/channels/create_channel.ts"; +import { deleteChannelTests } from "./helpers/channels/delete_channel.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS diff --git a/tests/util/formatUrls.ts b/tests/util/format_urls.ts similarity index 100% rename from tests/util/formatUrls.ts rename to tests/util/format_urls.ts From c4ddf18a0e77d9d248ecaa1b6ff3aa743b9d041a Mon Sep 17 00:00:00 2001 From: lts372005 <87189679+lts372005@users.noreply.github.com> Date: Mon, 1 Nov 2021 16:31:45 +0700 Subject: [PATCH 5/8] import format_urls.ts --- tests/local.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/local.ts b/tests/local.ts index bba4ce566..5b231a52d 100644 --- a/tests/local.ts +++ b/tests/local.ts @@ -2,3 +2,4 @@ import "./local/snowflake.ts"; import "./util/validate_length.ts"; import "./util/utils.ts"; import "./util/hash.ts"; +import "./util/format_urls.ts"; From 2176b7a072beec0f62a574f109de3c8b918cf7d0 Mon Sep 17 00:00:00 2001 From: lts372005 <87189679+lts372005@users.noreply.github.com> Date: Mon, 1 Nov 2021 16:38:13 +0700 Subject: [PATCH 6/8] fix parity with src/util/bigint.ts --- tests/{local/snowflake.ts => util/bigint.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{local/snowflake.ts => util/bigint.ts} (100%) diff --git a/tests/local/snowflake.ts b/tests/util/bigint.ts similarity index 100% rename from tests/local/snowflake.ts rename to tests/util/bigint.ts From 7f4e82eed78cff1c7638902201167d5218650d00 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Mon, 1 Nov 2021 11:10:20 +0100 Subject: [PATCH 7/8] Fix cache: implement GUILD_MEMBER_CHUNK --- src/cache.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cache.ts b/src/cache.ts index 382717697..f5a7ce2ae 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -188,6 +188,15 @@ export function createExecute(cache: Cache): CacheExecutor { return cached; }) .filter((m: DiscordenoMessage) => m); + case "GUILD_MEMBER_CHUNK": + options.users.forEach((user) => { + cache.users.set(user.id, user); + }); + // TODO: FIND A GOOD WAY FOR MEMBERS CACHE (GUILD ID) + // options.members.forEach((member) => { + // cache.members.set(member.id, member); + // }); + return; } }; } From 6bc79c60e02e10b378b608c69773079836a3843a Mon Sep 17 00:00:00 2001 From: TriForMine Date: Mon, 1 Nov 2021 10:10:58 +0000 Subject: [PATCH 8/8] change: prettier code --- src/cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache.ts b/src/cache.ts index f5a7ce2ae..f6eba8f9d 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -196,7 +196,7 @@ export function createExecute(cache: Cache): CacheExecutor { // options.members.forEach((member) => { // cache.members.set(member.id, member); // }); - return; + return; } }; }