Merge branch 'fp-attempt-9001' of https://github.com/discordeno/discordeno into fp-attempt-9001

This commit is contained in:
Skillz4Killz
2021-10-31 19:16:57 +00:00
committed by GitHub
2 changed files with 45 additions and 33 deletions

View File

@@ -1,34 +1,34 @@
import { Bot } from "../../../src/bot.ts";
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
import { assertExists,assertEquals } from "../../deps.ts";
import { assertExists, assertEquals } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
export async function createChannelTests(bot: Bot, guildId: bigint, options: CreateGuildChannel, t: Deno.TestContext) {
const channel = await bot.helpers.createChannel(guildId, options);
// Assertions
assertExists(channel);
assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.channels.has(channel.id));
if (!bot.cache.channels.has(channel.id)) {
throw new Error("The channel seemed to be created but it was not cached.");
}
if (options.topic && channel.topic !== options.topic) {
throw new Error("The channel was supposed to have a topic but it does not appear to be the same topic.");
}
if (options.bitrate && channel.bitrate !== options.bitrate) {
throw new Error("The channel was supposed to have a bitrate but it does not appear to be the same bitrate.");
}
if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) {
throw new Error(
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
);
}
}
const channel = await bot.helpers.createChannel(guildId, options);
// Assertions
assertExists(channel);
assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.channels.has(channel.id));
if (!bot.cache.channels.has(channel.id)) {
throw new Error("The channel seemed to be created but it was not cached.");
}
if (options.topic && channel.topic !== options.topic) {
throw new Error("The channel was supposed to have a topic but it does not appear to be the same topic.");
}
if (options.bitrate && channel.bitrate !== options.bitrate) {
throw new Error("The channel was supposed to have a bitrate but it does not appear to be the same bitrate.");
}
if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) {
throw new Error(
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
);
}
}

View File

@@ -1,5 +1,12 @@
import { TOKEN } from "../configs.ts";
import { createBot, createEventHandlers, DiscordChannelTypes, DiscordOverwriteTypes, startBot, stopBot } from "../mod.ts";
import {
createBot,
createEventHandlers,
DiscordChannelTypes,
DiscordOverwriteTypes,
startBot,
stopBot,
} from "../mod.ts";
import { assertEquals, assertExists } from "./deps.ts";
import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts";
import { getMessagesTest } from "./helpers/messages/getMessages.ts";
@@ -260,10 +267,15 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
t.step({
name: "[channel] create a new category channel",
async fn() {
await createChannelTests(bot, guild.id, {
name: "Discordeno-test",
type: DiscordChannelTypes.GuildCategory,
}, t);
await createChannelTests(
bot,
guild.id,
{
name: "Discordeno-test",
type: DiscordChannelTypes.GuildCategory,
},
t
);
},
...sanitizeMode,
}),