Files
discordeno/tests/role/removeRole.ts
2021-11-22 16:34:30 +00:00

39 lines
1.3 KiB
TypeScript

import { roleChanges } from "../constants.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] remove a role to a member",
fn: async (t) => {
const role = await bot.helpers.createRole(guild.id, {
name: "hoti",
});
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
bot.events.guildMemberUpdate = function (bot, member, user) {
roleChanges.set(user.id, member.roles);
};
await bot.helpers.addRole(guild.id, bot.id, role.id, "Blame wolfy");
// 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(guild.id, bot.id, role.id, "Blame wolfy");
// 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);
},
});