Merge branch 'fp-attempt-9001' into unit-tests-invites

This commit is contained in:
Skillz4Killz
2021-11-01 08:45:25 -04:00
committed by GitHub
19 changed files with 227 additions and 10 deletions
+9
View File
@@ -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;
}
};
}
+21
View File
@@ -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.");
}
}
+37
View File
@@ -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");
}
+34
View File
@@ -0,0 +1,34 @@
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.");
}
}
+35
View File
@@ -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.");
}
}
+27
View File
@@ -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.");
}
}
+1
View File
@@ -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";
+63 -10
View File
@@ -8,31 +8,36 @@ 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 { createInviteTest } from "./helpers/invites/create_invite.ts";
import { deleteInviteTest } from "./helpers/invites/delete_invite.ts";
import { getChannelInvitesTest } from "./helpers/invites/get_channels_invites.ts";
import { getInviteTest } from "./helpers/invites/get_invite.ts";
import { getInvitesTest } from "./helpers/invites/get_invites.ts";
import { createChannelTests } from "./helpers/channels/create_channel.ts";
import { deleteChannelTests } from "./helpers/channels/delete_channel.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
@@ -56,7 +61,7 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
},
// debug: console.log,
}),
intents: ["Guilds", "GuildMessages", "GuildMessageReactions"],
intents: ["Guilds", "GuildEmojis", "GuildMessages", "GuildMessageReactions"],
cache: {
isAsync: false,
},
@@ -519,5 +524,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);
});