This commit is contained in:
itohatweb
2021-04-13 07:26:23 +00:00
parent 174ec859f1
commit 5afa6f2c13
10 changed files with 132 additions and 86 deletions
@@ -8,9 +8,9 @@ import { delayUntil } from "../util/delay_until.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { botId } from "../../src/bot.ts";
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
import {editChannelOverwrite} from "../../src/helpers/channels/edit_channel_overwrite.ts";
import {channelOverwriteHasPermission} from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
import {DiscordBitwisePermissionFlags} from "../../src/types/permissions/bitwise_permission_flags.ts";
import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts";
import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
import { DiscordBitwisePermissionFlags } from "../../src/types/permissions/bitwise_permission_flags.ts";
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
const channel = await createChannel(tempData.guildId, options);
@@ -36,9 +36,14 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
}
assertEquals(
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, options.permissionOverwrites ? options.permissionOverwrites[0].allow : []),
true
)
channelOverwriteHasPermission(
channel.guildId,
botId,
cache.channels.get(channel.id)?.permissionOverwrites,
options.permissionOverwrites ? options.permissionOverwrites[0].allow : [],
),
true,
);
}
Deno.test({
+8 -5
View File
@@ -2,8 +2,8 @@ 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";
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
@@ -22,15 +22,18 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
// Edit the channel now
if (type === "raw") {
await editChannel(channel.id, {
name: "new-name"
name: "new-name",
}, reason);
} else {
await channel.edit({
name: "new-name"
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");
await delayUntil(
3000,
() => cache.channels.get(channel.id)?.name === "new-name",
);
assertEquals(cache.channels.get(channel.id)?.name, "new-name");
}
+18 -7
View File
@@ -8,9 +8,9 @@ import { delayUntil } from "../util/delay_until.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { botId } from "../../src/bot.ts";
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
import {editChannelOverwrite} from "../../src/helpers/channels/edit_channel_overwrite.ts";
import {channelOverwriteHasPermission} from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
import {DiscordBitwisePermissionFlags} from "../../src/types/permissions/bitwise_permission_flags.ts";
import { editChannelOverwrite } from "../../src/helpers/channels/edit_channel_overwrite.ts";
import { channelOverwriteHasPermission } from "../../src/helpers/channels/channel_overwrite_has_permission.ts";
import { DiscordBitwisePermissionFlags } from "../../src/types/permissions/bitwise_permission_flags.ts";
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
const channel = await createChannel(tempData.guildId, options);
@@ -43,13 +43,24 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
await delayUntil(
10000,
() => channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, ["VIEW_CHANNEL", "ADD_REACTIONS"]),
() =>
channelOverwriteHasPermission(
channel.guildId,
botId,
cache.channels.get(channel.id)?.permissionOverwrites,
["VIEW_CHANNEL", "ADD_REACTIONS"],
),
);
assertEquals(
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, ["VIEW_CHANNEL", "ADD_REACTIONS"]),
true
)
channelOverwriteHasPermission(
channel.guildId,
botId,
cache.channels.get(channel.id)?.permissionOverwrites,
["VIEW_CHANNEL", "ADD_REACTIONS"],
),
true,
);
}
Deno.test({
+4 -4
View File
@@ -3,10 +3,10 @@ import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { deleteChannel } from "../../src/helpers/channels/delete_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";
import {getChannel} from "../../src/helpers/channels/get_channel.ts";
import {botId} from "../../src/bot.ts";
import { editChannel } from "../../src/helpers/channels/edit_channel.ts";
import { assertEquals } from "../deps.ts";
import { getChannel } from "../../src/helpers/channels/get_channel.ts";
import { botId } from "../../src/bot.ts";
Deno.test({
name: "[channel] get a channel",
+5 -5
View File
@@ -3,11 +3,11 @@ import { createChannel } from "../../src/helpers/channels/create_channel.ts";
import { deleteChannel } from "../../src/helpers/channels/delete_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";
import {getChannel} from "../../src/helpers/channels/get_channel.ts";
import {botId} from "../../src/bot.ts";
import {getChannels} from "../../src/helpers/channels/get_channels.ts";
import { editChannel } from "../../src/helpers/channels/edit_channel.ts";
import { assertEquals } from "../deps.ts";
import { getChannel } from "../../src/helpers/channels/get_channel.ts";
import { botId } from "../../src/bot.ts";
import { getChannels } from "../../src/helpers/channels/get_channels.ts";
Deno.test({
name: "[channel] get channels.",
+18 -9
View File
@@ -2,17 +2,17 @@ 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 {assertEquals, assertExists} from "../deps.ts";
import {getChannels} from "../../src/helpers/channels/get_channels.ts";
import {sendMessage} from "../../src/helpers/messages/send_message.ts";
import {getPins} from "../../src/helpers/channels/get_pins.ts";
import {DiscordenoMessage} from "../../src/structures/message.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { getChannels } from "../../src/helpers/channels/get_channels.ts";
import { sendMessage } from "../../src/helpers/messages/send_message.ts";
import { getPins } from "../../src/helpers/channels/get_pins.ts";
import { DiscordenoMessage } from "../../src/structures/message.ts";
Deno.test({
name: "[channel] get pins.",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: 'pins-channel'
name: "pins-channel",
});
// Assertions
@@ -22,14 +22,23 @@ Deno.test({
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.");
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!");
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 delayUntil(
10000,
() =>
cache.messages.has(message.id) && cache.messages.has(secondMessage.id),
);
await message.pin();
await secondMessage.pin();
+13 -9
View File
@@ -2,11 +2,11 @@ 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 {assertEquals, assertExists} from "../deps.ts";
import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts";
import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts";
import {botId} from "../../src/bot.ts";
import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { botId } from "../../src/bot.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
Deno.test({
name: "[channel] is channel synced.",
@@ -31,12 +31,14 @@ Deno.test({
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.");
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
name: "synced-channel",
parentId: category.id,
});
// Assertions
@@ -46,7 +48,9 @@ Deno.test({
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.");
throw new Error(
"The channel seemed to be created but it was not cached.",
);
}
const isSynced = await isChannelSynced(channel.id);
+10 -8
View File
@@ -2,18 +2,18 @@ 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 {assertEquals, assertExists} from "../deps.ts";
import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts";
import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts";
import {botId} from "../../src/bot.ts";
import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts";
import {startTyping} from "../../src/helpers/channels/start_typing.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { botId } from "../../src/bot.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
Deno.test({
name: "[channel] is typing.",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: 'typing-channel',
name: "typing-channel",
});
// Assertions
@@ -23,7 +23,9 @@ Deno.test({
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.");
throw new Error(
"The channel seemed to be created but it was not cached.",
);
}
await startTyping(channel.id);
+33 -20
View File
@@ -2,61 +2,74 @@ 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 {assertEquals, assertExists} from "../deps.ts";
import {isChannelSynced} from "../../src/helpers/channels/is_channel_synced.ts";
import {DiscordChannelTypes} from "../../src/types/channels/channel_types.ts";
import {botId} from "../../src/bot.ts";
import {DiscordOverwriteTypes} from "../../src/types/channels/overwrite_types.ts";
import {startTyping} from "../../src/helpers/channels/start_typing.ts";
import {swapChannels} from "../../src/helpers/channels/swap_channels.ts";
import { assertEquals, assertExists } from "../deps.ts";
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { botId } from "../../src/bot.ts";
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
import { swapChannels } from "../../src/helpers/channels/swap_channels.ts";
Deno.test({
name: "[channel] swap channels",
async fn() {
const channel = await createChannel(tempData.guildId, {
name: 'channel-1',
name: "channel-1",
});
// Assertions
assertExists(channel);
const secondChannel = await createChannel(tempData.guildId, {
name: 'channel-2',
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));
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.");
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,
position: secondChannel.position!
position: secondChannel.position!,
},
{
id: secondChannel.id,
position: channel.position!
}
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);
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
)
secondChannel.position,
);
assertEquals(
cache.channels.get(secondChannel.id)?.position,
channel.position
)
channel.position,
);
},
...defaultTestOptions,
});
-1
View File
@@ -26,7 +26,6 @@ import "./channels/is_channel_synced.ts";
import "./channels/start_typing.ts";
import "./channels/swap_channels.ts";
// Emojis tests
import "./emojis/create_emoji.ts";
import "./emojis/delete_emoji.ts";