remove old tests

This commit is contained in:
Skillz4Killz
2021-10-28 17:26:16 +00:00
committed by GitHub
parent 109c2b8abe
commit 3d43d7eedf
55 changed files with 1 additions and 3282 deletions

View File

@@ -1,48 +0,0 @@
import { cache } from "../../src/cache.ts";
import { categoryChildren, createChannel } from "../../src/helpers/mod.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[channel] category channel ids",
async fn() {
const category = await createChannel(tempData.guildId, {
name: "Discordeno-test",
type: DiscordChannelTypes.GuildCategory,
});
// Assertions
assertExists(category);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const channelsToCreate = [1, 2, 3, 4, 5];
const channels = await Promise.all(
channelsToCreate.map((num) =>
createChannel(tempData.guildId, {
name: `Discordeno-test-${num}`,
parentId: category.id,
})
)
);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => channels.every((c) => cache.channels.has(c.id)));
// If every channel is not present in the cache, error out
if (!channels.every((c) => cache.channels.has(c.id))) {
throw new Error("The channels seemed to be created but it was not cached.");
}
const ids = await 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.");
}
},
...defaultTestOptions,
});

View File

@@ -1,60 +0,0 @@
import { botId } from "../../src/bot.ts";
import { cache } from "../../src/cache.ts";
import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
import { bigintToSnowflake } from "../../src/util/bigint.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(options: CreateGuildChannel) {
const channel = await createChannel(tempData.guildId, options);
// Assertions
assertExists(channel);
assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) {
throw new Error(
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
);
}
assertEquals(
channelOverwriteHasPermission(
channel.guildId,
botId,
cache.channels.get(channel.id)?.permissionOverwrites || [],
options.permissionOverwrites ? options.permissionOverwrites[0].allow : []
),
true
);
}
Deno.test({
name: "[channel] edit channel permission overwrites",
async fn() {
await ifItFailsBlameWolf({
name: "Discordeno-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
});
},
...defaultTestOptions,
});

View File

@@ -1,474 +0,0 @@
import { botId } from "../../src/bot.ts";
import { cache } from "../../src/cache.ts";
import { cloneChannel } from "../../src/helpers/channels/clone_channel.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
import { bigintToSnowflake } from "../../src/util/bigint.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(options: CreateGuildChannel, useGetter = false, reason?: string) {
const channel = await createChannel(tempData.guildId, options);
const cloned = useGetter ? await channel.clone(reason) : await cloneChannel(channel.id, reason);
//Assertations
assertExists(cloned);
assertEquals(cloned.type, channel.type);
// Delay the execution to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => cache.channels.has(cloned.id));
if (!cache.channels.has(cloned.id)) {
throw new Error(`The channel seemed to be cloned but was not cached.`);
}
if (channel.topic && cloned.topic !== channel.topic) {
throw new Error("The clone was supposed to have a topic but it does not appear to be the same topic.");
}
if (channel.bitrate && cloned.bitrate !== channel.bitrate) {
throw new Error("The clone was supposed to have a bitrate but it does not appear to be the same bitrate.");
}
if (channel.permissionOverwrites && cloned.permissionOverwrites?.length !== channel.permissionOverwrites.length) {
throw new Error(
"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" });
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel w/reason",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, false, "w/reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new category channel",
async fn() {
await ifItFailsBlameWolf({
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildCategory,
});
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new category channel w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildCategory,
},
false,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel",
async fn() {
await ifItFailsBlameWolf({
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
});
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
},
false,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel with a bitrate",
async fn() {
await ifItFailsBlameWolf({
name: "discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
bitrate: 32000,
});
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel with a bitrate w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
bitrate: 32000,
},
false,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel with a user limit",
async fn() {
await ifItFailsBlameWolf({
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
userLimit: 32,
});
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new voice channel with a user limit w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
userLimit: 32,
},
false,
"w/reason"
);
},
...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,
});
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel with a rate limit per user w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
rateLimitPerUser: 2423,
},
false,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel with NSFW",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true });
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel with NSFW w/reason",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true }, false, "w/reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel with permission overwrites",
async fn() {
await ifItFailsBlameWolf({
name: "Discordeno-clone-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
});
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone a new text channel with permission overwrites",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
},
false,
"w/reason"
);
},
...defaultTestOptions,
});
// GETTERS
Deno.test({
name: "[channel] clone() a new text channel",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, true);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new text channel w/reason",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, true, "w/reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new category channel",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildCategory,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new category channel w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildCategory,
},
true,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new voice channel",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new voice channel w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
},
true,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new voice channel with a bitrate",
async fn() {
await ifItFailsBlameWolf(
{
name: "discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
bitrate: 32000,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new voice channel with a bitrate w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
bitrate: 32000,
},
true,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new voice channel with a user limit",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
userLimit: 32,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new voice channel with a user limit w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
type: DiscordChannelTypes.GuildVoice,
userLimit: 32,
},
true,
"w/reason"
);
},
...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,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new text channel with a rate limit per user w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
rateLimitPerUser: 2423,
},
true,
"w/reason"
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new text channel with NSFW",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true }, true);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new text channel with NSFW w/reason",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-clone-test", nsfw: true }, true, "w/reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new text channel with permission overwrites",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] clone() a new text channel with permission overwrites w/reason",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-clone-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
},
true,
"w/reason"
);
},
...defaultTestOptions,
});

View File

@@ -1,169 +0,0 @@
import { botId } from "../../src/bot.ts";
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
import { bigintToSnowflake } from "../../src/util/bigint.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
const channel = await createChannel(tempData.guildId, options);
// Assertions
assertExists(channel);
assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText);
if (save) tempData.channelId = channel.id;
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
if (options.topic && channel.topic !== options.topic) {
throw new Error("The channel was supposed to have a topic but it does not appear to be the same topic.");
}
if (options.bitrate && channel.bitrate !== options.bitrate) {
throw new Error("The channel was supposed to have a bitrate but it does not appear to be the same bitrate.");
}
if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) {
throw new Error(
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
);
}
}
Deno.test({
name: "[channel] create a new text channel",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-test" }, true);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] create a new category channel",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-test",
type: DiscordChannelTypes.GuildCategory,
},
true
);
},
...defaultTestOptions,
});
// Deno.test({
// name: "[channel] create a new news channel",
// async fn() {
// await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_NEWS}, true);
// },
// ...defaultTestOptions,
// });
// Deno.test({
// name: "[channel] create a new store channel",
// async fn() {
// await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_STORE}, true);
// },
// ...defaultTestOptions,
// });
Deno.test({
name: "[channel] create a new voice channel",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-test",
type: DiscordChannelTypes.GuildVoice,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] create a new voice channel with a bitrate",
async fn() {
await ifItFailsBlameWolf(
{
name: "discordeno-test",
type: DiscordChannelTypes.GuildVoice,
bitrate: 32000,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] create a new voice channel with a user limit",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-test",
type: DiscordChannelTypes.GuildVoice,
userLimit: 32,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] create a new text channel with a rate limit per user",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-test",
rateLimitPerUser: 2423,
},
true
);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] create a new text channel with NSFW",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-test", nsfw: true }, true);
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] create a new text channel with permission overwrites",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
},
true
);
},
...defaultTestOptions,
});
// TODO: Need to validate tests for these options
// /** Sorting position of the channel */
// position?: number;

