mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
This commit is contained in:
@@ -8,9 +8,9 @@ import { delayUntil } from "../util/delay_until.ts";
|
|||||||
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
import { botId } from "../../src/bot.ts";
|
import { botId } from "../../src/bot.ts";
|
||||||
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
|
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
|
||||||
import {editChannelOverwrite} from "../../src/helpers/channels/edit_channel_overwrite.ts";
|
import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts";
|
||||||
import {channelOverwriteHasPermission} from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
|
import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
|
||||||
import {DiscordBitwisePermissionFlags} from "../../src/types/permissions/bitwise_permission_flags.ts";
|
import { DiscordBitwisePermissionFlags } from "../../src/types/permissions/bitwise_permission_flags.ts";
|
||||||
|
|
||||||
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
||||||
const channel = await createChannel(tempData.guildId, options);
|
const channel = await createChannel(tempData.guildId, options);
|
||||||
@@ -36,9 +36,14 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, options.permissionOverwrites ? options.permissionOverwrites[0].allow : []),
|
channelOverwriteHasPermission(
|
||||||
true
|
channel.guildId,
|
||||||
)
|
botId,
|
||||||
|
cache.channels.get(channel.id)?.permissionOverwrites,
|
||||||
|
options.permissionOverwrites ? options.permissionOverwrites[0].allow : [],
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { cache } from "../../src/cache.ts";
|
|||||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
import {editChannel} from "../../src/helpers/channels/edit_channel.ts";
|
import { editChannel } from "../../src/helpers/channels/edit_channel.ts";
|
||||||
import {assertEquals} from "../deps.ts";
|
import { assertEquals } from "../deps.ts";
|
||||||
|
|
||||||
async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
|
async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
|
||||||
// Create the necessary channels
|
// Create the necessary channels
|
||||||
@@ -15,22 +15,25 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
|
|||||||
// Make sure the channel was created.
|
// Make sure the channel was created.
|
||||||
if (!cache.channels.has(channel.id)) {
|
if (!cache.channels.has(channel.id)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"The channel should have been created but it is not in the cache.",
|
"The channel should have been created but it is not in the cache.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edit the channel now
|
// Edit the channel now
|
||||||
if (type === "raw") {
|
if (type === "raw") {
|
||||||
await editChannel(channel.id, {
|
await editChannel(channel.id, {
|
||||||
name: "new-name"
|
name: "new-name",
|
||||||
}, reason);
|
}, reason);
|
||||||
} else {
|
} else {
|
||||||
await channel.edit({
|
await channel.edit({
|
||||||
name: "new-name"
|
name: "new-name",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// wait 5 seconds to give it time for CHANNEL_UPDATE event
|
// wait 5 seconds to give it time for CHANNEL_UPDATE event
|
||||||
await delayUntil(3000, () => cache.channels.get(channel.id)?.name === "new-name");
|
await delayUntil(
|
||||||
|
3000,
|
||||||
|
() => cache.channels.get(channel.id)?.name === "new-name",
|
||||||
|
);
|
||||||
assertEquals(cache.channels.get(channel.id)?.name, "new-name");
|
assertEquals(cache.channels.get(channel.id)?.name, "new-name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import { delayUntil } from "../util/delay_until.ts";
|
|||||||
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
import { botId } from "../../src/bot.ts";
|
import { botId } from "../../src/bot.ts";
|
||||||
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
|
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
|
||||||
import {editChannelOverwrite} from "../../src/helpers/channels/edit_channel_overwrite.ts";
|
import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts";
|
||||||
import {channelOverwriteHasPermission} from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
|
import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
|
||||||
import {DiscordBitwisePermissionFlags} from "../../src/types/permissions/bitwise_permission_flags.ts";
|
import { DiscordBitwisePermissionFlags } from "../../src/types/permissions/bitwise_permission_flags.ts";
|
||||||
|
|
||||||
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
||||||
const channel = await createChannel(tempData.guildId, options);
|
const channel = await createChannel(tempData.guildId, options);
|
||||||
@@ -43,13 +43,24 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
|||||||
|
|
||||||
await delayUntil(
|
await delayUntil(
|
||||||
10000,
|
10000,
|
||||||
() => channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, ["VIEW_CHANNEL", "ADD_REACTIONS"]),
|
() =>
|
||||||
|
channelOverwriteHasPermission(
|
||||||
|
channel.guildId,
|
||||||
|
botId,
|
||||||
|
cache.channels.get(channel.id)?.permissionOverwrites,
|
||||||
|
["VIEW_CHANNEL", "ADD_REACTIONS"],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, ["VIEW_CHANNEL", "ADD_REACTIONS"]),
|
channelOverwriteHasPermission(
|
||||||
true
|
channel.guildId,
|
||||||
)
|
botId,
|
||||||
|
cache.channels.get(channel.id)?.permissionOverwrites,
|
||||||
|
["VIEW_CHANNEL", "ADD_REACTIONS"],
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
|||||||
import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts";
|
import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts";
|
||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
import {editChannel} from "../../src/helpers/channels/edit_channel.ts";
|
import { editChannel } from "../../src/helpers/channels/edit_channel.ts";
|
||||||
import {assertEquals} from "../deps.ts";
|
import { assertEquals } from "../deps.ts";
|
||||||
import {getChannel} from "../../src/helpers/channels/get_channel.ts";
|
import { getChannel } from "../../src/helpers/channels/get_channel.ts";
|
||||||
import {botId} from "../../src/bot.ts";
|
import { botId } from "../../src/bot.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "[channel] get a channel",
|
name: "[channel] get a channel",
|
||||||
@@ -20,7 +20,7 @@ Deno.test({
|
|||||||
// Make sure the channel was created.
|
// Make sure the channel was created.
|
||||||
if (!cache.channels.has(channel.id)) {
|
if (!cache.channels.has(channel.id)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"The channel should have been created but it is not in the cache.",
|
"The channel should have been created but it is not in the cache.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ Deno.test({
|
|||||||
await delayUntil(3000, () => cache.channels.has(channel.id));
|
await delayUntil(3000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
cache.channels.has(channel.id),
|
cache.channels.has(channel.id),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
|||||||
import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts";
|
import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts";
|
||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
import {editChannel} from "../../src/helpers/channels/edit_channel.ts";
|
import { editChannel } from "../../src/helpers/channels/edit_channel.ts";
|
||||||
import {assertEquals} from "../deps.ts";
|
import { assertEquals } from "../deps.ts";
|
||||||
import {getChannel} from "../../src/helpers/channels/get_channel.ts";
|
import { getChannel } from "../../src/helpers/channels/get_channel.ts";
|
||||||
import {botId} from "../../src/bot.ts";
|
import { botId } from "../../src/bot.ts";
|
||||||
import {getChannels} from "../../src/helpers/channels/get_channels.ts";
|
import { getChannels } from "../../src/helpers/channels/get_channels.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "[channel] get channels.",
|
name: "[channel] get channels.",
|
||||||
@@ -19,8 +19,8 @@ Deno.test({
|
|||||||
await delayUntil(3000, () => cache.channels.size > 0);
|
await delayUntil(3000, () => cache.channels.size > 0);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
cache.channels.size > 0,
|
cache.channels.size > 0,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
|
|||||||
+20
-11
@@ -2,17 +2,17 @@ import { cache } from "../../src/cache.ts";
|
|||||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
import {assertEquals, assertExists} from "../deps.ts";
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
import {getChannels} from "../../src/helpers/channels/get_channels.ts";
|
import { getChannels } from "../../src/helpers/channels/get_channels.ts";
|
||||||
import {sendMessage} from "../../src/helpers/messages/send_message.ts";
|
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
|
||||||
import {getPins} from "../../src/helpers/channels/get_pins.ts";
|
import { getPins } from "../../src/helpers/channels/get_pins.ts";
|
||||||
import {DiscordenoMessage} from "../../src/structures/message.ts";
|
import { DiscordenoMessage } from "../../src/structures/message.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "[channel] get pins.",
|
name: "[channel] get pins.",
|
||||||
async fn() {
|
async fn() {
|
||||||
const channel = await createChannel(tempData.guildId, {
|
const channel = await createChannel(tempData.guildId, {
|
||||||
name: 'pins-channel'
|
name: "pins-channel",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
@@ -22,14 +22,23 @@ Deno.test({
|
|||||||
await delayUntil(10000, () => cache.channels.has(channel.id));
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
if (!cache.channels.has(channel.id)) {
|
if (!cache.channels.has(channel.id)) {
|
||||||
throw new Error("The channel seemed to be created but it was not cached.");
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = await sendMessage(tempData.channelId, "Hello World!");
|
const message = await sendMessage(tempData.channelId, "Hello World!");
|
||||||
const secondMessage = await sendMessage(tempData.channelId, "Goodbye World!");
|
const secondMessage = await sendMessage(
|
||||||
|
tempData.channelId,
|
||||||
|
"Goodbye World!",
|
||||||
|
);
|
||||||
|
|
||||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||||
await delayUntil(10000, () => cache.messages.has(message.id) && cache.messages.has(secondMessage.id));
|
await delayUntil(
|
||||||
|
10000,
|
||||||
|
() =>
|
||||||
|
cache.messages.has(message.id) && cache.messages.has(secondMessage.id),
|
||||||
|
);
|
||||||
|
|
||||||
await message.pin();
|
await message.pin();
|
||||||
await secondMessage.pin();
|
await secondMessage.pin();
|
||||||
@@ -37,8 +46,8 @@ Deno.test({
|
|||||||
const pins = await getPins(tempData.channelId);
|
const pins = await getPins(tempData.channelId);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
pins.length,
|
pins.length,
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { cache } from "../../src/cache.ts";
|
|||||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
import {assertEquals, assertExists} from "../deps.ts";
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts";
|
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
|
||||||
import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts";
|
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||||
import {botId} from "../../src/bot.ts";
|
import { botId } from "../../src/bot.ts";
|
||||||
import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts";
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "[channel] is channel synced.",
|
name: "[channel] is channel synced.",
|
||||||
@@ -31,12 +31,14 @@ Deno.test({
|
|||||||
await delayUntil(10000, () => cache.channels.has(category.id));
|
await delayUntil(10000, () => cache.channels.has(category.id));
|
||||||
|
|
||||||
if (!cache.channels.has(category.id)) {
|
if (!cache.channels.has(category.id)) {
|
||||||
throw new Error("The channel seemed to be created but it was not cached.");
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const channel = await createChannel(tempData.guildId, {
|
const channel = await createChannel(tempData.guildId, {
|
||||||
name: 'synced-channel',
|
name: "synced-channel",
|
||||||
parentId: category.id
|
parentId: category.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
@@ -46,14 +48,16 @@ Deno.test({
|
|||||||
await delayUntil(10000, () => cache.channels.has(channel.id));
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
if (!cache.channels.has(channel.id)) {
|
if (!cache.channels.has(channel.id)) {
|
||||||
throw new Error("The channel seemed to be created but it was not cached.");
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSynced = await isChannelSynced(channel.id);
|
const isSynced = await isChannelSynced(channel.id);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
isSynced,
|
isSynced,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ import { cache } from "../../src/cache.ts";
|
|||||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
import {assertEquals, assertExists} from "../deps.ts";
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts";
|
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
|
||||||
import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts";
|
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||||
import {botId} from "../../src/bot.ts";
|
import { botId } from "../../src/bot.ts";
|
||||||
import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts";
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
import {startTyping} from "../../src/helpers/channels/start_typing.ts";
|
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "[channel] is typing.",
|
name: "[channel] is typing.",
|
||||||
async fn() {
|
async fn() {
|
||||||
const channel = await createChannel(tempData.guildId, {
|
const channel = await createChannel(tempData.guildId, {
|
||||||
name: 'typing-channel',
|
name: "typing-channel",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
@@ -23,7 +23,9 @@ Deno.test({
|
|||||||
await delayUntil(10000, () => cache.channels.has(channel.id));
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
if (!cache.channels.has(channel.id)) {
|
if (!cache.channels.has(channel.id)) {
|
||||||
throw new Error("The channel seemed to be created but it was not cached.");
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await startTyping(channel.id);
|
await startTyping(channel.id);
|
||||||
|
|||||||
@@ -2,61 +2,74 @@ import { cache } from "../../src/cache.ts";
|
|||||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
import {assertEquals, assertExists} from "../deps.ts";
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts";
|
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
|
||||||
import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts";
|
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||||
import {botId} from "../../src/bot.ts";
|
import { botId } from "../../src/bot.ts";
|
||||||
import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts";
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
import {startTyping} from "../../src/helpers/channels/start_typing.ts";
|
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
|
||||||
import {swapChannels} from "../../src/helpers/channels/swap_channels.ts";
|
import { swapChannels } from "../../src/helpers/channels/swap_channels.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "[channel] swap channels",
|
name: "[channel] swap channels",
|
||||||
async fn() {
|
async fn() {
|
||||||
const channel = await createChannel(tempData.guildId, {
|
const channel = await createChannel(tempData.guildId, {
|
||||||
name: 'channel-1',
|
name: "channel-1",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
assertExists(channel);
|
assertExists(channel);
|
||||||
|
|
||||||
const secondChannel = await createChannel(tempData.guildId, {
|
const secondChannel = await createChannel(tempData.guildId, {
|
||||||
name: 'channel-2',
|
name: "channel-2",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
assertExists(channel);
|
assertExists(channel);
|
||||||
|
|
||||||
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||||
await delayUntil(10000, () => cache.channels.has(channel.id) && cache.channels.has(secondChannel.id));
|
await delayUntil(
|
||||||
|
10000,
|
||||||
|
() =>
|
||||||
|
cache.channels.has(channel.id) && cache.channels.has(secondChannel.id),
|
||||||
|
);
|
||||||
|
|
||||||
if (!cache.channels.has(channel.id) || !cache.channels.has(secondChannel.id)) {
|
if (
|
||||||
throw new Error("The channel seemed to be created but it was not cached.");
|
!cache.channels.has(channel.id) || !cache.channels.has(secondChannel.id)
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await swapChannels(tempData.guildId, [
|
await swapChannels(tempData.guildId, [
|
||||||
{
|
{
|
||||||
id: channel.id,
|
id: channel.id,
|
||||||
position: secondChannel.position!
|
position: secondChannel.position!,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: secondChannel.id,
|
id: secondChannel.id,
|
||||||
position: channel.position!
|
position: channel.position!,
|
||||||
}
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Delay the execution by 5 seconds to allow CHANNEL_UPDATE event to be processed
|
// Delay the execution by 5 seconds to allow CHANNEL_UPDATE event to be processed
|
||||||
await delayUntil(10000, () => cache.channels.get(channel.id)?.position === secondChannel.position && cache.channels.get(secondChannel.id)?.position === channel.position);
|
await delayUntil(
|
||||||
|
10000,
|
||||||
|
() =>
|
||||||
|
cache.channels.get(channel.id)?.position === secondChannel.position &&
|
||||||
|
cache.channels.get(secondChannel.id)?.position === channel.position,
|
||||||
|
);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
cache.channels.get(channel.id)?.position,
|
cache.channels.get(channel.id)?.position,
|
||||||
secondChannel.position
|
secondChannel.position,
|
||||||
)
|
);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
cache.channels.get(secondChannel.id)?.position,
|
cache.channels.get(secondChannel.id)?.position,
|
||||||
channel.position
|
channel.position,
|
||||||
)
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import "./channels/is_channel_synced.ts";
|
|||||||
import "./channels/start_typing.ts";
|
import "./channels/start_typing.ts";
|
||||||
import "./channels/swap_channels.ts";
|
import "./channels/swap_channels.ts";
|
||||||
|
|
||||||
|
|
||||||
// Emojis tests
|
// Emojis tests
|
||||||
import "./emojis/create_emoji.ts";
|
import "./emojis/create_emoji.ts";
|
||||||
import "./emojis/delete_emoji.ts";
|
import "./emojis/delete_emoji.ts";
|
||||||
|
|||||||
Reference in New Issue
Block a user