fix invite and ban tests

This commit is contained in:
Skillz4Killz
2021-11-02 03:00:06 +00:00
committed by GitHub
parent e02e8fa6ec
commit 8c944ca2e0
6 changed files with 122 additions and 94 deletions
+24 -13
View File
@@ -1,24 +1,35 @@
import { Bot } from "../../../src/bot.ts";
import { CreateGuildBan } from "../../../src/types/mod.ts";
import { assertEquals } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
const banCounters = new Map<bigint, boolean>();
export async function banTest(bot: Bot, t: Deno.TestContext, guildId: bigint, id: bigint, options?: CreateGuildBan) {
await bot.helpers.ban(guildId, 456226577798135808n);
bot.events.guildBanAdd = function (bot, user, guildId) {
banCounters.set(user.id, true);
};
await bot.helpers.ban(guildId, id, options);
await delayUntil(10000, () => banCounters.get(id));
assertEquals(banCounters.get(id), true);
}
export async function getBansTest(bot: Bot, t: Deno.TestContext, guildId: bigint) {
await bot.helpers.getBans(guildId);
}
export async function banTestWReason(
bot: Bot,
t: Deno.TestContext,
guildId: bigint,
id: bigint,
options?: CreateGuildBan
) {
await bot.helpers.ban(guildId, 456226577798135808n, { reason: "Blame Wolf" });
const bans = await bot.helpers.getBans(guildId);
assertEquals(bans.size > 1, true);
}
export async function unbanTest(bot: Bot, t: Deno.TestContext, guildId: bigint, id: bigint) {
await bot.helpers.unban(guildId, 456226577798135808n);
bot.events.guildBanRemove = function (bot, user, guildId) {
banCounters.set(user.id, false);
};
await bot.helpers.unban(guildId, id);
await delayUntil(10000, () => !banCounters.get(id));
assertEquals(banCounters.get(id), false);
}