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
@@ -36,9 +36,14 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
} }
assertEquals( assertEquals(
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, options.permissionOverwrites ? options.permissionOverwrites[0].allow : []), channelOverwriteHasPermission(
true channel.guildId,
) botId,
cache.channels.get(channel.id)?.permissionOverwrites,
options.permissionOverwrites ? options.permissionOverwrites[0].allow : [],
),
true,
);
} }
Deno.test({ Deno.test({
+6 -3
View File
@@ -22,15 +22,18 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) {
// Edit the channel now // Edit the channel now
if (type === "raw") { if (type === "raw") {
await editChannel(channel.id, { await editChannel(channel.id, {
name: "new-name" name: "new-name",
}, reason); }, reason);
} else { } else {
await channel.edit({ await channel.edit({
name: "new-name" name: "new-name",
}); });
} }
// wait 5 seconds to give it time for CHANNEL_UPDATE event // wait 5 seconds to give it time for CHANNEL_UPDATE event
await delayUntil(3000, () => cache.channels.get(channel.id)?.name === "new-name"); await delayUntil(
3000,
() => cache.channels.get(channel.id)?.name === "new-name",
);
assertEquals(cache.channels.get(channel.id)?.name, "new-name"); assertEquals(cache.channels.get(channel.id)?.name, "new-name");
} }
+15 -4
View File
@@ -43,13 +43,24 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
await delayUntil( await delayUntil(
10000, 10000,
() => channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, ["VIEW_CHANNEL", "ADD_REACTIONS"]), () =>
channelOverwriteHasPermission(
channel.guildId,
botId,
cache.channels.get(channel.id)?.permissionOverwrites,
["VIEW_CHANNEL", "ADD_REACTIONS"],
),
); );
assertEquals( assertEquals(
channelOverwriteHasPermission(channel.guildId, botId, cache.channels.get(channel.id)?.permissionOverwrites, ["VIEW_CHANNEL", "ADD_REACTIONS"]), channelOverwriteHasPermission(
true channel.guildId,
) botId,
cache.channels.get(channel.id)?.permissionOverwrites,
["VIEW_CHANNEL", "ADD_REACTIONS"],
),
true,
);
} }
Deno.test({ Deno.test({
+13 -4
View File
@@ -12,7 +12,7 @@ Deno.test({
name: "[channel] get pins.", name: "[channel] get pins.",
async fn() { async fn() {
const channel = await createChannel(tempData.guildId, { const channel = await createChannel(tempData.guildId, {
name: 'pins-channel' name: "pins-channel",
}); });
// Assertions // Assertions
@@ -22,14 +22,23 @@ Deno.test({
await delayUntil(10000, () => cache.channels.has(channel.id)); await delayUntil(10000, () => cache.channels.has(channel.id));
if (!cache.channels.has(channel.id)) { if (!cache.channels.has(channel.id)) {
throw new Error("The channel seemed to be created but it was not cached."); throw new Error(
"The channel seemed to be created but it was not cached.",
);
} }
const message = await sendMessage(tempData.channelId, "Hello World!"); const message = await sendMessage(tempData.channelId, "Hello World!");
const secondMessage = await sendMessage(tempData.channelId, "Goodbye World!"); const secondMessage = await sendMessage(
tempData.channelId,
"Goodbye World!",
);
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
await delayUntil(10000, () => cache.messages.has(message.id) && cache.messages.has(secondMessage.id)); await delayUntil(
10000,
() =>
cache.messages.has(message.id) && cache.messages.has(secondMessage.id),
);
await message.pin(); await message.pin();
await secondMessage.pin(); await secondMessage.pin();
+8 -4
View File
@@ -31,12 +31,14 @@ Deno.test({
await delayUntil(10000, () => cache.channels.has(category.id)); await delayUntil(10000, () => cache.channels.has(category.id));
if (!cache.channels.has(category.id)) { if (!cache.channels.has(category.id)) {
throw new Error("The channel seemed to be created but it was not cached."); throw new Error(
"The channel seemed to be created but it was not cached.",
);
} }
const channel = await createChannel(tempData.guildId, { const channel = await createChannel(tempData.guildId, {
name: 'synced-channel', name: "synced-channel",
parentId: category.id parentId: category.id,
}); });
// Assertions // Assertions
@@ -46,7 +48,9 @@ Deno.test({
await delayUntil(10000, () => cache.channels.has(channel.id)); await delayUntil(10000, () => cache.channels.has(channel.id));
if (!cache.channels.has(channel.id)) { if (!cache.channels.has(channel.id)) {
throw new Error("The channel seemed to be created but it was not cached."); throw new Error(
"The channel seemed to be created but it was not cached.",
);
} }
const isSynced = await isChannelSynced(channel.id); const isSynced = await isChannelSynced(channel.id);
+4 -2
View File
@@ -13,7 +13,7 @@ Deno.test({
name: "[channel] is typing.", name: "[channel] is typing.",
async fn() { async fn() {
const channel = await createChannel(tempData.guildId, { const channel = await createChannel(tempData.guildId, {
name: 'typing-channel', name: "typing-channel",
}); });
// Assertions // Assertions
@@ -23,7 +23,9 @@ Deno.test({
await delayUntil(10000, () => cache.channels.has(channel.id)); await delayUntil(10000, () => cache.channels.has(channel.id));
if (!cache.channels.has(channel.id)) { if (!cache.channels.has(channel.id)) {
throw new Error("The channel seemed to be created but it was not cached."); throw new Error(
"The channel seemed to be created but it was not cached.",
);
} }
await startTyping(channel.id); await startTyping(channel.id);
+26 -13
View File
@@ -14,49 +14,62 @@ Deno.test({
name: "[channel] swap channels", name: "[channel] swap channels",
async fn() { async fn() {
const channel = await createChannel(tempData.guildId, { const channel = await createChannel(tempData.guildId, {
name: 'channel-1', name: "channel-1",
}); });
// Assertions // Assertions
assertExists(channel); assertExists(channel);
const secondChannel = await createChannel(tempData.guildId, { const secondChannel = await createChannel(tempData.guildId, {
name: 'channel-2', name: "channel-2",
}); });
// Assertions // Assertions
assertExists(channel); assertExists(channel);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delayUntil(10000, () => cache.channels.has(channel.id) && cache.channels.has(secondChannel.id)); await delayUntil(
10000,
() =>
cache.channels.has(channel.id) && cache.channels.has(secondChannel.id),
);
if (!cache.channels.has(channel.id) || !cache.channels.has(secondChannel.id)) { if (
throw new Error("The channel seemed to be created but it was not cached."); !cache.channels.has(channel.id) || !cache.channels.has(secondChannel.id)
) {
throw new Error(
"The channel seemed to be created but it was not cached.",
);
} }
await swapChannels(tempData.guildId, [ await swapChannels(tempData.guildId, [
{ {
id: channel.id, id: channel.id,
position: secondChannel.position! position: secondChannel.position!,
}, },
{ {
id: secondChannel.id, id: secondChannel.id,
position: channel.position! position: channel.position!,
} },
]); ]);
// Delay the execution by 5 seconds to allow CHANNEL_UPDATE event to be processed // Delay the execution by 5 seconds to allow CHANNEL_UPDATE event to be processed
await delayUntil(10000, () => cache.channels.get(channel.id)?.position === secondChannel.position && cache.channels.get(secondChannel.id)?.position === channel.position); await delayUntil(
10000,
() =>
cache.channels.get(channel.id)?.position === secondChannel.position &&
cache.channels.get(secondChannel.id)?.position === channel.position,
);
assertEquals( assertEquals(
cache.channels.get(channel.id)?.position, cache.channels.get(channel.id)?.position,
secondChannel.position secondChannel.position,
) );
assertEquals( assertEquals(
cache.channels.get(secondChannel.id)?.position, cache.channels.get(secondChannel.id)?.position,
channel.position channel.position,
) );
}, },
...defaultTestOptions, ...defaultTestOptions,
}); });
-1
View File
@@ -26,7 +26,6 @@ import "./channels/is_channel_synced.ts";
import "./channels/start_typing.ts"; import "./channels/start_typing.ts";
import "./channels/swap_channels.ts"; import "./channels/swap_channels.ts";
// Emojis tests // Emojis tests
import "./emojis/create_emoji.ts"; import "./emojis/create_emoji.ts";
import "./emojis/delete_emoji.ts"; import "./emojis/delete_emoji.ts";