From 45c879496f0767ace952d164d26b5b8addc49425 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 2 Nov 2021 15:55:46 +0000 Subject: [PATCH] tests working --- benchmarks | 2 +- src/bot.ts | 2 + tests/mod.ts | 992 ++++++++++++++++++++++++++------------------------- 3 files changed, 501 insertions(+), 495 deletions(-) diff --git a/benchmarks b/benchmarks index 2065c46a1..4181287d3 160000 --- a/benchmarks +++ b/benchmarks @@ -1 +1 @@ -Subproject commit 2065c46a1c09be7470aa4807509e56cbdcf08546 +Subproject commit 4181287d35c4be42243a93a8a0c18810810c3356 diff --git a/src/bot.ts b/src/bot.ts index cb379af35..fe6448c46 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -422,6 +422,8 @@ export async function stopBot(bot: Bot) { }); await delay(5000); + + return bot; } export interface CreateBotOptions { diff --git a/tests/mod.ts b/tests/mod.ts index 1d887694c..d310ea1a6 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -41,590 +41,594 @@ import { getEmojiTest } from "./helpers/emojis/get_emoji.ts"; import { getEmojisTest } from "./helpers/emojis/get_emojis.ts"; import { getBansTest, unbanTest, banTest } from "./helpers/members/ban.ts"; -Deno.test("[Bot] - Starting Tests", async (t) => { - // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS - const sanitizeMode = { - sanitizeResources: false, - sanitizeOps: false, - sanitizeExit: false, - }; +// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS +const sanitizeMode = { + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}; - let startedAt = 0; - const bot = createBot({ - token: TOKEN || Deno.env.get("DISCORD_TOKEN"), - // token: Deno.env.get("DISCORD_TOKEN")!, - // TEST BOT - botId: 770381961553510451n, - // DD bot - // botId: 675412054529540107n, - events: createEventHandlers({ - ready: () => { - startedAt = Date.now(); +Deno.test({ + name: "[Bot] - Starting Tests", + fn: async (t) => { + let startedAt = 0; + const bot = createBot({ + token: TOKEN || Deno.env.get("DISCORD_TOKEN"), + // token: Deno.env.get("DISCORD_TOKEN")!, + // TEST BOT + botId: 770381961553510451n, + // DD bot + // botId: 675412054529540107n, + events: createEventHandlers({ + ready: () => { + startedAt = Date.now(); + }, + // debug: console.log, + }), + intents: ["Guilds", "GuildEmojis", "GuildMessages", "GuildMessageReactions", "GuildBans"], + cache: { + isAsync: false, }, - // debug: console.log, - }), - intents: ["Guilds", "GuildEmojis", "GuildMessages", "GuildMessageReactions", "GuildBans"], - cache: { - isAsync: false, - }, - }); - - await startBot(bot); - - // Delay the execution to allow READY events to be processed - await delayUntil(10000, () => Boolean(startedAt)); - console.log("Bot online"); - - // DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE - if (bot.cache.guilds.size() <= 10) { - bot.cache.guilds.forEach(async (guild) => { - if (guild.ownerId === bot.id) await bot.helpers.deleteGuild(guild.id); }); - } - // Delay the execution to allow delete guilds to be processed - await delayUntil(10000, () => Boolean(startedAt)); + await startBot(bot); - // CREATE ONE GUILD SO WE CAN REUSE LATER TO SAVE RATE LIMITS - const guild = await bot.helpers.createGuild({ name: "Discordeno Test" }); + // Delay the execution to allow READY events to be processed + await delayUntil(10000, () => Boolean(startedAt)); + console.log("Bot online"); - // Assertions - assertExists(guild); - assertExists(guild.id); + // DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE + if (bot.cache.guilds.size() <= 10) { + bot.cache.guilds.forEach(async (guild) => { + if (guild.ownerId === bot.id) await bot.helpers.deleteGuild(guild.id); + }); + } - // Delay the execution to allow GUILD_CREATE event to be processed - await delayUntil(10000, () => bot.cache.guilds.has(guild.id)); + // Delay the execution to allow delete guilds to be processed + await delayUntil(10000, () => Boolean(startedAt)); - // FINAL CHECK TO THROW IF MISSING STILL - if (!bot.cache.guilds.has(guild.id)) { - throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`); - } - - await Promise.all([ - t.step({ - name: "[guild] format a guild's icon url", - fn: async (t) => { - assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined); - assertEquals( - bot.helpers.guildIconURL(785384884197392384n, { - icon: 3837424427068676005442449262648382018748n, - }), - "https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" - ); - }, - ...sanitizeMode, - }), - t.step({ - name: "[guild] format a guild's banner url", - fn: async (t) => { - assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined); - assertEquals( - bot.helpers.guildBannerURL(613425648685547541n, { - banner: 3919584870146358272366452115178209474142n, - }), - "https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128" - ); - }, - ...sanitizeMode, - }), - t.step({ - name: "[guild] format a guild's splash url", - fn: async (t) => { - assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined); - assertEquals( - bot.helpers.guildSplashURL(785384884197392384n, { - splash: 3837424427068676005442449262648382018748n, - }), - "https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" - ); - }, - ...sanitizeMode, - }), - ]); - - // CHANNEL TESTS GROUPED - await t.step("Channel related tests", async (t) => { - const channel = await bot.helpers.createChannel(guild.id, { name: "Discordeno-test" }); + // CREATE ONE GUILD SO WE CAN REUSE LATER TO SAVE RATE LIMITS + const guild = await bot.helpers.createGuild({ name: "Discordeno Test" }); // Assertions - assertExists(channel); - assertEquals(channel.type, DiscordChannelTypes.GuildText); + assertExists(guild); + assertExists(guild.id); - // ALL MESSAGE RELATED TESTS THAT DEPEND ON AN EXISTING CHANNEL - await t.step("Message related tests", async (t) => { - const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz"); + // Delay the execution to allow GUILD_CREATE event to be processed + await delayUntil(10000, () => bot.cache.guilds.has(guild.id)); - // CONDUCT ALL TESTS RELATED TO A MESSAGE HERE + // FINAL CHECK TO THROW IF MISSING STILL + if (!bot.cache.guilds.has(guild.id)) { + throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`); + } + + await Promise.all([ + t.step({ + name: "[guild] format a guild's icon url", + fn: async (t) => { + assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined); + assertEquals( + bot.helpers.guildIconURL(785384884197392384n, { + icon: 3837424427068676005442449262648382018748n, + }), + "https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" + ); + }, + ...sanitizeMode, + }), + t.step({ + name: "[guild] format a guild's banner url", + fn: async (t) => { + assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined); + assertEquals( + bot.helpers.guildBannerURL(613425648685547541n, { + banner: 3919584870146358272366452115178209474142n, + }), + "https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128" + ); + }, + ...sanitizeMode, + }), + t.step({ + name: "[guild] format a guild's splash url", + fn: async (t) => { + assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined); + assertEquals( + bot.helpers.guildSplashURL(785384884197392384n, { + splash: 3837424427068676005442449262648382018748n, + }), + "https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128" + ); + }, + ...sanitizeMode, + }), + ]); + + // CHANNEL TESTS GROUPED + await t.step("Channel related tests", async (t) => { + const channel = await bot.helpers.createChannel(guild.id, { name: "Discordeno-test" }); + + // Assertions + assertExists(channel); + assertEquals(channel.type, DiscordChannelTypes.GuildText); + + // ALL MESSAGE RELATED TESTS THAT DEPEND ON AN EXISTING CHANNEL + await t.step("Message related tests", async (t) => { + const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz"); + + // CONDUCT ALL TESTS RELATED TO A MESSAGE HERE + await Promise.all([ + t.step({ + name: "[message] send message with text", + fn: async (t) => { + await sendMessageWithTextTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] send message with embeds", + fn: async (t) => { + await sendMessageWithEmbedsTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] send message with components", + fn: async (t) => { + await sendMessageWithComponents(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] edit message", + fn: async (t) => { + await editMessageTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] delete message without a reason", + fn: async (t) => { + await deleteMessageWithoutReasonTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] delete message with a reason", + fn: async (t) => { + await deleteMessageWithReasonTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] delete messages without a reason", + fn: async (t) => { + await deleteMessagesWithoutReasonTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] delete messages with a reason", + fn: async (t) => { + await deleteMessagesWithReasonTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] fetch a message", + fn: async (t) => { + await getMessageTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] fetch messages", + fn: async (t) => { + await getMessagesTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add a reaction", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add a custom reaction", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple reactions", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple custom reactions", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple reactions in order", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple custom reactions in order", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] remove a reaction.", + fn: async (t) => { + await removeReactionTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] remove all reactions.", + fn: async (t) => { + await removeAllReactionTests(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] remove emoji reactions.", + fn: async (t) => { + await removeReactionEmojiTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] pin a message", + fn: async (t) => { + await pinMessageTests(bot, channel.id, message.id, t); + }, + ...sanitizeMode, + }), + ]); + }); + + // ALL CHANNEL RELATED TESTS CAN GO HERE await Promise.all([ t.step({ - name: "[message] send message with text", + name: "[channel] send message with text", fn: async (t) => { await sendMessageWithTextTest(bot, channel.id, t); }, ...sanitizeMode, }), t.step({ - name: "[message] send message with embeds", - fn: async (t) => { - await sendMessageWithEmbedsTest(bot, channel.id, t); + name: "[channel] create a new text channel", + async fn() { + await createChannelTests(bot, guild.id, { name: "Discordeno-test" }, t); }, ...sanitizeMode, }), t.step({ - name: "[message] send message with components", - fn: async (t) => { - await sendMessageWithComponents(bot, channel.id, t); + name: "[channel] create a new category channel", + async fn() { + await createChannelTests( + bot, + guild.id, + { + name: "Discordeno-test", + type: DiscordChannelTypes.GuildCategory, + }, + t + ); + }, + ...sanitizeMode, + }), + // t.step({ + // name: "[channel] create a new news channel", + // async fn() { + // await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_NEWS}, t); + // }, + // ...sanitizeMode, + // }), + + // t.step({ + // name: "[channel] create a new store channel", + // async fn() { + // await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_STORE}, t); + // }, + // ...sanitizeMode, + // }), + t.step({ + name: "[channel] create a new voice channel", + async fn() { + await createChannelTests( + bot, + guild.id, + { + name: "Discordeno-test", + type: DiscordChannelTypes.GuildVoice, + }, + t + ); }, ...sanitizeMode, }), t.step({ - name: "[message] edit message", - fn: async (t) => { - await editMessageTest(bot, channel.id, t); + name: "[channel] create a new voice channel with a bitrate", + async fn() { + await createChannelTests( + bot, + guild.id, + { + name: "discordeno-test", + type: DiscordChannelTypes.GuildVoice, + bitrate: 32000, + }, + t + ); }, ...sanitizeMode, }), t.step({ - name: "[message] delete message without a reason", - fn: async (t) => { - await deleteMessageWithoutReasonTest(bot, channel.id, t); + name: "[channel] create a new voice channel with a user limit", + async fn() { + await createChannelTests( + bot, + guild.id, + { + name: "Discordeno-test", + type: DiscordChannelTypes.GuildVoice, + userLimit: 32, + }, + t + ); }, ...sanitizeMode, }), t.step({ - name: "[message] delete message with a reason", - fn: async (t) => { - await deleteMessageWithReasonTest(bot, channel.id, t); + name: "[channel] create a new text channel with a rate limit per user", + async fn() { + await createChannelTests( + bot, + guild.id, + { + name: "Discordeno-test", + rateLimitPerUser: 2423, + }, + t + ); }, ...sanitizeMode, }), t.step({ - name: "[message] delete messages without a reason", - fn: async (t) => { - await deleteMessagesWithoutReasonTest(bot, channel.id, t); + name: "[channel] create a new text channel with NSFW", + async fn() { + await createChannelTests(bot, guild.id, { name: "Discordeno-test", nsfw: true }, t); }, ...sanitizeMode, }), t.step({ - name: "[message] delete messages with a reason", - fn: async (t) => { - await deleteMessagesWithReasonTest(bot, channel.id, t); + name: "[channel] create a new text channel with permission overwrites", + async fn() { + await createChannelTests( + bot, + guild.id, + { + name: "Discordeno-test", + permissionOverwrites: [ + { + id: bot.id, + type: DiscordOverwriteTypes.Member, + allow: ["VIEW_CHANNEL"], + deny: [], + }, + ], + }, + t + ); }, ...sanitizeMode, }), t.step({ - name: "[message] fetch a message", - fn: async (t) => { - await getMessageTest(bot, channel.id, t); + name: "[channel] delete a channel with a reason", + async fn() { + await deleteChannelTests( + bot, + guild.id, + { + reason: "with a reason", + }, + t + ); }, ...sanitizeMode, }), t.step({ - name: "[message] fetch messages", - fn: async (t) => { - await getMessagesTest(bot, channel.id, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] add a reaction", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] add a custom reaction", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] add multiple reactions", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] add multiple custom reactions", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] add multiple reactions in order", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] add multiple custom reactions in order", - fn: async (t) => { - await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] remove a reaction.", - fn: async (t) => { - await removeReactionTest(bot, channel.id, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] remove all reactions.", - fn: async (t) => { - await removeAllReactionTests(bot, channel.id, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] remove emoji reactions.", - fn: async (t) => { - await removeReactionEmojiTest(bot, channel.id, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[message] pin a message", - fn: async (t) => { - await pinMessageTests(bot, channel.id, message.id, t); + name: "[channel] delete a channel without a reason", + async fn() { + await deleteChannelTests(bot, guild.id, {}, t); }, ...sanitizeMode, }), ]); + + // ALL TEST RELATED TO INVITES + await t.step("Invites related tests", async (t) => { + await Promise.all([ + t.step({ + name: "[invite] create an invite", + async fn() { + await createInviteTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] delete an invite", + async fn() { + await deleteInviteTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] get channels invites", + async fn() { + await getChannelInvitesTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] get invite", + async fn() { + await getInviteTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] get invites", + async fn() { + await getInvitesTest(bot, channel.id, guild.id, t); + }, + ...sanitizeMode, + }), + ]); + }); }); - // ALL CHANNEL RELATED TESTS CAN GO HERE - await Promise.all([ - t.step({ - name: "[channel] send message with text", + // MEMBER TESTS GROUPED + await t.step("Members related tests", async (t) => { + // THESE BAN TESTS SHOULD BE DONE ONE BY ONE + await t.step({ + name: "[member] ban user from guild without reason", fn: async (t) => { - await sendMessageWithTextTest(bot, channel.id, t); + // THIS IS WOLF, IF ANYTHING BREAKS BLAME HIM! + await banTest(bot, t, guild.id, 270273690074087427n, { reason: "Blame Wolf" }); }, ...sanitizeMode, - }), - t.step({ - name: "[channel] create a new text channel", - async fn() { - await createChannelTests(bot, guild.id, { name: "Discordeno-test" }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[channel] create a new category channel", - async fn() { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - type: DiscordChannelTypes.GuildCategory, - }, - t - ); - }, - ...sanitizeMode, - }), - // t.step({ - // name: "[channel] create a new news channel", - // async fn() { - // await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_NEWS}, t); - // }, - // ...sanitizeMode, - // }), + }); - // t.step({ - // name: "[channel] create a new store channel", - // async fn() { - // await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_STORE}, t); - // }, - // ...sanitizeMode, - // }), - t.step({ - name: "[channel] create a new voice channel", - async fn() { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - type: DiscordChannelTypes.GuildVoice, - }, - t - ); + await t.step({ + name: "[member] get a single user's ban", + fn: async (t) => { + assertExists(await bot.helpers.getBan(guild.id, 270273690074087427n)); }, ...sanitizeMode, - }), - t.step({ - name: "[channel] create a new voice channel with a bitrate", - async fn() { - await createChannelTests( - bot, - guild.id, - { - name: "discordeno-test", - type: DiscordChannelTypes.GuildVoice, - bitrate: 32000, - }, - t - ); + }); + + await t.step({ + name: "[member] ban member from guild without reason", + fn: async (t) => { + // THIS IS IAN, HE PLAY'S GOLDEN SUN. BAN BEFORE HE MAKES US ADDICTED TO IT!!! + await banTest(bot, t, guild.id, 90339695967350784n); }, ...sanitizeMode, - }), - t.step({ - name: "[channel] create a new voice channel with a user limit", - async fn() { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - type: DiscordChannelTypes.GuildVoice, - userLimit: 32, - }, - t - ); + }); + await t.step({ + name: "[member] get bans on a server", + fn: async (t) => { + await getBansTest(bot, t, guild.id); }, ...sanitizeMode, - }), - t.step({ - name: "[channel] create a new text channel with a rate limit per user", - async fn() { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - rateLimitPerUser: 2423, - }, - t - ); - }, - ...sanitizeMode, - }), - t.step({ - name: "[channel] create a new text channel with NSFW", - async fn() { - await createChannelTests(bot, guild.id, { name: "Discordeno-test", nsfw: true }, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[channel] create a new text channel with permission overwrites", - async fn() { - await createChannelTests( - bot, - guild.id, - { - name: "Discordeno-test", - permissionOverwrites: [ - { - id: bot.id, - type: DiscordOverwriteTypes.Member, - allow: ["VIEW_CHANNEL"], - deny: [], - }, - ], - }, - t - ); - }, - ...sanitizeMode, - }), - t.step({ - name: "[channel] delete a channel with a reason", - async fn() { - await deleteChannelTests( - bot, - guild.id, - { - reason: "with a reason", - }, - t - ); - }, - ...sanitizeMode, - }), - t.step({ - name: "[channel] delete a channel without a reason", - async fn() { - await deleteChannelTests(bot, guild.id, {}, t); - }, - ...sanitizeMode, - }), - ]); + }); - // ALL TEST RELATED TO INVITES - await t.step("Invites related tests", async (t) => { await Promise.all([ t.step({ - name: "[invite] create an invite", - async fn() { - await createInviteTest(bot, channel.id, t); + name: "[member] fetch a single member by id", + fn: async (t) => { + await fetchSingleMemberTest(bot, guild.id, t); }, ...sanitizeMode, }), t.step({ - name: "[invite] delete an invite", - async fn() { - await deleteInviteTest(bot, channel.id, t); + name: "[member] format a members avatar url", + fn: async (t) => { + assertEquals( + bot.helpers.avatarURL(130136895395987456n, 8840, { + avatar: 4055337350987360625717955448021200177333n, + }), + "https://cdn.discordapp.com/avatars/130136895395987456/eae5905ad2d18d7c8deca20478b088b5.jpg?size=128" + ); }, ...sanitizeMode, }), t.step({ - name: "[invite] get channels invites", - async fn() { - await getChannelInvitesTest(bot, channel.id, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[invite] get invite", - async fn() { - await getInviteTest(bot, channel.id, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[invite] get invites", - async fn() { - await getInvitesTest(bot, channel.id, guild.id, t); + name: "[member] unban member from guild", + fn: async (t) => { + await Promise.all([ + unbanTest(bot, t, guild.id, 270273690074087427n), + unbanTest(bot, t, guild.id, 90339695967350784n), + ]); }, ...sanitizeMode, }), ]); }); - }); - // MEMBER TESTS GROUPED - await t.step("Members related tests", async (t) => { - // THESE BAN TESTS SHOULD BE DONE ONE BY ONE - await t.step({ - name: "[member] ban user from guild without reason", - fn: async (t) => { - // THIS IS WOLF, IF ANYTHING BREAKS BLAME HIM! - await banTest(bot, t, guild.id, 270273690074087427n, { reason: "Blame Wolf" }); - }, - ...sanitizeMode, + // 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, + }), + ]); }); + // CONDUCT MEMORY BENCHMARK TESTS await t.step({ - name: "[member] get a single user's ban", + name: "[Memory] Benchmark memory tests", fn: async (t) => { - assertExists(await bot.helpers.getBan(guild.id, 270273690074087427n)); + await memoryBenchmarks(bot, true); }, - ...sanitizeMode, }); - await t.step({ - name: "[member] ban member from guild without reason", - fn: async (t) => { - // THIS IS IAN, HE PLAY'S GOLDEN SUN. BAN BEFORE HE MAKES US ADDICTED TO IT!!! - await banTest(bot, t, guild.id, 90339695967350784n); - }, - ...sanitizeMode, - }); - await t.step({ - name: "[member] get bans on a server", - fn: async (t) => { - await getBansTest(bot, t, guild.id); - }, - ...sanitizeMode, - }); - - await Promise.all([ - t.step({ - name: "[member] fetch a single member by id", - fn: async (t) => { - await fetchSingleMemberTest(bot, guild.id, t); - }, - ...sanitizeMode, - }), - t.step({ - name: "[member] format a members avatar url", - fn: async (t) => { - assertEquals( - bot.helpers.avatarURL(130136895395987456n, 8840, { - avatar: 4055337350987360625717955448021200177333n, - }), - "https://cdn.discordapp.com/avatars/130136895395987456/eae5905ad2d18d7c8deca20478b088b5.jpg?size=128" - ); - }, - ...sanitizeMode, - }), - t.step({ - name: "[member] unban member from guild", - fn: async (t) => { - await Promise.all([ - unbanTest(bot, t, guild.id, 270273690074087427n), - unbanTest(bot, t, guild.id, 90339695967350784n), - ]); - }, - ...sanitizeMode, - }), - ]); - }); - - // 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, - }), - ]); - }); - - // CONDUCT MEMORY BENCHMARK TESTS - await t.step({ - name: "[Memory] Benchmark memory tests", - fn: async (t) => { - await memoryBenchmarks(bot, true); - }, - }); - - await stopBot(bot); + await stopBot(bot); + }, + ...sanitizeMode, });