View File

@@ -1,57 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts";
import { delayUntil } from "../util/delay_until.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 delayUntil(3000, () => cache.channels.has(channel.id));
// 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(channel.id);
// wait 5 seconds to give it time for CHANNEL_DELETE event
await delayUntil(3000, () => !cache.channels.has(channel.id));
// 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 delayUntil(10000, () => cache.channels.has(channel.id));
// 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(channel.id, "with a reason");
// wait 5 seconds to give it time for CHANNEL_DELETE event
await delayUntil(10000, () => !cache.channels.has(channel.id));
// 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,
});

View File

@@ -1,61 +0,0 @@
import { botId } from "../../src/bot.ts";
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
import { bigintToSnowflake } from "../../src/util/bigint.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) {
const channel = await createChannel(tempData.guildId, options);
// Assertions
assertExists(channel);
assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) {
throw new Error(
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
);
}
await deleteChannelOverwrite(channel.guildId, channel.id, botId);
await delayUntil(10000, () => cache.channels.get(channel.id)?.permissionOverwrites?.length === 0);
if (cache.channels.get(channel.id)?.permissionOverwrites?.length !== 0) {
throw new Error("The channel permission overwrite was supposed to be deleted but it does not appear to be.");
}
}
Deno.test({
name: "[channel] create a new text channel with permission overwrites",
async fn() {
await ifItFailsBlameWolf(
{
name: "Discordeno-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
},
true
);
},
...defaultTestOptions,
});

View File

@@ -1,69 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { delayUntil } from "../util/delay_until.ts";
import { editChannel } from "../../src/helpers/channels/edit_channel.ts";
import { assertEquals } from "../deps.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
// Create the necessary channels
const channel = await createChannel(tempData.guildId, {
name: "edit-channel",
});
// wait 5 seconds to give it time for CHANNEL_CREATE event
await delayUntil(3000, () => cache.channels.has(channel.id));
// 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.");
}
// Edit the channel now
if (type === "raw") {
await editChannel(
channel.id,
{
name: "new-name",
},
reason
);
} else {
await channel.edit({
name: "new-name",
});
}
// wait 5 seconds to give it time for CHANNEL_UPDATE event
await delayUntil(3000, () => cache.channels.get(channel.id)?.name === "new-name");
assertEquals(cache.channels.get(channel.id)?.name, "new-name");
}
Deno.test({
name: "[channel] edit a channel without a reason.",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] edit a channel with a reason.",
async fn() {
await ifItFailsBlameWolf("raw", "with a reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] channel.edit() without a reason.",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[channel] channel.edit() with a reason.",
async fn() {
await ifItFailsBlameWolf("getter", "with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,72 +0,0 @@
import { botId } from "../../src/bot.ts";
import { cache } from "../../src/cache.ts";
import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
import { bigintToSnowflake } from "../../src/util/bigint.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(options: CreateGuildChannel) {
const channel = await createChannel(tempData.guildId, options);
// Assertions
assertExists(channel);
assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) {
throw new Error(
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
);
}
await editChannelOverwrite(channel.guildId, channel.id, botId, {
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL", "ADD_REACTIONS"],
deny: [],
});
await delayUntil(10000, () =>
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites || [], [
"VIEW_CHANNEL",
"ADD_REACTIONS",
])
);
assertEquals(
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites || [], [
"VIEW_CHANNEL",
"ADD_REACTIONS",
]),
true
);
}
Deno.test({
name: "[channel] edit channel permission overwrites",
async fn() {
await ifItFailsBlameWolf({
name: "Discordeno-test",
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
});
},
...defaultTestOptions,
});

View File

@@ -1,31 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { getChannel } from "../../src/helpers/channels/get_channel.ts";
import { assertEquals } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[channel] get a channel",
async fn() {
// Create the necessary channels
const channel = await createChannel(tempData.guildId, {
name: "get-channel",
});
// wait 5 seconds to give it time for CHANNEL_CREATE event
await delayUntil(3000, () => cache.channels.has(channel.id));
// 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.");
}
cache.channels.delete(channel.id);
// Delete the channel now without a reason
await getChannel(channel.id);
await delayUntil(3000, () => cache.channels.has(channel.id));
assertEquals(cache.channels.has(channel.id), true);
},
...defaultTestOptions,
});

View File

@@ -1,19 +0,0 @@
import { cache } from "../../src/cache.ts";
import { getChannels } from "../../src/helpers/channels/get_channels.ts";
import { assertEquals } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[channel] get channels.",
async fn() {
cache.channels.clear();
// Delete the channel now without a reason
await getChannels(tempData.guildId);
await delayUntil(3000, () => cache.channels.size > 0);
assertEquals(cache.channels.size > 0, true);
},
...defaultTestOptions,
});

View File

@@ -1,40 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { getPins } from "../../src/helpers/channels/get_pins.ts";
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[channel] get pins.",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: "pins-channel",
});
// Assertions
assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const message = await sendMessage(tempData.channelId, "Hello World!");
const secondMessage = await sendMessage(tempData.channelId, "Goodbye World!");
// 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 message.pin();
await secondMessage.pin();
const pins = await getPins(tempData.channelId);
assertEquals(pins.length, 2);
},
...defaultTestOptions,
});

View File

