fix(tests): fix reactions tests

This commit is contained in:
TriForMine
2021-04-10 20:24:38 +02:00
parent b7321a6d0e
commit 12e21084a6
10 changed files with 53 additions and 36 deletions

View File

@@ -1,7 +1,7 @@
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
import { assertExists } from "../deps.ts";
import { cache } from "../../src/cache.ts";
import { createChannel, categoryChildren } from "../../src/helpers/mod.ts";
import { categoryChildren, createChannel } from "../../src/helpers/mod.ts";
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
import { delay } from "../../src/util/utils.ts";
@@ -20,7 +20,7 @@ Deno.test({
if (!cache.channels.has(category.id)) {
throw new Error(
"The channel seemed to be created but it was not cached."
"The channel seemed to be created but it was not cached.",
);
}
@@ -31,25 +31,27 @@ Deno.test({
name: `Discordeno-test-${num}`,
parentId: category.id,
})
)
),
);
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
await delay(5000);
// If every channel is not present in the cache, error out
if (!channels.every((c) => cache.channels.has(c.id)))
if (!channels.every((c) => cache.channels.has(c.id))) {
throw new Error(
"The channels seemed to be created but it was not cached."
"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."
"The category channel ids did not match with the category channels.",
);
}
},
...defaultTestOptions,
});

View File

@@ -40,7 +40,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
Deno.test({
name: "[channel] create a new text channel",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-test"}, true);
await ifItFailsBlameWolf({ name: "Discordeno-test" }, true);
},
...defaultTestOptions,
});
@@ -48,7 +48,10 @@ Deno.test({
Deno.test({
name: "[channel] create a new category channel",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_CATEGORY}, true);
await ifItFailsBlameWolf({
name: "Discordeno-test",
type: DiscordChannelTypes.GUILD_CATEGORY,
}, true);
},
...defaultTestOptions,
});
@@ -72,7 +75,10 @@ Deno.test({
Deno.test({
name: "[channel] create a new voice channel",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_VOICE}, true);
await ifItFailsBlameWolf({
name: "Discordeno-test",
type: DiscordChannelTypes.GUILD_VOICE,
}, true);
},
...defaultTestOptions,
});
@@ -80,7 +86,11 @@ Deno.test({
Deno.test({
name: "[channel] create a new voice channel with a bitrate",
async fn() {
await ifItFailsBlameWolf({ name: "discordeno-test", type: DiscordChannelTypes.GUILD_VOICE, bitrate: 32000 }, true);
await ifItFailsBlameWolf({
name: "discordeno-test",
type: DiscordChannelTypes.GUILD_VOICE,
bitrate: 32000,
}, true);
},
...defaultTestOptions,
});
@@ -88,7 +98,11 @@ Deno.test({
Deno.test({
name: "[channel] create a new voice channel with a user limit",
async fn() {
await ifItFailsBlameWolf({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_VOICE, userLimit: 32 }, true);
await ifItFailsBlameWolf({
name: "Discordeno-test",
type: DiscordChannelTypes.GUILD_VOICE,
userLimit: 32,
}, true);
},
...defaultTestOptions,
});
@@ -96,7 +110,10 @@ Deno.test({
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);
await ifItFailsBlameWolf({
name: "Discordeno-test",
rateLimitPerUser: 2423,
}, true);
},
...defaultTestOptions,
});
@@ -109,9 +126,8 @@ Deno.test({
...defaultTestOptions,
});
// TODO: Need to validate tests for these options
// /** Sorting position of the channel */
// position?: number;
// /** The channel's permission overwrites */
// permissionOverwrites?: Overwrite[];
// permissionOverwrites?: Overwrite[];

View File

@@ -5,7 +5,7 @@ import { DiscordReaction } from "../../src/types/messages/reaction.ts";
import { delay } from "../../src/util/utils.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 { createEmoji } from "../../src/helpers/emojis/create_emoji.ts";
async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
const message = await sendMessage(tempData.channelId, "Hello World!");
@@ -33,7 +33,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
}
},
)
).id
}>`;
@@ -52,9 +52,9 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
.get(message.id)
?.reactions?.filter(
(reaction: DiscordReaction) =>
reaction.emoji?.name === (custom ? "blamewolf" : "❤")
reaction.emoji?.name === (custom ? "blamewolf" : "❤"),
).length,
1
1,
);
}

View File

@@ -3,7 +3,6 @@ import {
cache,
createEmoji,
delay,
DiscordReaction,
sendMessage,
} from "../../mod.ts";
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
@@ -68,9 +67,7 @@ async function ifItFailsBlameWolf(
await delay(5000);
assertEquals(
await cache.messages.get(message.id)?.reactions?.filter((
reaction: DiscordReaction,
) => emojiIds.includes(reaction.emoji?.name)).length,
await cache.messages.get(message.id)?.reactions?.length,
2,
);
}

View File

@@ -14,10 +14,9 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
// Wait few seconds for the channel create event to arrive and cache it
await delay(5000);
const message =
type === "raw"
? await sendMessage(channel.id, "Hello World!")
: await channel.send("Hello World!");
const message = type === "raw"
? await sendMessage(channel.id, "Hello World!")
: await channel.send("Hello World!");
// Assertions
assertExists(message);

View File

@@ -44,8 +44,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
// Check if the reactions has been deleted
assertEquals(
await cache.messages.get(message.id)?.reactions?.length,
0,
await cache.messages.get(message.id)?.reactions,
undefined,
);
}

View File

@@ -44,8 +44,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
// Check if the reactions has been deleted
assertEquals(
await cache.messages.get(message.id)?.reactions?.length,
0,
await cache.messages.get(message.id)?.reactions,
undefined,
);
}

View File

@@ -45,8 +45,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
// Check if the reactions has been deleted
assertEquals(
await cache.messages.get(message.id)?.reactions?.length,
0,
await cache.messages.get(message.id)?.reactions,
undefined,
);
}

View File

@@ -50,8 +50,8 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") {
// Check if the reactions has been deleted
assertEquals(
await cache.messages.get(message.id)?.reactions?.length,
0,
await cache.messages.get(message.id)?.reactions,
undefined,
);
}

View File

@@ -1,4 +1,7 @@
import { snakeKeysToCamelCase,camelKeysToSnakeCase } from "../../src/util/utils.ts";
import {
camelKeysToSnakeCase,
snakeKeysToCamelCase,
} from "../../src/util/utils.ts";
import { assertEquals } from "../deps.ts";
const testSnakeObject = {