Merge branch 'fp-attempt-9001' of https://github.com/Skillz4Killz/discordeno into fp-attempt-9001

This commit is contained in:
Skillz4Killz
2021-11-02 20:45:36 +00:00
committed by GitHub
10 changed files with 277 additions and 41 deletions

View 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.`);
}
}

View 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.`);
}
}

View 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.`);
}
}

View 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);
}

View 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);
}

View 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);
}

View 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!");
}
}

View 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);
}

View 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);
}

View File

@@ -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) => {