@@ -1,58 +0,0 @@
import { botId } from "../../src/bot.ts";
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { bigintToSnowflake } from "../../src/util/bigint.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[channel] is channel synced.",
async fn() {
const category = await createChannel(tempData.guildId, {
name: "synced-category",
type: DiscordChannelTypes.GuildCategory,
permissionOverwrites: [
{
id: bigintToSnowflake(botId),
type: DiscordOverwriteTypes.Member,
allow: ["VIEW_CHANNEL"],
deny: [],
},
],
});
// Assertions
assertExists(category);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const channel = await createChannel(tempData.guildId, {
name: "synced-channel",
parentId: category.id,
});
// Assertions
assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const isSynced = await isChannelSynced(channel.id);
assertEquals(isSynced, true);
},
...defaultTestOptions,
});

View File

@@ -1,28 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
import { assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[channel] is typing.",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: "typing-channel",
});
// Assertions
assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
await startTyping(channel.id);
},
...defaultTestOptions,
});

View File

@@ -1,56 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { swapChannels } from "../../src/helpers/channels/swap_channels.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[channel] swap channels",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: "channel-1",
});
// Assertions
assertExists(channel);
const secondChannel = await createChannel(tempData.guildId, {
name: "channel-2",
});
// Assertions
assertExists(channel);
// 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));
if (!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, [
{
id: channel.id.toString(),
position: secondChannel.position!,
},
{
id: secondChannel.id.toString(),
position: channel.position!,
},
]);
// 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
);
assertEquals(cache.channels.get(channel.id)?.position, secondChannel.position);
assertEquals(cache.channels.get(secondChannel.id)?.position, channel.position);
},
...defaultTestOptions,
});

View File

@@ -3,4 +3,4 @@ export {
assertEquals,
assertExists,
assertThrows,
} from "https://deno.land/std@0.97.0/testing/asserts.ts";
} from "https://deno.land/std@0.113.0/testing/asserts.ts";

View File

@@ -1,13 +0,0 @@
import { defaultTestOptions } from "../ws/start_bot.ts";
import { assertEquals } from "../deps.ts";
import { getDiscoveryCategories } from "../../src/helpers/discovery/get_discovery_categories.ts";
Deno.test({
name: "[discovery] get categories",
async fn() {
const categories = await getDiscoveryCategories();
assertEquals(categories.size > 0, true);
},
...defaultTestOptions,
});

View File

@@ -1,13 +0,0 @@
import { defaultTestOptions } from "../ws/start_bot.ts";
import { assertEquals } from "../deps.ts";
import { validDiscoveryTerm } from "../../src/helpers/discovery/valid_discovery_term.ts";
Deno.test({
name: "[discovery] get categories",
async fn() {
const valid = await validDiscoveryTerm("Bots");
assertEquals(valid, true);
},
...defaultTestOptions,
});

View File

@@ -1,28 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts";
import { delayUntil } from "../util/delay_until.ts";
Deno.test({
name: "[emoji] create an emoji",
async fn() {
const emoji = await createEmoji(
tempData.guildId,
"blamewolf",
"https://cdn.discordapp.com/emojis/814955268123000832.png",
{
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
}
);
assertExists(emoji);
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!));
assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!), true);
},
...defaultTestOptions,
});

View File

@@ -1,45 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts";
import { delayUntil } from "../util/delay_until.ts";
import { deleteEmoji } from "../../src/helpers/emojis/delete_emoji.ts";
async function ifItFailsBlameWolf(reason?: string) {
const emoji = await createEmoji(
tempData.guildId,
"blamewolf",
"https://cdn.discordapp.com/emojis/814955268123000832.png",
{
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
}
);
assertExists(emoji);
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!));
await deleteEmoji(tempData.guildId, emoji.id!, reason);
await delayUntil(10000, () => !cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!));
assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!), false);
}
Deno.test({
name: "[emoji] delete an emoji without a reason",
async fn() {
await ifItFailsBlameWolf();
},
...defaultTestOptions,
});
Deno.test({
name: "[emoji] delete an emoji with a reason",
async fn() {
await ifItFailsBlameWolf("with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,38 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts";
import { delayUntil } from "../util/delay_until.ts";
import { editEmoji } from "../../src/helpers/emojis/edit_emoji.ts";
Deno.test({
name: "[emoji] edit an emoji",
async fn() {
const emoji = await createEmoji(
tempData.guildId,
"blamewolf",
"https://cdn.discordapp.com/emojis/814955268123000832.png",
{
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
}
);
assertExists(emoji);
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!));
await editEmoji(tempData.guildId, emoji.id!, {
name: "blamewolf_infinite",
});
await delayUntil(
10000,
() => cache.guilds.get(tempData.guildId)?.emojis?.get(emoji.id!)?.name === "blamewolf_infinite"
);
assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.get(emoji.id!)?.name, "blamewolf_infinite");
},
...defaultTestOptions,
});

View File

@@ -1,35 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts";
import { delayUntil } from "../util/delay_until.ts";
import { getEmoji } from "../../src/helpers/emojis/get_emoji.ts";
Deno.test({
name: "[emoji] get an emoji",
async fn() {
const emoji = await createEmoji(
tempData.guildId,
"blamewolf",
"https://cdn.discordapp.com/emojis/814955268123000832.png",
{
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
}
);
assertExists(emoji);
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!));
cache.guilds.get(tempData.guildId)?.emojis?.delete(emoji.id!);
await getEmoji(tempData.guildId, emoji.id!);
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!));
assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.has(emoji.id!), true);
},
...defaultTestOptions,
});

View File

@@ -1,19 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { delayUntil } from "../util/delay_until.ts";
import { getEmojis } from "../../src/helpers/mod.ts";
Deno.test({
name: "[emoji] get emojis",
async fn() {
cache.guilds.get(tempData.guildId)?.emojis?.clear();
await getEmojis(tempData.guildId);
await delayUntil(10000, () => (cache.guilds.get(tempData.guildId)?.emojis?.size || 0) > 0);
assertEquals((cache.guilds.get(tempData.guildId)?.emojis?.size || 0) > 0, true);
},
...defaultTestOptions,
});

View File

@@ -1,28 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { createGuild } from "../../src/helpers/guilds/create_guild.ts";
import { delayUntil } from "../util/delay_until.ts";
Deno.test({
name: "[guild] create a new guild",
async fn() {
const guild = await createGuild({
name: "Discordeno Test",
});
// Assertions
assertExists(guild);
assertExists(guild.id);
tempData.guildId = guild.id;
// Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed
await delayUntil(10000, () => cache.guilds.has(guild.id));
if (!cache.guilds.has(guild.id)) {
throw new Error(`The guild seemed to be created but it was not cached. ${JSON.stringify(guild)}`);
}
},
...defaultTestOptions,
});

