mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix(tests): remaining channel unit tests
This commit is contained in:
@@ -1,28 +1,3 @@
|
||||
import { deleteChannelOverwriteTests } from "./helpers/channels/deleteChannelOverwrite.ts";
|
||||
import { editChannelTests } from "./helpers/channels/editChannel.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] delete a channel overwrite",
|
||||
async fn(t) {
|
||||
await deleteChannelOverwriteTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] edit a channel w/o a reason",
|
||||
async fn(t) {
|
||||
await editChannelTests(guild.id, {});
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] edit a channel w/ a reason",
|
||||
async fn(t) {
|
||||
await editChannelTests(guild.id, { reason: "Blame wolf" });
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
|
||||
// import "./channels/connectToVoice.ts";
|
||||
// import "./misc/editBotStatus.ts";
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { ChannelTypes } from "../../mod.ts";
|
||||
import { assertEquals } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] edit a channel",
|
||||
async fn(t) {
|
||||
const bot = loadBot();
|
||||
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "editChannel" });
|
||||
|
||||
// Edit a channel name without a reason
|
||||
await t.step("[channel] edit a channel name without a reason", async () => {
|
||||
const editedChannel = await bot.helpers.editChannel(channel.id, { name: "editedchannel" });
|
||||
assertEquals(editedChannel.name, "editedchannel");
|
||||
});
|
||||
|
||||
// Edit a channel topic
|
||||
await t.step("[channel] edit a channel topic with a reason", async () => {
|
||||
const editedChannel = await bot.helpers.editChannel(channel.id, { topic: "editedChannel" });
|
||||
assertEquals(editedChannel.topic, "editedChannel");
|
||||
});
|
||||
|
||||
// Change the channel to a news channel
|
||||
await t.step("[channel] change the channel to a news channel with a reason", async () => {
|
||||
const editedChannel = await bot.helpers.editChannel(channel.id, { type: ChannelTypes.GuildNews }, "reason");
|
||||
assertEquals(editedChannel.type, ChannelTypes.GuildNews);
|
||||
});
|
||||
|
||||
// Change from a news channel to a text channel
|
||||
await t.step("[channel] change from a news channel to a text channel", async () => {
|
||||
const editedChannel = await bot.helpers.editChannel(channel.id, { type: ChannelTypes.GuildText });
|
||||
assertEquals(editedChannel.type, ChannelTypes.GuildText);
|
||||
});
|
||||
|
||||
// Enable nsfw
|
||||
await t.step("[channel] enable nsfw", async () => {
|
||||
const editedChannel = await bot.helpers.editChannel(channel.id, { nsfw: true });
|
||||
assertEquals(editedChannel.nsfw, true);
|
||||
});
|
||||
|
||||
// Disable nsfw
|
||||
await t.step("[channel] disable nsfw", async () => {
|
||||
const editedChannel = await bot.helpers.editChannel(channel.id, { nsfw: false });
|
||||
assertEquals(editedChannel.nsfw, false);
|
||||
});
|
||||
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { ChannelTypes, OverwriteTypes } from "../../../types/shared.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { loadBot } from "../../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] Delete a channel overwrite",
|
||||
async fn(t) {
|
||||
const bot = loadBot();
|
||||
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "deleteChannelOverwrite",
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: bot.id,
|
||||
type: OverwriteTypes.Member,
|
||||
allow: ["VIEW_CHANNEL"],
|
||||
deny: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(channel);
|
||||
assertEquals(channel.type, ChannelTypes.GuildText);
|
||||
assertEquals(channel.permissionOverwrites.length, 1);
|
||||
|
||||
await bot.helpers.deleteChannelOverwrite(channel.id, bot.id);
|
||||
|
||||
// Fetch the channel again to validate
|
||||
const fetchedChannel = await bot.helpers.getChannel(channel.id);
|
||||
assertExists(fetchedChannel?.id);
|
||||
assertEquals(fetchedChannel.permissionOverwrites.length, 0);
|
||||
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user