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
+66
View File
@@ -0,0 +1,66 @@
import { Bot } from "../../../src/bot.ts";
import { Cache } from "../../../src/cache.ts";
import { assertEquals, assertExists } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
const roleChanges = new Map<bigint, bigint[]>();
export async function addRoleTest(bot: Bot<Cache>, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
const role = await bot.helpers.createRole(guildId, {
name: "hoti",
});
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));
bot.events.guildMemberUpdate = function (bot, member, user) {
roleChanges.set(user.id, member.roles);
};
await bot.helpers.addRole(guildId, bot.id, role.id, options.reason);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), true);
}
export async function removeRoleTest(
bot: Bot<Cache>,
guildId: bigint,
options: { reason?: string },
t: Deno.TestContext
) {
const role = await bot.helpers.createRole(guildId, {
name: "hoti",
});
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));
bot.events.guildMemberUpdate = function (bot, member, user) {
roleChanges.set(user.id, member.roles);
};
await bot.helpers.addRole(guildId, bot.id, role.id, options.reason);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), true);
await bot.helpers.removeRole(guildId, bot.id, role.id, options.reason);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => !roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), false);
}