mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 09:20:08 +00:00
Merge pull request #819 from TriForMine/emojis-tests
tests: add emojis tests
This commit is contained in:
@@ -12,7 +12,7 @@ Deno.test({
|
||||
name: "delete-channel",
|
||||
});
|
||||
// wait 5 seconds to give it time for CHANNEL_CREATE event
|
||||
delayUntil(3000, () => cache.channels.has(channel.id));
|
||||
await delayUntil(3000, () => cache.channels.has(channel.id));
|
||||
// Make sure the channel was created.
|
||||
if (!cache.channels.has(channel.id)) {
|
||||
throw new Error(
|
||||
@@ -23,7 +23,7 @@ Deno.test({
|
||||
// Delete the channel now without a reason
|
||||
await deleteChannel(tempData.guildId, channel.id);
|
||||
// wait 5 seconds to give it time for CHANNEL_DELETE event
|
||||
delayUntil(3000, () => !cache.channels.has(channel.id));
|
||||
await delayUntil(3000, () => !cache.channels.has(channel.id));
|
||||
// Make sure it is gone from cache
|
||||
if (cache.channels.has(channel.id)) {
|
||||
throw new Error(
|
||||
|
||||
28
tests/emojis/create_emoji.ts
Normal file
28
tests/emojis/create_emoji.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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,
|
||||
});
|
||||
45
tests/emojis/delete_emoji.ts
Normal file
45
tests/emojis/delete_emoji.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
});
|
||||
35
tests/emojis/edit_emoji.ts
Normal file
35
tests/emojis/edit_emoji.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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,
|
||||
});
|
||||
35
tests/emojis/get_emoji.ts
Normal file
35
tests/emojis/get_emoji.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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,
|
||||
});
|
||||
19
tests/emojis/get_emojis.ts
Normal file
19
tests/emojis/get_emojis.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
|
||||
assertEquals(cache.guilds.get(tempData.guildId)?.emojis?.size > 0, true);
|
||||
},
|
||||
...defaultTestOptions,
|
||||
});
|
||||
@@ -7,7 +7,7 @@ import "./util/utils.ts";
|
||||
|
||||
// API TESTING BELOW
|
||||
|
||||
// First initate the connection
|
||||
// First initiate the connection
|
||||
import "./ws/start_bot.ts";
|
||||
import "./guilds/create_guild.ts";
|
||||
|
||||
@@ -16,6 +16,13 @@ import "./channels/create_channel.ts";
|
||||
import "./channels/category_children.ts";
|
||||
import "./channels/delete_channel.ts";
|
||||
|
||||
// Emojis tests
|
||||
import "./emojis/create_emoji.ts";
|
||||
import "./emojis/delete_emoji.ts";
|
||||
import "./emojis/edit_emoji.ts";
|
||||
import "./emojis/get_emoji.ts";
|
||||
import "./emojis/get_emojis.ts";
|
||||
|
||||
// Messages tests
|
||||
import "./messages/add_reaction.ts";
|
||||
import "./messages/add_reactions.ts";
|
||||
|
||||
Reference in New Issue
Block a user