Rework channel clone tests

- Removed previous channel clone test
- Copied over create channel tests and modified `ifItFailsBlameWolf` to check against a clone instead of created
This commit is contained in:
Exists
2021-04-14 14:14:37 -04:00
parent fea973b346
commit 3b41656c09
+126 -14
View File
@@ -1,20 +1,23 @@
import { tempData } from "../ws/start_bot.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts"; import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts"; import { cache } from "../../src/cache.ts";
import { cloneChannel } from "../../src/helpers/channels/clone_channel.ts"; import { cloneChannel } from "../../src/helpers/channels/clone_channel.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
import { delayUntil } from "../util/delay_until.ts"; import { delayUntil } from "../util/delay_until.ts";
import { botId } from "../../src/bot.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
Deno.test({ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
name: "[channel] clone a channel", const channel = await createChannel(tempData.guildId, options);
async fn() {
const cloned = await cloneChannel(tempData.channelId, "testing");
//Get channel that was cloned const cloned = await cloneChannel(channel.id);
const originalChannel = cache.channels.get(tempData.channelId);
//Assertation //Assertations
assertExists(cloned); assertExists(cloned);
assertEquals(cloned.type, originalChannel.type); assertEquals(cloned.type, channel.type);
// Delay the execution to allow CHANNEL_CREATE event to be processed // Delay the execution to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => cache.channels.has(cloned.id)); await delayUntil(10000, () => cache.channels.has(cloned.id));
@@ -23,26 +26,135 @@ Deno.test({
throw new Error(`The channel seemed to be cloned but was not cached.`); throw new Error(`The channel seemed to be cloned but was not cached.`);
} }
if (originalChannel.topic && cloned.topic !== originalChannel.topic) { if (channel.topic && cloned.topic !== channel.topic) {
throw new Error( throw new Error(
"The clone was supposed to have a topic but it does not appear to be the same topic.", "The clone was supposed to have a topic but it does not appear to be the same topic.",
); );
} }
if (originalChannel.bitrate && cloned.bitrate !== originalChannel.bitrate) { if (channel.bitrate && cloned.bitrate !== channel.bitrate) {
throw new Error( throw new Error(
"The clone was supposed to have a bitrate but it does not appear to be the same bitrate.", "The clone was supposed to have a bitrate but it does not appear to be the same bitrate.",
); );
} }
if ( if (
originalChannel.permissionOverwrites && channel.permissionOverwrites &&
cloned.permissionOverwrites?.length !== cloned.permissionOverwrites?.length !== channel.permissionOverwrites.length
originalChannel.permissionOverwrites.length
) { ) {
throw new Error( throw new Error(
"The clone was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites.", "The clone was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites.",
); );
} }
}
Deno.test({
name: "[channel] clone a new text channel",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, false);
}, },
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new category channel",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GUILD_CATEGORY,
},
false,
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GUILD_VOICE,
},
false,
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel with a bitrate",
async fn() {
await ifItFailsBlameWolf(
{
name: "discordeno-clone-test",
type: DiscordChannelTypes.GUILD_VOICE,
bitrate: 32000,
},
false,
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel with a user limit",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GUILD_VOICE,
userLimit: 32,
},
false,
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel with a rate limit per user",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
rateLimitPerUser: 2423,
},
false,
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel with NSFW",
async fn() {
await ifItFailsBlameWolf(
{ name: "Discordeno-clone-test", nsfw: true },
false,
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] create a new text channel with permission overwrites",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
permissionOverwrites: [
{
id: botId,
type: DiscordOverwriteTypes.MEMBER,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
},
false,
);
},
...defaultTestOptions,
}); });