fix(tests): migrate emoji related unit tests

This commit is contained in:
Skillz4Killz
2022-05-27 18:44:49 +00:00
committed by ITOH
parent 19ff286a6d
commit 10dff1ca50
16 changed files with 196 additions and 201 deletions

View File

@@ -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.");
}
},
});

View File

@@ -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.");
}
},
});

View File

@@ -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.");
}
},
});

View File

@@ -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.");
}
},
});

View File

@@ -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",
);
});

View File

@@ -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);
},
});

View File

@@ -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.");
}
},
});

View File

@@ -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);
},
});

View File

@@ -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);
},
});

View File

@@ -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);
},
});

View File

@@ -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);
},
});

View File

@@ -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);
},
});

View File

@@ -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);
},
});

View File

@@ -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);
},
});

View File

@@ -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);
},
});

View File

@@ -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() {