View File

@@ -1,24 +0,0 @@
import { cache } from "../../src/cache.ts";
import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[guild] delete a guild",
async fn() {
if (!tempData.guildId) {
throw new Error("The guild id was not available to be deleted.");
}
if (!cache.guilds.has(tempData.guildId)) {
throw new Error("The guild was not cached so impossible to delete.");
}
await deleteGuild(tempData.guildId);
await delayUntil(10000, () => !cache.guilds.has(tempData.guildId));
if (cache.guilds.has(tempData.guildId)) {
throw new Error("The guild was not able to be deleted.");
}
},
...defaultTestOptions,
});

View File

@@ -1,39 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
import { getInvite } from "../../src/helpers/invites/get_invite.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[invite] create invite",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: "invite-channel",
});
// Assertions
assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const invite = await createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: false,
});
// Assertions
assertExists(invite);
assertEquals((await getInvite(invite.code)) !== undefined, true);
},
...defaultTestOptions,
});

View File

@@ -1,42 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
import { deleteInvite } from "../../src/helpers/invites/delete_invite.ts";
import { getChannelInvites } from "../../src/helpers/invites/get_channel_invites.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[invite] delete invite",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: "invite-channel",
});
// Assertions
assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const invite = await createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: false,
});
// Assertions
assertExists(invite);
await deleteInvite(channel.id, invite.code);
assertEquals((await getChannelInvites(channel.id))?.size, 0);
},
...defaultTestOptions,
});

View File

@@ -1,49 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
import { getChannelInvites } from "../../src/helpers/invites/get_channel_invites.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[invite] get channel invites",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: "invite-channel",
});
// Assertions
assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const invite = await createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: false,
});
// Assertions
assertExists(invite);
const secondInvite = await createInvite(channel.id, {
maxAge: 32400,
maxUses: 5,
temporary: true,
unique: true,
});
// Assertions
assertExists(secondInvite);
assertEquals((await getChannelInvites(channel.id))?.size, 2);
},
...defaultTestOptions,
});

View File

@@ -1,43 +0,0 @@
import { cache } from "../../src/cache.ts";
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
import { getInvite } from "../../src/helpers/invites/get_invite.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
Deno.test({
name: "[invite] get invite",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: "invite-channel",
});
// Assertions
assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => 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.");
}
const invite = await createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: false,
});
// Assertions
assertExists(invite);
const fetchedInvite = await getInvite(invite.code);
assertExists(fetchedInvite);
assertEquals(fetchedInvite.code, invite.code);
},
...defaultTestOptions,
});

View File

@@ -1,33 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals } from "../deps.ts";
import { getInvites } from "../../src/helpers/invites/get_invites.ts";
import { cache } from "../../src/cache.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw") {
let invites;
if (type === "raw") {
invites = await getInvites(tempData.guildId);
} else {
const guild = cache.guilds.get(tempData.guildId);
invites = await guild?.invites();
}
assertEquals((invites?.size || 0) >= 0, true);
}
Deno.test({
name: "[invite] get invites",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[invite] guild.invites()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});

View File

@@ -1,25 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { searchMembers } from "../../src/helpers/members/search_members.ts";
import { botId, cache } from "../../mod.ts";
async function ifItFailsBlameWolf() {
const botMember = cache.members.get(botId);
// Assertions
assertExists(botMember);
const foundMembers = await searchMembers(tempData.guildId, botMember!.username.substring(0, 4), {
limit: 1,
});
assertEquals(foundMembers.size, 1);
}
Deno.test({
name: "[members] search guild members",
async fn() {
await ifItFailsBlameWolf();
},
...defaultTestOptions,
});

View File

@@ -1,83 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
import { addReaction } from "../../src/helpers/messages/add_reaction.ts";
import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts";
import { delayUntil } from "../util/delay_until.ts";
import { Reaction } from "../../src/types/messages/reaction.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
let emojiId = "❤";
if (custom) {
emojiId = `<:blamewolf:${
(
await createEmoji(tempData.guildId, "blamewolf", "https://cdn.discordapp.com/emojis/814955268123000832.png", {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
})
).id
}>`;
}
if (type === "raw") {
await addReaction(message.channelId, message.id, emojiId);
} else {
await message.addReaction(emojiId);
}
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 1);
assertEquals(
await cache.messages
.get(message.id)
?.reactions?.filter((reaction: Reaction) => reaction.emoji?.name === (custom ? "blamewolf" : "❤")).length,
1
);
}
Deno.test({
name: "[message] add a reaction",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.addReaction()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] add a custom reaction",
async fn() {
await ifItFailsBlameWolf("raw", true);
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.addReaction() with a custom reaction",
async fn() {
await ifItFailsBlameWolf("getter", true);
},
...defaultTestOptions,
});

View File

