mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
fix(tests): move emoji tests to guild stuff cuz rate limits
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[emoji] create an emoji",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
},
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[emoji] delete an emoji with a reason",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, "with a reason");
|
||||
|
||||
const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
assertEquals(exists.id, undefined);
|
||||
},
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[emoji] delete an emoji without a reason",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
|
||||
const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
assertEquals(exists.id, undefined);
|
||||
},
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[emoji] Edit an emoji name",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
assertEquals(emoji.name, "blamewolf");
|
||||
|
||||
await bot.helpers.editEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, {
|
||||
name: "edited",
|
||||
});
|
||||
|
||||
const edited = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
|
||||
assertEquals(edited.name, "edited");
|
||||
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
},
|
||||
});
|
||||
@@ -1,33 +0,0 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[emoji] Edit an emoji's roles",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
assertEquals(emoji.name, "blamewolf");
|
||||
|
||||
const role = await bot.helpers.createRole(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "dd-test-emoji",
|
||||
});
|
||||
await bot.helpers.editEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, {
|
||||
roles: [role.id],
|
||||
});
|
||||
|
||||
const edited = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
|
||||
assertEquals(edited.roles?.length, 1);
|
||||
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
await bot.helpers.deleteRole(CACHED_COMMUNITY_GUILD_ID, role.id);
|
||||
},
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[emoji] get an emoji",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
assertExists(exists.id);
|
||||
assertEquals(emoji.id, exists.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
},
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[emoji] get all guild emojis",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
const emoji2 = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "blamewolf2",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
assertExists(emoji2.id);
|
||||
|
||||
const exists = await bot.helpers.getEmojis(CACHED_COMMUNITY_GUILD_ID);
|
||||
assertEquals(exists.size > 1, true);
|
||||
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id);
|
||||
await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji2.id);
|
||||
},
|
||||
});
|
||||
270
testss/guild.test.ts
Normal file
270
testss/guild.test.ts
Normal file
@@ -0,0 +1,270 @@
|
||||
import { ChannelTypes } from "../mod.ts";
|
||||
import { assertEquals, assertExists, assertNotEquals } from "./deps.ts";
|
||||
import { loadBot } from "./mod.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] Create a guild",
|
||||
async fn(t) {
|
||||
const bot = await loadBot();
|
||||
|
||||
// Delete the oldest guild(most likely to have finished tests).
|
||||
|
||||
const guild = await bot.helpers.createGuild({
|
||||
name: "Discordeno-test",
|
||||
});
|
||||
assertExists(guild.id);
|
||||
|
||||
try {
|
||||
await t.step("[guild] Get a guild", async () => {
|
||||
const exists = await bot.helpers.getGuild(guild.id);
|
||||
assertExists(exists);
|
||||
assertExists(exists.id);
|
||||
assertEquals(exists.name, guild.name);
|
||||
});
|
||||
|
||||
await t.step("[guild] Edit a guild", async (t) => {
|
||||
const voiceChannel = await bot.helpers.createChannel(guild.id, {
|
||||
name: "edit-guild-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
});
|
||||
assertExists(voiceChannel.id);
|
||||
|
||||
const edited = await bot.helpers.editGuild(guild.id, {
|
||||
name: "Discordeno-test-edited",
|
||||
afkChannelId: voiceChannel.id,
|
||||
// afkTimeout: 5,
|
||||
}, guild.shardId);
|
||||
assertEquals(edited.name, "Discordeno-test-edited");
|
||||
assertNotEquals(guild.afkChannelId, voiceChannel.id);
|
||||
assertEquals(edited.afkChannelId, voiceChannel.id);
|
||||
// assertEquals(guild.afkTimeout, 0);
|
||||
// assertEquals(edited.afkTimeout, 5);
|
||||
|
||||
await t.step("[guild] Reset a guild's afk channel id", async () => {
|
||||
const edited2 = await bot.helpers.editGuild(guild.id, { afkChannelId: null }, guild.shardId);
|
||||
assertNotEquals(edited.afkChannelId, edited2.afkChannelId);
|
||||
assertEquals(edited2.afkChannelId, undefined);
|
||||
});
|
||||
|
||||
await bot.helpers.deleteChannel(voiceChannel.id);
|
||||
});
|
||||
|
||||
// await t.step("[guild] Edit a guild's afk settings", async () => {
|
||||
|
||||
// });
|
||||
|
||||
await t.step("[guild] Get audit logs", async () => {
|
||||
const auditLogs = await bot.helpers.getAuditLogs(guild.id, { limit: 1 });
|
||||
assertExists(auditLogs.auditLogEntries.length);
|
||||
});
|
||||
|
||||
// Get available voice regions
|
||||
await t.step("[guild] Get available voice regions", async () => {
|
||||
const regions = await bot.helpers.getVoiceRegions(guild.id);
|
||||
assertExists(regions.size);
|
||||
});
|
||||
|
||||
// Get a guild ban
|
||||
await t.step("[guild] Get a guild ban", async (t) => {
|
||||
await bot.helpers.banMember(guild.id, 379643682984296448n);
|
||||
|
||||
const fetchedBan = await bot.helpers.getBan(guild.id, 379643682984296448n);
|
||||
|
||||
// Assertions
|
||||
assertExists(fetchedBan);
|
||||
assertEquals(fetchedBan.user.id, 379643682984296448n);
|
||||
|
||||
// Get multiple guild bans
|
||||
await t.step("[guild] Get multiple guild bans", async () => {
|
||||
await bot.helpers.banMember(guild.id, 416477607966670869n);
|
||||
await bot.helpers.banMember(guild.id, 635383782576357407n);
|
||||
|
||||
const fetchedBans = await bot.helpers.getBans(guild.id);
|
||||
|
||||
// Assertions
|
||||
assertExists(fetchedBans);
|
||||
});
|
||||
});
|
||||
|
||||
// Get vanity URL
|
||||
await t.step("[guild] Get vanity URL", async () => {
|
||||
const vanityUrl = await bot.helpers.getVanityUrl(guild.id);
|
||||
assertEquals(vanityUrl.code, undefined);
|
||||
});
|
||||
|
||||
await t.step({
|
||||
name: "[emoji] create an emoji",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
},
|
||||
});
|
||||
|
||||
await t.step({
|
||||
name: "[emoji] delete an emoji without a reason",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
|
||||
const exists = await bot.helpers.getEmoji(guild.id, emoji.id);
|
||||
assertEquals(exists.id, undefined);
|
||||
},
|
||||
});
|
||||
|
||||
await t.step({
|
||||
name: "[emoji] delete an emoji with a reason",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id, "with a reason");
|
||||
|
||||
const exists = await bot.helpers.getEmoji(guild.id, emoji.id);
|
||||
assertEquals(exists.id, undefined);
|
||||
},
|
||||
});
|
||||
|
||||
await t.step({
|
||||
name: "[emoji] Edit an emoji name",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
assertEquals(emoji.name, "blamewolf");
|
||||
|
||||
await bot.helpers.editEmoji(guild.id, emoji.id, {
|
||||
name: "edited",
|
||||
});
|
||||
|
||||
const edited = await bot.helpers.getEmoji(guild.id, emoji.id);
|
||||
|
||||
assertEquals(edited.name, "edited");
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
},
|
||||
});
|
||||
|
||||
await t.step({
|
||||
name: "[emoji] Edit an emoji's roles",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
assertEquals(emoji.name, "blamewolf");
|
||||
|
||||
const role = await bot.helpers.createRole(guild.id, {
|
||||
name: "dd-test-emoji",
|
||||
});
|
||||
await bot.helpers.editEmoji(guild.id, emoji.id, {
|
||||
roles: [role.id],
|
||||
});
|
||||
|
||||
const edited = await bot.helpers.getEmoji(guild.id, emoji.id);
|
||||
|
||||
assertEquals(edited.roles?.length, 1);
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
await bot.helpers.deleteRole(guild.id, role.id);
|
||||
},
|
||||
});
|
||||
|
||||
await t.step({
|
||||
name: "[emoji] get an emoji",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
|
||||
const exists = await bot.helpers.getEmoji(guild.id, emoji.id);
|
||||
assertExists(exists.id);
|
||||
assertEquals(emoji.id, exists.id);
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
},
|
||||
});
|
||||
|
||||
await t.step({
|
||||
name: "[emoji] get all guild emojis",
|
||||
fn: async (t) => {
|
||||
const bot = await loadBot();
|
||||
const emoji = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
const emoji2 = await bot.helpers.createEmoji(guild.id, {
|
||||
name: "blamewolf2",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji.id);
|
||||
assertExists(emoji2.id);
|
||||
|
||||
const exists = await bot.helpers.getEmojis(guild.id);
|
||||
assertEquals(exists.size > 1, true);
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji2.id);
|
||||
},
|
||||
});
|
||||
|
||||
await t.step("[guild] Delete a guild", async () => {
|
||||
await bot.helpers.deleteGuild(guild.id);
|
||||
//
|
||||
const exists = await bot.helpers.getGuild(guild.id);
|
||||
assertEquals(exists, undefined);
|
||||
});
|
||||
} catch (error) {
|
||||
// If any errors arise, delete the guild
|
||||
await bot.helpers.deleteGuild(guild.id);
|
||||
// then throw the error
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user