add channel tests

This commit is contained in:
Skillz4Killz
2021-10-31 19:12:04 +00:00
committed by GitHub
parent b439dc1f4a
commit 66b64b1868
4 changed files with 185 additions and 5 deletions
+3 -2
View File
@@ -24,10 +24,11 @@ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateG
userLimit: options.userLimit,
rateLimitPerUser: options.rateLimitPerUser,
position: options.position,
parentId: options.parentId,
parentId: options.parentId?.toString(),
nsfw: options.nsfw,
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
...perm,
id: perm.id.toString(),
type: perm.type,
allow: bot.utils.calculateBits(perm.allow),
deny: bot.utils.calculateBits(perm.deny),
})),
+3 -2
View File
@@ -3,7 +3,7 @@ import { DiscordOverwriteTypes } from "./overwrite_types.ts";
export interface Overwrite {
/** Role or user id */
id: string;
id: bigint;
/** Either 0 (role) or 1 (member) */
type: DiscordOverwriteTypes;
/** Permission bit set */
@@ -13,7 +13,8 @@ export interface Overwrite {
}
/** https://discord.com/developers/docs/resources/channel#overwrite-object */
export interface DiscordOverwrite extends Omit<Overwrite, "allow" | "deny"> {
export interface DiscordOverwrite extends Omit<Overwrite, "allow" | "deny" | "id"> {
id: string;
allow: string;
deny: string;
}
+34
View File
@@ -0,0 +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 { 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."
);
}
}
+145 -1
View File
@@ -1,5 +1,5 @@
import { TOKEN } from "../configs.ts";
import { createBot, createEventHandlers, DiscordChannelTypes, 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";
@@ -19,6 +19,7 @@ import { editMessageTest } from "./helpers/messages/editMessage.ts";
import { fetchSingleMemberTest } from "./helpers/members/fetchMembers.ts";
import { pinMessageTests } from "./helpers/messages/pin.ts";
import { removeAllReactionTests, removeReactionEmojiTest, removeReactionTest } from "./helpers/messages/reactions.ts";
import { createChannelTests } from "./helpers/channels/createChannel.ts";
Deno.test("[Bot] - Starting Tests", async (t) => {
// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS
@@ -237,6 +238,149 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
}),
]);
});
// ALL CHANNEL RELATED TESTS CAN GO HERE
await Promise.all([
t.step({
name: "[channel] send message with text",
fn: async (t) => {
await sendMessageWithTextTest(bot, channel.id, t);
},
...sanitizeMode,
}),
t.step({
name: "[channel] create a new text channel",
async fn() {
await createChannelTests(bot, guild.id, { name: "Discordeno-test" }, t);
},
...sanitizeMode,
}),
t.step({
name: "[channel] create a new category channel",
async fn() {
await createChannelTests(bot, guild.id, {
name: "Discordeno-test",
type: DiscordChannelTypes.GuildCategory,
}, t);
},
...sanitizeMode,
}),
// t.step({
// name: "[channel] create a new news channel",
// async fn() {
// await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_NEWS}, t);
// },
// ...sanitizeMode,
// }),
// t.step({
// name: "[channel] create a new store channel",
// async fn() {
// await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_STORE}, t);
// },
// ...sanitizeMode,
// }),
t.step({
name: "[channel] create a new voice channel",
async fn() {
await createChannelTests(
bot,
guild.id,
{
name: "Discordeno-test",
type: DiscordChannelTypes.GuildVoice,
},
t
);
},
...sanitizeMode,
}),
t.step({
name: "[channel] create a new voice channel with a bitrate",
async fn() {
await createChannelTests(
bot,
guild.id,
{
name: "discordeno-test",
type: DiscordChannelTypes.GuildVoice,
bitrate: 32000,
},
t
);
},
...sanitizeMode,
}),
t.step({
name: "[channel] create a new voice channel with a user limit",
async fn() {
await createChannelTests(
bot,
guild.id,
{
name: "Discordeno-test",
type: DiscordChannelTypes.GuildVoice,
userLimit: 32,
},
t
);
},
...sanitizeMode,
}),
t.step({
name: "[channel] create a new text channel with a rate limit per user",
async fn() {
await createChannelTests(
bot,
guild.id,
{
name: "Discordeno-test",
rateLimitPerUser: 2423,
},
t
);
},
...sanitizeMode,
}),
t.step({
name: "[channel] create a new text channel with NSFW",
async fn() {
await createChannelTests(bot, guild.id, { name: "Discordeno-test", nsfw: true }, t);
},
...sanitizeMode,
}),
t.step({
name: "[channel] create a new text channel with permission overwrites",
async fn() {
await createChannelTests(
bot,
guild.id,
{
name: "Discordeno-test",
permissionOverwrites: [
{
id: bot.id,
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
},
t
);
},
...sanitizeMode,
}),
]);
});
// MEMBER TESTS GROUPED