diff --git a/tests/emoji/createEmoji.ts b/tests/emoji/createEmoji.ts deleted file mode 100644 index 595fb4140..000000000 --- a/tests/emoji/createEmoji.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] create an emoji", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - 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 () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } - }, -}); diff --git a/tests/emoji/deleteEmojiWithReason.ts b/tests/emoji/deleteEmojiWithReason.ts deleted file mode 100644 index b54549541..000000000 --- a/tests/emoji/deleteEmojiWithReason.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] delete an emoji without a reason", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - 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 () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } - - await bot.helpers.deleteEmoji(guild.id, emoji.id, "with a reason"); - - await delayUntil(10000, async () => !bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be deleted but it's still cached."); - } - }, -}); diff --git a/tests/emoji/deleteEmojiWithoutReason.ts b/tests/emoji/deleteEmojiWithoutReason.ts deleted file mode 100644 index 341ff180a..000000000 --- a/tests/emoji/deleteEmojiWithoutReason.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] delete an emoji without a reason", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - 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 () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } - - await bot.helpers.deleteEmoji(guild.id, emoji.id); - - await delayUntil(10000, async () => !bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be deleted but it's still cached."); - } - }, -}); diff --git a/tests/emoji/editEmoji.ts b/tests/emoji/editEmoji.ts deleted file mode 100644 index 0351e5dad..000000000 --- a/tests/emoji/editEmoji.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] edit an emoji", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - 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 () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } - - await bot.helpers.editEmoji(guild.id, emoji.id, { - name: "blamewolf_infinite", - }); - - await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.get(emoji.id)?.name === "blamewolf_infinite"); - - if (bot.guilds.get(guild.id)?.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/emoji/emojiUrl.ts b/tests/emoji/emojiUrl.ts deleted file mode 100644 index 41df85330..000000000 --- a/tests/emoji/emojiUrl.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { assertEquals } from "../deps.ts"; -import { bot } from "../mod.ts"; - -Deno.test("[emoji] Create an emoji url", async () => { - assertEquals( - bot.helpers.emojiUrl(785403373817823272n, false), - "https://cdn.discordapp.com/emojis/785403373817823272.png", - ); - assertEquals( - bot.helpers.emojiUrl(785403373817823272n, true), - "https://cdn.discordapp.com/emojis/785403373817823272.gif", - ); -}); diff --git a/tests/emoji/getEmoji.ts b/tests/emoji/getEmoji.ts deleted file mode 100644 index 856fb05ae..000000000 --- a/tests/emoji/getEmoji.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] get an emoji", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - 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 () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } - - bot.guilds.get(guild.id)?.emojis?.delete(emoji.id); - - const getEmoji = await bot.helpers.getEmoji(guild.id, emoji.id); - - // Assertions - assertExists(getEmoji); - }, -}); diff --git a/tests/emoji/getMultipleEmojis.ts b/tests/emoji/getMultipleEmojis.ts deleted file mode 100644 index 14d8baefd..000000000 --- a/tests/emoji/getMultipleEmojis.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] get multiple emojis", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - 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 () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id)); - - if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) { - throw new Error("The emoji seemed to be created but it was not cached."); - } - - const emojis = await bot.helpers.getEmojis(guild.id); - - if (emojis.size === 0) { - throw new Error("The getEmojis function returned 0 emojis."); - } - }, -}); diff --git a/testss/channels/createNews.test.ts b/testss/channels/createNews.test.ts index 1b086dc03..f10cbda36 100644 --- a/testss/channels/createNews.test.ts +++ b/testss/channels/createNews.test.ts @@ -6,14 +6,11 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new news channel", async fn(t) { - console.log("news", 1); const bot = await loadBot(); - console.log("news", 2); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test", type: ChannelTypes.GuildNews, }); - console.log("news", 3); // Assertions assertExists(channel); @@ -25,9 +22,7 @@ Deno.test({ assertEquals(channel.nsfw, false); assertEquals(channel.permissionOverwrites.length, 0); - console.log("news", 4); // Delete the channel once test is done await bot.helpers.deleteChannel(channel.id); - console.log("news", 5); }, }); diff --git a/testss/emojis/createEmoji.test.ts b/testss/emojis/createEmoji.test.ts new file mode 100644 index 000000000..e77bd376b --- /dev/null +++ b/testss/emojis/createEmoji.test.ts @@ -0,0 +1,20 @@ +import { assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] create an emoji", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + }, +}); diff --git a/testss/emojis/deleteEmojiWithReason.test.ts b/testss/emojis/deleteEmojiWithReason.test.ts new file mode 100644 index 000000000..ce49c25f2 --- /dev/null +++ b/testss/emojis/deleteEmojiWithReason.test.ts @@ -0,0 +1,23 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] delete an emoji with a reason", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, "with a reason"); + + const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + assertEquals(exists.id, undefined); + }, +}); diff --git a/testss/emojis/deleteEmojiWithoutReason.test.ts b/testss/emojis/deleteEmojiWithoutReason.test.ts new file mode 100644 index 000000000..df70aa168 --- /dev/null +++ b/testss/emojis/deleteEmojiWithoutReason.test.ts @@ -0,0 +1,23 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] delete an emoji without a reason", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + + const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + assertEquals(exists.id, undefined); + }, +}); diff --git a/testss/emojis/editEmojiName.test.ts b/testss/emojis/editEmojiName.test.ts new file mode 100644 index 000000000..024b5a8a1 --- /dev/null +++ b/testss/emojis/editEmojiName.test.ts @@ -0,0 +1,29 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] Edit an emoji name", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + assertEquals(emoji.name, "blamewolf"); + + await bot.helpers.editEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, { + name: "edited", + }); + + const edited = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + + assertEquals(edited.name, "edited"); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + }, +}); diff --git a/testss/emojis/editEmojiRoles.test.ts b/testss/emojis/editEmojiRoles.test.ts new file mode 100644 index 000000000..ed30fcefd --- /dev/null +++ b/testss/emojis/editEmojiRoles.test.ts @@ -0,0 +1,33 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] Edit an emoji's roles", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + assertEquals(emoji.name, "blamewolf"); + + const role = await bot.helpers.createRole(CACHED_COMMUNITY_GUILD_ID, { + name: "dd-test-emoji", + }); + await bot.helpers.editEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, { + roles: [role.id], + }); + + const edited = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + + assertEquals(edited.roles?.length, 1); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + await bot.helpers.deleteRole(CACHED_COMMUNITY_GUILD_ID, role.id); + }, +}); diff --git a/testss/emojis/getEmoji.test.ts b/testss/emojis/getEmoji.test.ts new file mode 100644 index 000000000..817f7f566 --- /dev/null +++ b/testss/emojis/getEmoji.test.ts @@ -0,0 +1,24 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] get an emoji", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + assertExists(exists.id); + assertEquals(emoji.id, exists.id) + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + }, +}); diff --git a/testss/emojis/getEmojis.test.ts b/testss/emojis/getEmojis.test.ts new file mode 100644 index 000000000..badf7bb4c --- /dev/null +++ b/testss/emojis/getEmojis.test.ts @@ -0,0 +1,31 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] get all guild emojis", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + const emoji2 = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf2", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + assertExists(emoji2.id); + + const exists = await bot.helpers.getEmojis(CACHED_COMMUNITY_GUILD_ID); + assertEquals(exists.size > 1, true); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji2.id); + }, +}); diff --git a/testss/utils.test.ts b/testss/utils.test.ts index 87afcf46d..03040e043 100644 --- a/testss/utils.test.ts +++ b/testss/utils.test.ts @@ -2,6 +2,7 @@ import { formatImageURL, iconBigintToHash, iconHashToBigInt, validateLength } fr import { bigintToSnowflake, snowflakeToBigint } from "../util/bigint.ts"; import { removeTokenPrefix } from "../util/token.ts"; import { assertEquals, assertNotEquals } from "./deps.ts"; +import { loadBot } from "./mod.ts"; Deno.test({ name: "[token] Remove token prefix when Bot is prefixed.", @@ -35,6 +36,18 @@ Deno.test("[bigint] - Transform a bigint to a string", () => { assertNotEquals(big, result); }); +Deno.test("[emoji] Create an emoji url", async () => { + const bot = await loadBot(); + assertEquals( + bot.helpers.emojiUrl(785403373817823272n, false), + "https://cdn.discordapp.com/emojis/785403373817823272.png", + ); + assertEquals( + bot.helpers.emojiUrl(785403373817823272n, true), + "https://cdn.discordapp.com/emojis/785403373817823272.gif", + ); +}); + Deno.test({ name: "[utils] format image url", fn() {