Files
discordeno/tests/helpers/roles/roleChanges.ts
2022-02-11 09:49:53 +00:00

32 lines
1.1 KiB
TypeScript

import { Bot } from "../../../bot.ts";
import { assertEquals, assertExists } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
const roleChanges = new Map<bigint, bigint[]>();
export async function addRoleTest(bot: Bot, 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.guilds.get(guildId)?.roles.has(role.id));
assertExists(bot.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, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {}