mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
tests: add deleteChannel tests
This commit is contained in:
@@ -14,7 +14,6 @@ import {
|
|||||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||||
export async function createChannel(
|
export async function createChannel(
|
||||||
guildId: string,
|
guildId: string,
|
||||||
name: string,
|
|
||||||
options?: CreateGuildChannel,
|
options?: CreateGuildChannel,
|
||||||
) {
|
) {
|
||||||
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||||
@@ -31,7 +30,6 @@ export async function createChannel(
|
|||||||
endpoints.GUILD_CHANNELS(guildId),
|
endpoints.GUILD_CHANNELS(guildId),
|
||||||
{
|
{
|
||||||
...options,
|
...options,
|
||||||
name,
|
|
||||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||||
...perm,
|
...perm,
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { cache, createChannel, delay } from "../../mod.ts";
|
||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[channel] create a new channel",
|
||||||
|
async fn() {
|
||||||
|
const channel = await createChannel(tempData.guildId, {
|
||||||
|
name: "Discordeno-test",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(channel);
|
||||||
|
|
||||||
|
tempData.channelId = channel.id;
|
||||||
|
assertEquals(tempData.channelId, channel.id);
|
||||||
|
|
||||||
|
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||||
|
await delay(5000);
|
||||||
|
|
||||||
|
if (!cache.channels.has(channel.id)) {
|
||||||
|
throw new Error("The channel seemed to be created but it was not cached.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { cache, createChannel, delay, deleteChannel } from "../../mod.ts";
|
||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[channel] delete a channel without a reason.",
|
||||||
|
async fn() {
|
||||||
|
// Create the necessary channels
|
||||||
|
const channel = await createChannel(tempData.guildId, {
|
||||||
|
name: "delete-channel",
|
||||||
|
});
|
||||||
|
// wait 5 seconds to give it time for CHANNEL_CREATE event
|
||||||
|
await delay(5000);
|
||||||
|
// Make sure the channel was created.
|
||||||
|
if (!cache.channels.has(channel.id))
|
||||||
|
throw new Error(
|
||||||
|
"The channel should have been created but it is not in the cache."
|
||||||
|
);
|
||||||
|
|
||||||
|
// Delete the channel now without a reason
|
||||||
|
await deleteChannel(tempData.guildId, channel.id);
|
||||||
|
// wait 5 seconds to give it time for CHANNEL_DELETE event
|
||||||
|
await delay(5000);
|
||||||
|
// Make sure it is gone from cache
|
||||||
|
if (cache.channels.has(channel.id))
|
||||||
|
throw new Error(
|
||||||
|
"The channel should have been deleted but it is still in cache."
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[channel] delete a channel with a reason.",
|
||||||
|
async fn() {
|
||||||
|
// Create the necessary channels
|
||||||
|
const channel = await createChannel(tempData.guildId, {
|
||||||
|
name: "delete-channel",
|
||||||
|
});
|
||||||
|
// wait 5 seconds to give it time for CHANNEL_CREATE event
|
||||||
|
await delay(5000);
|
||||||
|
// Make sure the channel was created.
|
||||||
|
if (!cache.channels.has(channel.id))
|
||||||
|
throw new Error(
|
||||||
|
"The channel should have been created but it is not in the cache."
|
||||||
|
);
|
||||||
|
|
||||||
|
// Delete the channel now without a reason
|
||||||
|
await deleteChannel(tempData.guildId, channel.id, "with a reason");
|
||||||
|
// wait 5 seconds to give it time for CHANNEL_DELETE event
|
||||||
|
await delay(5000);
|
||||||
|
// Make sure it is gone from cache
|
||||||
|
if (cache.channels.has(channel.id))
|
||||||
|
throw new Error(
|
||||||
|
"The channel should have been deleted but it is still in cache."
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
@@ -10,5 +10,11 @@ import "./util/utils.ts";
|
|||||||
// First initate the connection
|
// First initate the connection
|
||||||
import "./ws/start_bot.ts";
|
import "./ws/start_bot.ts";
|
||||||
import "./guilds/create_guild.ts";
|
import "./guilds/create_guild.ts";
|
||||||
|
|
||||||
|
// Channel tests
|
||||||
|
import "./channels/create_channel.ts";
|
||||||
|
import "./channels/delete_channel.ts";
|
||||||
|
|
||||||
|
// Final cleanup
|
||||||
import "./guilds/delete_server.ts";
|
import "./guilds/delete_server.ts";
|
||||||
import "./ws/ws_close.ts";
|
import "./ws/ws_close.ts";
|
||||||
|
|||||||
Reference in New Issue
Block a user