mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
Closes #1179
This commit is contained in:
@@ -170,6 +170,8 @@ export type CacheExecutor = (
|
||||
export function createExecute(cache: Cache): CacheExecutor {
|
||||
return function (type, options) {
|
||||
switch (type) {
|
||||
case "FILTER_CATEGORY_CHILDREN_CHANNELS":
|
||||
return cache.channels.filter(c => c.parentId === options.parentChannelId);
|
||||
case "DELETE_MESSAGES_FROM_CHANNEL":
|
||||
cache.messages.forEach((message) => {
|
||||
if (message.channelId === options.channelId) {
|
||||
|
||||
40
tests/helpers/channels/categoryChannels.ts
Normal file
40
tests/helpers/channels/categoryChannels.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/channels/channel_types.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function categoryChildrenTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const category = await bot.helpers.createChannel(guildId, {
|
||||
name: "Discordeno-test",
|
||||
type: DiscordChannelTypes.GuildCategory,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(category);
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.channels.has(category.id));
|
||||
|
||||
assertExists(bot.cache.channels.has(category.id));
|
||||
|
||||
const channelsToCreate = [1, 2, 3, 4, 5];
|
||||
const channels = await Promise.all(
|
||||
channelsToCreate.map((num) =>
|
||||
bot.helpers.createChannel(guildId, {
|
||||
name: `Discordeno-test-${num}`,
|
||||
parentId: category.id,
|
||||
})
|
||||
)
|
||||
);
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => channels.every((c) => bot.cache.channels.has(c.id)));
|
||||
|
||||
// If every channel is not present in the cache, error out
|
||||
if (!channels.every((c) => bot.cache.channels.has(c.id))) {
|
||||
throw new Error("The channels seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
const ids = await bot.helpers.categoryChildren(category.id);
|
||||
if (ids.size !== channelsToCreate.length || !channels.every((c) => ids.has(c.id))) {
|
||||
throw new Error("The category channel ids did not match with the category channels.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user