add clone channel unit test

This commit is contained in:
Skillz4Killz
2021-11-04 00:29:20 +00:00
committed by GitHub
parent c001e09e56
commit df0e4052ad
5 changed files with 40 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import {
calculateBits,
isHigherPosition,
requireOverwritePermissions,
calculatePermissions,
} from "./util/permissions.ts";
import {
checkRateLimits,
@@ -322,6 +323,7 @@ export function createUtils(options: Partial<HelperUtils>) {
formatImageURL,
validateSlashCommands,
requireOverwritePermissions,
calculatePermissions,
};
}
@@ -358,6 +360,7 @@ export interface HelperUtils {
formatImageURL: typeof formatImageURL;
validateSlashCommands: typeof validateSlashCommands;
requireOverwritePermissions: typeof requireOverwritePermissions;
calculatePermissions: typeof calculatePermissions;
}
export function createGatewayManager(
@@ -481,6 +484,7 @@ export interface Helpers {
batchEditSlashCommandPermissions: typeof helpers.batchEditSlashCommandPermissions;
categoryChildren: typeof helpers.categoryChildren;
channelOverwriteHasPermission: typeof helpers.channelOverwriteHasPermission;
cloneChannel: typeof helpers.cloneChannel;
connectToVoiceChannel: typeof helpers.connectToVoiceChannel;
createChannel: typeof helpers.createChannel;
createEmoji: typeof helpers.createEmoji;

View File

@@ -17,7 +17,7 @@ export async function cloneChannel(bot: Bot, channelId: bigint, reason?: string)
name: channelToClone.name!,
topic: channelToClone.topic || undefined,
permissionOverwrites: channelToClone.permissionOverwrites.map((overwrite) => ({
id: overwrite.id.toString(),
id: overwrite.id,
type: overwrite.type,
allow: bot.utils.calculatePermissions(overwrite.allow),
deny: bot.utils.calculatePermissions(overwrite.deny),

View File

@@ -153,6 +153,7 @@ import { startPrivateThread } from "./channels/threads/start_private_thread.ts";
import { startThread } from "./channels/threads/start_thread.ts";
import { unarchiveThread } from "./channels/threads/unarchive_thread.ts";
import { unlockThread } from "./channels/threads/unlock_thread.ts";
import { cloneChannel } from "./channels/clone_channel.ts";
export {
addDiscoverySubcategory,
@@ -165,6 +166,7 @@ export {
batchEditSlashCommandPermissions,
categoryChildren,
channelOverwriteHasPermission,
cloneChannel,
connectToVoiceChannel,
createChannel,
createEmoji,

View File

@@ -0,0 +1,20 @@
import { Bot } from "../../../src/bot.ts";
import { DiscordenoChannel } from "../../../src/transformers/channel.ts";
import { assertExists, assertEquals } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
export async function cloneChannelTests(bot: Bot, guildId: bigint, channel: DiscordenoChannel, options: {reason?: string}, t: Deno.TestContext) {
const cloned = await bot.helpers.cloneChannel(channel.id, options.reason);
//Assertations
assertExists(cloned);
assertEquals(cloned.type, channel.type);
// Delay the execution to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => bot.cache.channels.has(cloned.id));
assertExists(bot.cache.channels.has(cloned.id));
assertEquals(channel.topic, cloned.topic);
assertEquals(channel.bitrate, cloned.bitrate);
assertEquals(channel.permissionOverwrites.length, cloned.permissionOverwrites.length);
}

View File

@@ -59,6 +59,7 @@ import { getVanityURLTests } from "./helpers/guilds/getVanityUrl.ts";
import { getDiscoveryCategoriesTest, validDiscoveryTermTest } from "./helpers/misc/discoveries.ts";
import { categoryChildrenTest } from "./helpers/channels/categoryChannels.ts";
import { channelOverwriteHasPermissionTest } from "./helpers/channels/channelOverwriteHasPermission.ts";
import { cloneChannelTests } from "./helpers/channels/cloneChannel.ts";
// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS
const sanitizeMode = {
@@ -555,6 +556,18 @@ Deno.test({
async fn() {
await channelOverwriteHasPermissionTest(bot, guild.id, t);
}
}),
t.step({
name: "[channel] clone a channel w/o a reason",
async fn() {
await cloneChannelTests(bot, guild.id, channel, {}, t);
}
}),
t.step({
name: "[channel] clone a channel w a reason",
async fn() {
await cloneChannelTests(bot, guild.id, channel, { reason: "Blame wolf"}, t);
}
})
]);