From 3e4e41067dc84ceb3761230a05ceeff90c88009a Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Fri, 27 May 2022 18:11:25 +0000 Subject: [PATCH] fix: rate limited unit tests from createBot async --- testss/channels/createCategory.test.ts | 2 +- testss/channels/createNews.test.ts | 7 ++++++- testss/channels/createText.test.ts | 2 +- testss/channels/createTextWithNsfw.test.ts | 2 +- testss/channels/createTextWithPerms.test.ts | 2 +- .../channels/createTextWithRateLimit.test.ts | 2 +- testss/channels/createVoice.test.ts | 2 +- testss/channels/createVoiceWithBitrate.test.ts | 2 +- .../channels/createVoiceWithUserLimit.test.ts | 2 +- testss/channels/deleteWithReason.test.ts | 2 +- testss/channels/deleteWithoutReason.test.ts | 2 +- testss/channels/getChannel.test.ts | 2 +- testss/channels/getChannels.test.ts | 2 +- testss/channels/stageInstances.test.ts | 2 +- testss/channels/threads/deleteThread.test.ts | 2 +- testss/channels/threads/editThread.test.ts | 2 +- .../channels/threads/getActiveThreads.test.ts | 2 +- .../threads/getArchivedThreads.test.ts | 2 +- .../threads/joinAndLeaveThread.test.ts | 2 +- testss/channels/threads/startThread.test.ts | 2 +- testss/mod.ts | 18 ++++++++++++------ 21 files changed, 37 insertions(+), 26 deletions(-) diff --git a/testss/channels/createCategory.test.ts b/testss/channels/createCategory.test.ts index d12894cee..0f356875e 100644 --- a/testss/channels/createCategory.test.ts +++ b/testss/channels/createCategory.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new category channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test", type: ChannelTypes.GuildCategory, diff --git a/testss/channels/createNews.test.ts b/testss/channels/createNews.test.ts index bccd5192a..1b086dc03 100644 --- a/testss/channels/createNews.test.ts +++ b/testss/channels/createNews.test.ts @@ -6,11 +6,14 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new news channel", async fn(t) { - const bot = loadBot(); + 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); @@ -22,7 +25,9 @@ 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/channels/createText.test.ts b/testss/channels/createText.test.ts index 127692470..242eb4027 100644 --- a/testss/channels/createText.test.ts +++ b/testss/channels/createText.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test" }); // Assertions diff --git a/testss/channels/createTextWithNsfw.test.ts b/testss/channels/createTextWithNsfw.test.ts index 352d8fe08..f27d3ebc4 100644 --- a/testss/channels/createTextWithNsfw.test.ts +++ b/testss/channels/createTextWithNsfw.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel with NSFW", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", nsfw: true, diff --git a/testss/channels/createTextWithPerms.test.ts b/testss/channels/createTextWithPerms.test.ts index ee1b96b5e..d9e5df961 100644 --- a/testss/channels/createTextWithPerms.test.ts +++ b/testss/channels/createTextWithPerms.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel with permission overwrites", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", permissionOverwrites: [ diff --git a/testss/channels/createTextWithRateLimit.test.ts b/testss/channels/createTextWithRateLimit.test.ts index 597f66167..002c42131 100644 --- a/testss/channels/createTextWithRateLimit.test.ts +++ b/testss/channels/createTextWithRateLimit.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel with a rate limit per user", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", rateLimitPerUser: 2423, diff --git a/testss/channels/createVoice.test.ts b/testss/channels/createVoice.test.ts index 10ab285fc..84f3854c6 100644 --- a/testss/channels/createVoice.test.ts +++ b/testss/channels/createVoice.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new voice channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test", type: ChannelTypes.GuildVoice, diff --git a/testss/channels/createVoiceWithBitrate.test.ts b/testss/channels/createVoiceWithBitrate.test.ts index da1764350..141909268 100644 --- a/testss/channels/createVoiceWithBitrate.test.ts +++ b/testss/channels/createVoiceWithBitrate.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new voice channel with a bitrate", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", type: ChannelTypes.GuildVoice, diff --git a/testss/channels/createVoiceWithUserLimit.test.ts b/testss/channels/createVoiceWithUserLimit.test.ts index fdc63c331..9936c9906 100644 --- a/testss/channels/createVoiceWithUserLimit.test.ts +++ b/testss/channels/createVoiceWithUserLimit.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new voice channel with a user limit", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", type: ChannelTypes.GuildVoice, diff --git a/testss/channels/deleteWithReason.test.ts b/testss/channels/deleteWithReason.test.ts index 8f56ced12..48f6a938a 100644 --- a/testss/channels/deleteWithReason.test.ts +++ b/testss/channels/deleteWithReason.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] delete a channel with a reason", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "delete-channel", }); diff --git a/testss/channels/deleteWithoutReason.test.ts b/testss/channels/deleteWithoutReason.test.ts index 9295dfa4b..9b5acdd7c 100644 --- a/testss/channels/deleteWithoutReason.test.ts +++ b/testss/channels/deleteWithoutReason.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] delete a channel without a reason", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); // Create a channel to delete const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "delete-channel", diff --git a/testss/channels/getChannel.test.ts b/testss/channels/getChannel.test.ts index 650e981f2..c59796528 100644 --- a/testss/channels/getChannel.test.ts +++ b/testss/channels/getChannel.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] Get a channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "fetching", }); diff --git a/testss/channels/getChannels.test.ts b/testss/channels/getChannels.test.ts index a097ec47d..c78430259 100644 --- a/testss/channels/getChannels.test.ts +++ b/testss/channels/getChannels.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] Get all channels", async fn() { - const bot = loadBot(); + const bot = await loadBot(); const [first, second] = await Promise.all([ bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "first" }), bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "second" }), diff --git a/testss/channels/stageInstances.test.ts b/testss/channels/stageInstances.test.ts index b0980ce9e..ddecdb2a3 100644 --- a/testss/channels/stageInstances.test.ts +++ b/testss/channels/stageInstances.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[stage] Create a stage instance", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const stage = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "createinstance", type: ChannelTypes.GuildStageVoice, diff --git a/testss/channels/threads/deleteThread.test.ts b/testss/channels/threads/deleteThread.test.ts index e87552afc..6f7b92e2b 100644 --- a/testss/channels/threads/deleteThread.test.ts +++ b/testss/channels/threads/deleteThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Delete a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/editThread.test.ts b/testss/channels/threads/editThread.test.ts index 1db1d4155..ea8eecd57 100644 --- a/testss/channels/threads/editThread.test.ts +++ b/testss/channels/threads/editThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Edit and archive a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/getActiveThreads.test.ts b/testss/channels/threads/getActiveThreads.test.ts index 4eff80b45..501463f97 100644 --- a/testss/channels/threads/getActiveThreads.test.ts +++ b/testss/channels/threads/getActiveThreads.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Get active threads", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/getArchivedThreads.test.ts b/testss/channels/threads/getArchivedThreads.test.ts index e4af2396b..4a085e0de 100644 --- a/testss/channels/threads/getArchivedThreads.test.ts +++ b/testss/channels/threads/getArchivedThreads.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Get archived threads", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/joinAndLeaveThread.test.ts b/testss/channels/threads/joinAndLeaveThread.test.ts index 9c7acace7..c22f840ce 100644 --- a/testss/channels/threads/joinAndLeaveThread.test.ts +++ b/testss/channels/threads/joinAndLeaveThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] join and leave a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/startThread.test.ts b/testss/channels/threads/startThread.test.ts index fa32babd3..44f016afb 100644 --- a/testss/channels/threads/startThread.test.ts +++ b/testss/channels/threads/startThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Start a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/mod.ts b/testss/mod.ts index 6b7a87eff..01a6d037c 100644 --- a/testss/mod.ts +++ b/testss/mod.ts @@ -3,16 +3,22 @@ import { dotenv } from "./deps.ts"; dotenv({ export: true, path: `${Deno.cwd()}/.env` }); -export function loadBot() { +export async function loadBot() { const token = Deno.env.get("DISCORD_TOKEN"); if (!token) throw new Error("Token was not provided."); - const botId = BigInt(atob(token.split(".")[0])); - const bot = createBot({ - events: {}, - intents: 0, - botId, + const bot = await createBot({ token, + botGatewayData: { + url: "wss://gateway.discord.gg", + shards: 1, + sessionStartLimit: { + maxConcurrency: 1, + remaining: 1000, + resetAfter: Date.now() + 1000 * 60 * 60 * 24, + total: 1000, + }, + }, }); bot.rest = createRestManager({