add role tests

This commit is contained in:
Skillz4Killz
2021-11-02 19:32:57 +00:00
committed by GitHub
parent 484857ef05
commit 300c760480
7 changed files with 225 additions and 2 deletions
+29
View File
@@ -0,0 +1,29 @@
import { Bot } from "../../../src/bot.ts";
import { Cache } from "../../../src/cache.ts";
import { assertExists } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
export async function deleteRoleTests(
bot: Bot<Cache>,
guildId: bigint,
options: { reason?: string },
t: Deno.TestContext
) {
const role = await bot.helpers.createRole(guildId, { name: "hoti" }, options.reason);
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guildId)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guildId)?.roles.has(role.id));
await bot.helpers.deleteRole(guildId, role.id);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => !bot.cache.guilds.get(guildId)?.roles.has(role.id));
if (bot.cache.guilds.get(guildId)?.roles.has(role.id)) {
throw new Error(`The role should have been deleted but it is still in cache.`);
}
}