@@ -1,122 +0,0 @@
import { addReactions, cache, createEmoji, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false, ordered = false) {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
let emojiIds = ["❤", "😃"];
if (custom) {
emojiIds = [
`<:blamewolf:${
(
await createEmoji(tempData.guildId, "blamewolf", "https://cdn.discordapp.com/emojis/814955268123000832.png", {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
})
).id
}>`,
`<:blamewolf2:${
(
await createEmoji(
tempData.guildId,
"blamewolf2",
"https://cdn.discordapp.com/emojis/814955268123000832.png",
{
name: "blamewolf2",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
}
)
).id
}>`,
];
}
if (type === "raw") {
await addReactions(message.channelId, message.id, emojiIds, ordered);
} else {
await message.addReactions(emojiIds, ordered);
}
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 2);
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 2);
}
Deno.test({
name: "[message] add reactions",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.addReactions()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] add custom reactions",
async fn() {
await ifItFailsBlameWolf("raw", true);
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.addReactions() with custom reactions",
async fn() {
await ifItFailsBlameWolf("getter", true);
},
...defaultTestOptions,
});
Deno.test({
name: "[message] add ordered reactions",
async fn() {
await ifItFailsBlameWolf("raw", false, true);
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.addReactions() ordered",
async fn() {
await ifItFailsBlameWolf("getter", false, true);
},
...defaultTestOptions,
});
Deno.test({
name: "[message] add ordered custom reactions",
async fn() {
await ifItFailsBlameWolf("raw", true, true);
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.addReactions() with ordered custom reactions",
async fn() {
await ifItFailsBlameWolf("getter", true, true);
},
...defaultTestOptions,
});

View File

@@ -1,136 +0,0 @@
import { cache } from "../../src/cache.ts";
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", content: "string" | "embed" | "reply" = "string") {
const channel = cache.channels.get(tempData.channelId);
assertExists(channel);
// deno-lint-ignore no-explicit-any
let messageContent: any = "Hello World!";
let secondMessageId = undefined;
if (content === "embed") {
messageContent = {
content: "Hello World!",
embed: {
title: "Hello, Embed!",
description: "This is an embedded message.",
color: 0x41ebf4,
fields: [],
},
};
} else if (content === "reply") {
const message = await sendMessage(channel!.id, "Test Message");
assertExists(message);
// Wait few seconds for the channel create event to arrive and cache it
await delayUntil(10000, () => cache.messages.has(message.id));
secondMessageId = message.id;
messageContent = {
content: "Hi",
allowedMentions: {
repliedUser: true,
},
messageReference: {
messageId: message.id,
channelId: channel?.id,
guildId: tempData.guildId,
failIfNotExists: true,
},
};
}
const message = type === "raw" ? await sendMessage(channel!.id, messageContent) : await channel?.send(messageContent);
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message!.id));
if (!cache.messages.has(message!.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
if (content === "string") {
assertEquals(cache.messages.get(message!.id)?.content, messageContent);
} else if (content === "embed") {
assertEquals(cache.messages.get(message!.id)?.embeds?.length, 1);
} else {
assertEquals(cache.messages.get(message!.id)?.messageReference?.messageId, secondMessageId);
}
}
Deno.test({
name: "[message] send a new message",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] channel.send()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] send a new message with an embed",
async fn() {
await ifItFailsBlameWolf("raw", "embed");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] channel.send() with an embed",
async fn() {
await ifItFailsBlameWolf("getter", "embed");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] send a message with a reply",
async fn() {
await ifItFailsBlameWolf("raw", "reply");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] channel.send() with a reply",
async fn() {
await ifItFailsBlameWolf("getter", "reply");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.reply()",
async fn() {
const channel = cache.channels.get(tempData.channelId);
assertExists(channel);
const message = await sendMessage(channel!.id, "Test Message");
assertExists(message);
// Wait few seconds for the channel create event to arrive and cache it
await delayUntil(10000, () => cache.messages.has(message!.id));
const reply = await message.reply("Welcome!");
await delayUntil(10000, () => cache.messages.has(reply!.id));
if (!cache.messages.has(reply!.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
assertEquals(cache.messages.get(reply.id)?.messageReference?.messageId, message.id);
},
...defaultTestOptions,
});

View File

@@ -1,65 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
import { deleteMessage } from "../../src/helpers/messages/delete_message.ts";
import { delayUntil } from "../util/delay_until.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Delete the message now
if (type === "raw") {
await deleteMessage(tempData.channelId, message.id, reason);
} else {
await message.delete(reason);
}
// Wait 5 seconds to give it time for MESSAGE_DELETE event
await delayUntil(10000, () => !cache.messages.has(message.id));
// Make sure it is gone from cache
if (cache.messages.has(message.id)) {
throw new Error("The message should have been deleted but it is still in cache.");
}
}
Deno.test({
name: "[message] delete a message without a reason.",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] delete a message with a reason.",
async fn() {
await ifItFailsBlameWolf("raw", "with a reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.delete() without a reason.",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.delete() with a reason.",
async fn() {
await ifItFailsBlameWolf("getter", "with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,54 +0,0 @@
import { cache, deleteMessages, sendMessage } from "../../mod.ts";
import { assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(reason?: string) {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
const secondMessage = await sendMessage(tempData.channelId, "Hello World 2!");
// Assertions
assertExists(secondMessage);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(secondMessage.id));
// Make sure the message was created.
if (!cache.messages.has(secondMessage.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Delete the message now
await deleteMessages(tempData.channelId, [message.id, secondMessage.id], reason);
// Wait 5 seconds to give it time for MESSAGE_DELETE event
await delayUntil(10000, () => !cache.messages.has(message.id) && !cache.messages.has(secondMessage.id));
// Make sure it is gone from cache
if (cache.messages.has(message.id) || cache.messages.has(secondMessage.id)) {
throw new Error("The message should have been deleted but it is still in cache.");
}
}
Deno.test({
name: "[message] delete messages without a reason.",
async fn() {
await ifItFailsBlameWolf();
},
...defaultTestOptions,
});
Deno.test({
name: "[message] delete messages with a reason.",
async fn() {
await ifItFailsBlameWolf("with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,47 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
import { editMessage } from "../../src/helpers/messages/edit_message.ts";
import { delayUntil } from "../util/delay_until.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw") {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Edit the message now
if (type === "raw") {
await editMessage(message.channelId, message.id, "Goodbye World!");
} else {
await message.edit("Goodbye World!");
}
// Wait 5 seconds to give it time for MESSAGE_UPDATE event
await delayUntil(10000, () => cache.messages.get(message.id)?.content === "Goodbye World!");
// Make sure it has been modified in cache
assertEquals(cache.messages.get(message.id)?.content, "Goodbye World!");
}
Deno.test({
name: "[message] edit a message",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.edit()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});

View File

@@ -1,27 +0,0 @@
import { cache, getMessage, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
Deno.test({
name: "[message] fetch a message",
async fn() {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Fetch the message
const fetchedMessage = await getMessage(tempData.channelId, message.id);
// Check if getMessage has worked
assertEquals(fetchedMessage.id, message.id);
assertEquals(fetchedMessage.content, message.content);
},
...defaultTestOptions,
});

View File

@@ -1,41 +0,0 @@
import { cache, getMessages, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
Deno.test({
name: "[message] fetch messages",
async fn() {
const message = await sendMessage(tempData.channelId, "Hello World!");
const secondMessage = await sendMessage(tempData.channelId, "Hello World 2!");
const thirdMessage = await sendMessage(tempData.channelId, "Hello World 3!");
// Assertions
assertExists(message);
assertExists(secondMessage);
assertExists(thirdMessage);
// 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) && cache.messages.has(thirdMessage.id)
);
// Make sure the message was created.
if (
!cache.messages.has(message.id) ||
!cache.messages.has(secondMessage.id) ||
!cache.messages.has(thirdMessage.id)
) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Fetch the messages
const fetchedMessages = await getMessages(tempData.channelId, {
after: message.id,
limit: 2,
});
// Check if getMessages has worked
assertEquals(fetchedMessages?.length, 2);
},
...defaultTestOptions,
});

View File

@@ -1,28 +0,0 @@
import { addReaction, cache, getReactions, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
Deno.test({
name: "[message] fetch reactions",
async fn() {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
await addReaction(message.channelId, message.id, "❤");
// Fetch the message
const fetchedReactions = await getReactions(tempData.channelId, message.id, "❤");
// Check if getMessage has worked
assertEquals(fetchedReactions.size, 1);
},
...defaultTestOptions,
});

View File

@@ -1,44 +0,0 @@
import { cache, getPins, pin, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { DiscordenoMessage } from "../../src/structures/message.ts";
import { delayUntil } from "../util/delay_until.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw") {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
if (type === "raw") {
await pin(message.channelId, message.id);
} else {
await message.pin();
}
const pins = await getPins(tempData.channelId);
assertEquals(pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, 1);
}
Deno.test({
name: "[message] pin a message",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.pin()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});

View File

@@ -1,53 +0,0 @@
import { addReactions, cache, removeAllReactions, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw") {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Add reactions to the message
await addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]);
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 3);
// Be sure that the message has the reactions
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 3);
if (type === "raw") {
await removeAllReactions(message.channelId, message.id);
} else {
await message.removeAllReactions();
}
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions === undefined);
// Check if the reactions has been deleted
assertEquals(await cache.messages.get(message.id)?.reactions, undefined);
}
Deno.test({
name: "[message] remove all reactions",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.removeAllReactions()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});

View File

@@ -1,69 +0,0 @@
import { addReaction, cache, removeReaction, sendMessage } from "../../mod.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", user = false) {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Add reactions to the message
await addReaction(message.channelId, message.id, "❤");
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 1);
// Be sure that the message has the reactions
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1);
if (type === "raw") {
await removeReaction(message.channelId, message.id, "❤", user ? { userId: message.authorId } : undefined);
} else {
await message.removeReaction("❤", user ? message.authorId : undefined);
}
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions === undefined);
// Check if the reactions has been deleted
assertEquals(await cache.messages.get(message.id)?.reactions, undefined);
}
Deno.test({
name: "[message] remove a reaction",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.removeReaction()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] remove a user reaction",
async fn() {
await ifItFailsBlameWolf("raw", true);
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.removeReaction with user",
async fn() {
await ifItFailsBlameWolf("getter", true);
},
...defaultTestOptions,
});

View File

@@ -1,53 +0,0 @@
import { addReaction, cache, removeReactionEmoji, sendMessage } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw") {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
// Make sure the message was created.
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
// Add reactions to the message
await addReaction(message.channelId, message.id, "❤");
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 1);
// Be sure that the message has the reactions
assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1);
if (type === "raw") {
await removeReactionEmoji(message.channelId, message.id, "❤");
} else {
await message.removeReactionEmoji("❤");
}
// Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed
await delayUntil(10000, () => cache.messages.get(message.id)?.reactions === undefined);
// Check if the reactions has been deleted
assertEquals(cache.messages.get(message.id)?.reactions, undefined);
}
Deno.test({
name: "[message] remove a reaction emoji",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[message] message.removeReactionEmoji()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});

View File

@@ -1,52 +0,0 @@
import { cache, getPins, pin, sendMessage, unpin } from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { DiscordenoMessage } from "../../src/structures/message.ts";
import { delayUntil } from "../util/delay_until.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw") {
const message = await sendMessage(tempData.channelId, "Hello World!");
// Assertions
assertExists(message);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id));
if (!cache.messages.has(message.id)) {
throw new Error("The message seemed to be sent but it was not cached.");
}
await pin(message.channelId, message.id);
// Be sure that the pin got added
const pins = await getPins(tempData.channelId);
assertEquals(pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, 1);
if (type === "raw") {
await unpin(message.channelId, message.id);
} else {
//await message.unpin();
}
// Be sure that the pin got removed
const removedPins = await getPins(tempData.channelId);
assertEquals(removedPins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, 0);
}
Deno.test({
name: "[message] unpin a message",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
/*
Deno.test({
name: "[message] message.unpin()",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});*/

View File

@@ -1,65 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { delayUntil } from "../util/delay_until.ts";
import { addRole } from "../../src/helpers/roles/add_role.ts";
import { createRole } from "../../src/helpers/roles/create_role.ts";
import { botId } from "../../src/bot.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
const role = await createRole(tempData.guildId, {
name: "hoti",
});
assertExists(role);
// Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id));
if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) {
throw new Error(`The role seemed to be created but it was not cached.`);
}
if (type === "raw") {
await addRole(tempData.guildId, botId, role.id, reason);
} else {
await cache.members.get(botId)!.addRole(tempData.guildId, role.id, reason);
}
// Delay the execution by 5 seconds to allow GUILD_MEMBER_UPDATE event to be processed
await delayUntil(10000, () => cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id));
assertEquals(cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id), true);
}
Deno.test({
name: "[role] add a role without a reason",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[role] add a role with a reason",
async fn() {
await ifItFailsBlameWolf("raw", "with a reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[role] member.addRole() without a reason",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[role] member.addRole() with a reason",
async fn() {
await ifItFailsBlameWolf("getter", "with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,40 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { delayUntil } from "../util/delay_until.ts";
import { createRole } from "../../src/helpers/roles/create_role.ts";
async function ifItFailsBlameWolf(reason?: string) {
const role = await createRole(
tempData.guildId,
{
name: "hoti",
},
reason
);
assertExists(role);
// Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id));
if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) {
throw new Error(`The role seemed to be created but it was not cached.`);
}
}
Deno.test({
name: "[role] create a role without a reason",
async fn() {
await ifItFailsBlameWolf();
},
...defaultTestOptions,
});
Deno.test({
name: "[role] create a role with a reason",
async fn() {
await ifItFailsBlameWolf("with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,50 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { delayUntil } from "../util/delay_until.ts";
import { createRole } from "../../src/helpers/roles/create_role.ts";
import { deleteRole } from "../../src/helpers/roles/delete_role.ts";
async function ifItFailsBlameWolf(reason?: string) {
const role = await createRole(
tempData.guildId,
{
name: "hoti",
},
reason
);
assertExists(role);
// Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id));
if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) {
throw new Error(`The role seemed to be created but it was not cached.`);
}
await deleteRole(tempData.guildId, role.id);
// Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed
await delayUntil(10000, () => !cache.guilds.get(tempData.guildId)?.roles.has(role.id));
if (cache.guilds.get(tempData.guildId)?.roles.has(role.id)) {
throw new Error(`The role should have been deleted but it is still in cache.`);
}
}
Deno.test({
name: "[role] delete a role without a reason",
async fn() {
await ifItFailsBlameWolf();
},
...defaultTestOptions,
});
Deno.test({
name: "[role] delete a role with a reason",
async fn() {
await ifItFailsBlameWolf("with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,34 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { delayUntil } from "../util/delay_until.ts";
import { createRole } from "../../src/helpers/roles/create_role.ts";
import { editRole } from "../../src/helpers/roles/edit_role.ts";
Deno.test({
name: "[role] edit a role",
async fn() {
const role = await createRole(tempData.guildId, {
name: "hoti",
});
assertExists(role);
// Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id));
if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) {
throw new Error(`The role seemed to be created but it was not cached.`);
}
await editRole(tempData.guildId, role.id, {
name: "#rememberAyntee",
});
// Delay the execution by 5 seconds to allow GUILD_ROLE_UPDATE event to be processed
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.get(role.id)?.name === "#rememberAyntee");
assertEquals(cache.guilds.get(tempData.guildId)?.roles.get(role.id)?.name === "#rememberAyntee", true);
},
...defaultTestOptions,
});

View File

@@ -1,20 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { delayUntil } from "../util/delay_until.ts";
import { botId } from "../../src/bot.ts";
import { getRoles } from "../../src/helpers/roles/get_roles.ts";
Deno.test({
name: "[role] get roles",
async fn() {
cache.guilds.get(tempData.guildId)?.roles.clear();
await getRoles(tempData.guildId);
await delayUntil(10000, () => cache.members.get(botId)?.guilds.get(tempData.guildId).roles.length > 0);
assertEquals(cache.members.get(botId)?.guilds.get(tempData.guildId).roles.length > 0, true);
},
...defaultTestOptions,
});

View File

@@ -1,75 +0,0 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { delayUntil } from "../util/delay_until.ts";
import { addRole } from "../../src/helpers/roles/add_role.ts";
import { createRole } from "../../src/helpers/roles/create_role.ts";
import { botId } from "../../src/bot.ts";
import { removeRole } from "../../src/helpers/roles/remove_role.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
const role = await createRole(tempData.guildId, {
name: "hoti",
});
assertExists(role);
// Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id));
if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id)) {
throw new Error(`The role seemed to be created but it was not cached.`);
}
if (type === "raw") {
await addRole(tempData.guildId, botId, role.id, reason);
} else {
await cache.members.get(botId)!.addRole(tempData.guildId, role.id, reason);
}
// Delay the execution by 5 seconds to allow GUILD_MEMBER_UPDATE event to be processed
await delayUntil(10000, () => cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id));
if (type === "raw") {
await removeRole(tempData.guildId, botId, role.id, reason);
} else {
await cache.members.get(botId)!.removeRole(tempData.guildId, role.id, reason);
}
// Delay the execution by 5 seconds to allow GUILD_MEMBER_UPDATE event to be processed
await delayUntil(10000, () => !cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id));
assertEquals(cache.members.get(botId)?.guilds.get(tempData.guildId)!.roles.includes(role.id), false);
}
Deno.test({
name: "[role] remove a role without a reason",
async fn() {
await ifItFailsBlameWolf("raw");
},
...defaultTestOptions,
});
Deno.test({
name: "[role] remove a role with a reason",
async fn() {
await ifItFailsBlameWolf("raw", "with a reason");
},
...defaultTestOptions,
});
Deno.test({
name: "[role] member.removeRole() without a reason",
async fn() {
await ifItFailsBlameWolf("getter");
},
...defaultTestOptions,
});
Deno.test({
name: "[role] member.removeRole() with a reason",
async fn() {
await ifItFailsBlameWolf("getter", "with a reason");
},
...defaultTestOptions,
});

View File

@@ -1,14 +0,0 @@
// deno-lint-ignore require-await
export async function delayUntil(maxMs: number, isReady: () => boolean | undefined, timeoutTime = 100): Promise<void> {
const maxTime = Date.now() + maxMs;
function hackyFix(resolve: () => void) {
if (isReady() || Date.now() >= maxTime) {
resolve();
} else {
setTimeout(() => hackyFix(resolve), timeoutTime);
}
}
return new Promise((resolve) => hackyFix(resolve));
}

View File

@@ -1,274 +0,0 @@
import { ApplicationCommandOption } from "../../src/types/interactions/commands/application_command_option.ts";
import { ApplicationCommandOptionChoice } from "../../src/types/interactions/commands/application_command_option_choice.ts";
import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/commands/application_command_option_types.ts";
import { validateSlashCommands } from "../../src/util/utils.ts";
import { assertThrows } from "../deps.ts";
Deno.test({
name: "[utils] validateSlashCommands(): application command name",
fn() {
assertThrows(() =>
validateSlashCommands([
{
// The maximum length of the name of an application command is 32.
name: "a".repeat(33),
},
])
);
validateSlashCommands([
{
name: "workingname",
},
]);
},
});
Deno.test({
name: "[utils] validateSlashCommands(): application command description",
fn() {
assertThrows(() =>
// The maximum length of the description of an application command is 100.
validateSlashCommands([{ description: "a".repeat(101) }])
);
validateSlashCommands([
{
description: "valid description (should not throw)",
},
]);
},
});
Deno.test({
name: "[utils] validateSlashCommands(): number of options",
fn() {
const option = {
name: "optionname",
description: "The description of the option.",
type: DiscordApplicationCommandOptionTypes.String,
};
// The maximum number of options an application command can "accomodate" is 25.
const options: ApplicationCommandOption[] = Array(26).fill(option);
assertThrows(() => validateSlashCommands([{ options }]));
validateSlashCommands([
{
options: [option],
},
]);
},
});
Deno.test({
name: "[utils] validateSlashCommands(): number of option choices",
fn() {
const choice: ApplicationCommandOptionChoice = {
name: "choicename",
value: "choicevalue",
};
// The maximum number of application command option choices is 25.
const choices = Array(26).fill(choice);
assertThrows(() =>
validateSlashCommands([
{
options: [
{
name: "optionname",
type: DiscordApplicationCommandOptionTypes.String,
description: "The description of the option.",
choices,
},
],
},
])
);
validateSlashCommands([
{
options: [
{
name: "optionname",
type: DiscordApplicationCommandOptionTypes.String,
description: "The description of the option.",
choices: [choice],
},
],
},
]);
},
});
Deno.test({
name: "[utils] validateSlashCommands(): option name",
fn() {
assertThrows(() =>
validateSlashCommands([
{
options: [
{
// The maximum length of application command option name is 32.
name: "a".repeat(33),
description: "The description of the option.",
type: DiscordApplicationCommandOptionTypes.String,
},
],
},
])
);
validateSlashCommands([
{
options: [
{
name: "optionname",
description: "The description of the option.",
type: DiscordApplicationCommandOptionTypes.String,
},
],
},
]);
},
});
Deno.test({
name: "[utils] validateSlashCommands(): option description",
fn() {
assertThrows(() =>
validateSlashCommands([
{
options: [
{
name: "optionname",
// The maximum length of application command option description is 100.
description: "a".repeat(101),
type: DiscordApplicationCommandOptionTypes.String,
},
],
},
])
);
validateSlashCommands([
{
options: [
{
name: "optionname",
description: "The description of the option.",
type: DiscordApplicationCommandOptionTypes.String,
},
],
},
]);
},
});
Deno.test({
name: "[utils] validateSlashCommands(): the option choice name",
fn() {
assertThrows(() =>
validateSlashCommands([
{
options: [
{
name: "optionname",
choices: [
{
// The maximum length of an option choice name is 100.
name: "a".repeat(101),
value: "choicevalue",
},
],
description: "The description of the option.",
type: DiscordApplicationCommandOptionTypes.String,
},
],
},
])
);
validateSlashCommands([
{
options: [
{
name: "optionname",
description: "The description of the option.",
type: DiscordApplicationCommandOptionTypes.String,
choices: [
{
name: "choicename",
value: "choicevalue",
},
],
},
],
},
]);
},
});
Deno.test({
name: "[utils] validateSlashCommands(): option choice value",
fn() {
assertThrows(() =>
validateSlashCommands([
{
options: [
{
type: DiscordApplicationCommandOptionTypes.String,
description: "The description of the option.",
name: "optionname",
choices: [
{
name: "choicename",
value: 123,
},
],
},
],
},
])
);
assertThrows(() => {
validateSlashCommands([
{
options: [
{
description: "The description of the option.",
name: "optionname",
type: DiscordApplicationCommandOptionTypes.String,
choices: [
{
name: "choicename",
// The maximum length of an option choice value is 100.
value: "a".repeat(101),
},
],
},
],
},
]);
});
validateSlashCommands([
{
options: [
{
type: DiscordApplicationCommandOptionTypes.String,
description: "The description of the option.",
name: "optionname",
choices: [
{
name: "choicename",
value: "choicevalue",
},
],
},
],
},
]);
},
});

View File

@@ -1,44 +0,0 @@
import { validateLength } from "../../src/util/validate_length.ts";
import { assertEquals } from "../deps.ts";
Deno.test({
name: "[utils] Validate length is too low",
fn() {
assertEquals(validateLength("test", { min: 5 }), false);
},
});
Deno.test({
name: "[utils] Validate length is too high",
fn() {
assertEquals(validateLength("test", { max: 3 }), false);
},
});
Deno.test({
name: "[utils] Validate length is NOT just right in between.",
fn() {
assertEquals(validateLength("test", { min: 5, max: 3 }), false);
},
});
Deno.test({
name: "[utils] Validate length is NOT too low",
fn() {
assertEquals(validateLength("test", { min: 3 }), true);
},
});
Deno.test({
name: "[utils] Validate length is NOT too high",
fn() {
assertEquals(validateLength("test", { max: 5 }), true);
},
});
Deno.test({
name: "[utils] Validate length is just right in between.",
fn() {
assertEquals(validateLength("test", { min: 3, max: 6 }), true);
},
});

View File

@@ -1,58 +0,0 @@
import { botId, startBot } from "../../src/bot.ts";
import { cache } from "../../src/cache.ts";
import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts";
import { delay } from "../../src/util/utils.ts";
import { ws } from "../../src/ws/ws.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { delayUntil } from "../util/delay_until.ts";
// Set necessary settings
// Disables the logger which logs everything
ws.log = function (_x: string, _d: unknown) {
// if (["RAW", "GUILD_CREATE", "HEARTBEATING_DETAILS"].includes(_x))
// return console.log(_x);
// console.log(_x, _d);
};
// Default options for tests
export const defaultTestOptions: Partial<Deno.TestDefinition> = {
sanitizeOps: false,
sanitizeResources: false,
};
// Temporary data
export const tempData = {
guildId: 0n,
roleId: 0n,
channelId: 0n,
messageId: 0n,
};
Deno.test({
name: "[ws] connect to gateway",
async fn() {
const token = Deno.env.get("DISCORD_TOKEN");
if (!token) throw new Error("Token is not provided");
await startBot({
token,
eventHandlers: {},
intents: ["GuildMessages", "Guilds", "GuildEmojis", "GuildMessageReactions"],
});
// Delay the execution by 5 seconds
await delay(3000);
await delayUntil(10000, () => cache.isReady);
// DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE
if (cache.guilds.size <= 10) {
for (const guild of cache.guilds.values()) await deleteGuild(guild.id);
}
// Assertions
assertExists(botId);
assertEquals(true, cache.isReady);
},
...defaultTestOptions,
});

View File

@@ -1,17 +0,0 @@
import { delay } from "../../src/util/utils.ts";
import { ws } from "../../src/ws/ws.ts";
import { defaultTestOptions } from "./start_bot.ts";
// Exit the Deno process once all tests are done.
Deno.test({
name: "[ws] Close all shards manually.",
async fn() {
ws.shards.forEach((shard) => {
clearInterval(shard.heartbeat.intervalId);
ws.closeWS(shard.ws, 3061, "Discordeno Testing Finished! Do Not RESUME!");
});
await delay(3000);
},
...defaultTestOptions,
});