mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
Merge branch 'fp-attempt-9001' of https://github.com/Skillz4Killz/discordeno into fp-attempt-9001
This commit is contained in:
21
tests/helpers/guilds/createGuild.ts
Normal file
21
tests/helpers/guilds/createGuild.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function createGuildTests(bot: Bot, t: Deno.TestContext) {
|
||||
const guild = await bot.helpers.createGuild({
|
||||
name: "Isekai Maid Fake Server",
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(guild);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.has(guild.id));
|
||||
|
||||
if (!bot.cache.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be created but it was not cached.`);
|
||||
}
|
||||
}
|
||||
30
tests/helpers/guilds/deleteGuild.ts
Normal file
30
tests/helpers/guilds/deleteGuild.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function deleteGuildTests(bot: Bot, t: Deno.TestContext) {
|
||||
const guild = await bot.helpers.createGuild({
|
||||
name: "Isekai Maid Fake Server",
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(guild);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.has(guild.id));
|
||||
|
||||
if (!bot.cache.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be created but it was not cached.`);
|
||||
}
|
||||
|
||||
await bot.helpers.deleteGuild(guild.id);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => !bot.cache.guilds.has(guild.id));
|
||||
|
||||
if (bot.cache.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be deleted but it's still cached.`);
|
||||
}
|
||||
}
|
||||
21
tests/helpers/guilds/editGuild.ts
Normal file
21
tests/helpers/guilds/editGuild.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function editGuildTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const guild = await bot.helpers.editGuild(guildId, {
|
||||
name: "Discordeno Test 1.0",
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(guild);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, async () => (await bot.cache.guilds.get(guild.id))?.name === "Discordeno Test 1.0");
|
||||
|
||||
if (!bot.cache.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be edited but the cache didn't got updated.`);
|
||||
}
|
||||
}
|
||||
12
tests/helpers/guilds/getAuditLogs.ts
Normal file
12
tests/helpers/guilds/getAuditLogs.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function getAuditLogsTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const logs = await bot.helpers.getAuditLogs(guildId);
|
||||
|
||||
// Assertions
|
||||
assertExists(logs);
|
||||
}
|
||||
13
tests/helpers/guilds/getAvailableVoiceRegions.ts
Normal file
13
tests/helpers/guilds/getAvailableVoiceRegions.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { getAvailableVoiceRegions } from "../../../src/helpers/guilds/get_available_voice_regions.ts";
|
||||
|
||||
export async function getAvailableVoiceRegionsTests(bot: Bot, t: Deno.TestContext) {
|
||||
const regions = await bot.helpers.getAvailableVoiceRegions();
|
||||
|
||||
// Assertions
|
||||
assertExists(regions);
|
||||
}
|
||||
16
tests/helpers/guilds/getBan.ts
Normal file
16
tests/helpers/guilds/getBan.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { getAvailableVoiceRegions } from "../../../src/helpers/guilds/get_available_voice_regions.ts";
|
||||
|
||||
export async function getBanTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
await bot.helpers.ban(guildId, 379643682984296448n);
|
||||
|
||||
const fetchedBan = await bot.helpers.getBan(guildId, 379643682984296448n);
|
||||
|
||||
// Assertions
|
||||
assertExists(fetchedBan);
|
||||
assertEquals(fetchedBan.user.id, 379643682984296448n);
|
||||
}
|
||||
20
tests/helpers/guilds/getBans.ts
Normal file
20
tests/helpers/guilds/getBans.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { getAvailableVoiceRegions } from "../../../src/helpers/guilds/get_available_voice_regions.ts";
|
||||
|
||||
export async function getBansTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
await bot.helpers.ban(guildId, 416477607966670869n);
|
||||
await bot.helpers.ban(guildId, 635383782576357407n);
|
||||
|
||||
const fetchedBans = await bot.helpers.getBans(guildId);
|
||||
|
||||
// Assertions
|
||||
assertExists(fetchedBans);
|
||||
|
||||
if (fetchedBans.size === 0) {
|
||||
throw new Error("getBans didn't return any ban, but it should have returned at least 2 bans!");
|
||||
}
|
||||
}
|
||||
14
tests/helpers/guilds/getGuild.ts
Normal file
14
tests/helpers/guilds/getGuild.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { getAvailableVoiceRegions } from "../../../src/helpers/guilds/get_available_voice_regions.ts";
|
||||
|
||||
export async function getGuildTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const fetchedGuild = await bot.helpers.getGuild(guildId);
|
||||
|
||||
// Assertions
|
||||
assertExists(fetchedGuild);
|
||||
assertEquals(fetchedGuild.id, guildId);
|
||||
}
|
||||
14
tests/helpers/guilds/getVanityUrl.ts
Normal file
14
tests/helpers/guilds/getVanityUrl.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/create_guild_channel.ts";
|
||||
import { DiscordChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { getAvailableVoiceRegions } from "../../../src/helpers/guilds/get_available_voice_regions.ts";
|
||||
|
||||
export async function getVanityURLTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const fetchedVanityURL = await bot.helpers.getVanityURL(guildId);
|
||||
|
||||
// Assertions
|
||||
assertExists(fetchedVanityURL);
|
||||
assertEquals(fetchedVanityURL.code, null);
|
||||
}
|
||||
157
tests/mod.ts
157
tests/mod.ts
@@ -46,6 +46,15 @@ import { getRolesTest } from "./helpers/roles/getRoles.ts";
|
||||
import { editRoleTests } from "./helpers/roles/editRole.ts";
|
||||
import { addRoleTest, removeRoleTest } from "./helpers/roles/roleChanges.ts";
|
||||
import { getUserTests } from "./helpers/misc/user.ts";
|
||||
import { createGuildTests } from "./helpers/guilds/createGuild.ts";
|
||||
import { deleteGuildTests } from "./helpers/guilds/deleteGuild.ts";
|
||||
import { editGuildTests } from "./helpers/guilds/editGuild.ts";
|
||||
import { getAuditLogsTests } from "./helpers/guilds/getAuditLogs.ts";
|
||||
import { getAvailableVoiceRegionsTests } from "./helpers/guilds/getAvailableVoiceRegions.ts";
|
||||
import { getBanTests } from "./helpers/guilds/getBan.ts";
|
||||
import { getBansTests } from "./helpers/guilds/getBans.ts";
|
||||
import { getGuildTests } from "./helpers/guilds/getGuild.ts";
|
||||
import { getVanityURLTests } from "./helpers/guilds/getVanityUrl.ts";
|
||||
|
||||
// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS
|
||||
const sanitizeMode = {
|
||||
@@ -108,47 +117,113 @@ Deno.test({
|
||||
throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`);
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
t.step({
|
||||
name: "[guild] format a guild's icon url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildIconURL(785384884197392384n, {
|
||||
icon: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] format a guild's banner url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildBannerURL(613425648685547541n, {
|
||||
banner: 3919584870146358272366452115178209474142n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] format a guild's splash url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildSplashURL(785384884197392384n, {
|
||||
splash: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
]);
|
||||
// GUILD TESTS GROUPED
|
||||
await t.step("Guild related tests", async (t) => {
|
||||
await Promise.all([
|
||||
t.step({
|
||||
name: "[guild] format a guild's icon url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildIconURL(785384884197392384n, {
|
||||
icon: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] format a guild's banner url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildBannerURL(613425648685547541n, {
|
||||
banner: 3919584870146358272366452115178209474142n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] format a guild's splash url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildSplashURL(785384884197392384n, {
|
||||
splash: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] create a guild",
|
||||
fn: async (t) => {
|
||||
await createGuildTests(bot, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] delete a guild",
|
||||
fn: async (t) => {
|
||||
await deleteGuildTests(bot, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] edit a guild",
|
||||
fn: async (t) => {
|
||||
await editGuildTests(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] get audit logs",
|
||||
fn: async (t) => {
|
||||
await getAuditLogsTests(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] get available voice regions",
|
||||
fn: async (t) => {
|
||||
await getAvailableVoiceRegionsTests(bot, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] get a ban",
|
||||
fn: async (t) => {
|
||||
await getBanTests(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] get bans",
|
||||
fn: async (t) => {
|
||||
await getBansTests(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] get guilds",
|
||||
fn: async (t) => {
|
||||
await getGuildTests(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[guild] get vanity url",
|
||||
fn: async (t) => {
|
||||
await getVanityURLTests(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
// CHANNEL TESTS GROUPED
|
||||
await t.step("Channel related tests", async (t) => {
|
||||
|
||||
Reference in New Issue
Block a user