mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
add clone channel unit test
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
20
tests/helpers/channels/cloneChannel.ts
Normal file
20
tests/helpers/channels/cloneChannel.ts
Normal 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);
|
||||
}
|
||||
13
tests/mod.ts
13
tests/mod.ts
@@ -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);
|
||||
}
|
||||
})
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user