Files
discordeno/tests/helpers/channels/deleteChannelOverwrite.ts
Skillz4Killz ef5b25b319 test: fix unit tests related to code bugs (#2001)
* fix: get tests runnable

* fix: tests are now passing

* fix: 32 passing tests

* fix: deno fmt u dumb dumb work automatically for once in your life

* fix: 54 tests passing now

* fix: 94 passing, itoh was wrong he guess wrong hehe

* fix: remove debug logs

* fix: remove broken webhook test for now

Co-authored-by: ITOH <to@itoh.at>
2022-02-06 15:56:56 +00:00

48 lines
1.5 KiB
TypeScript

import { ChannelTypes, OverwriteTypes } from "../../../mod.ts";
import { channelOverwriteHasPermission } from "../../../plugins/permissions/src/permissions.ts";
import { assertEquals, assertExists } from "../../deps.ts";
import { bot } from "../../mod.ts";
import { delayUntil } from "../../utils.ts";
export async function deleteChannelOverwriteTests(guildId: bigint) {
const channel = await bot.helpers.createChannel(guildId, {
name: "Discordeno-test",
permissionOverwrites: [
{
id: bot.id,
type: OverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
});
// Assertions
assertExists(channel);
assertEquals(channel.type, ChannelTypes.GuildText);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.channels.has(channel.id));
if (!bot.channels.has(channel.id)) {
throw new Error("The channel seemed to be created but it was not cached.");
}
assertEquals(channel.permissionOverwrites.length, 1);
assertEquals(
channelOverwriteHasPermission(channel.guildId, bot.id, bot.channels.get(channel.id)?.permissionOverwrites || [], [
"VIEW_CHANNEL",
]),
true,
);
await bot.helpers.deleteChannelOverwrite(channel.id, bot.id);
await delayUntil(10000, () => bot.channels.get(channel.id)?.permissionOverwrites?.length === 0);
if (bot.channels.get(channel.id)?.permissionOverwrites?.length !== 0) {
throw new Error("The channel permission overwrite was supposed to be deleted but it does not appear to be.");
}
}