diff --git a/tests/helpers/invites/createInvite.ts b/tests/helpers/invites/createInvite.ts new file mode 100644 index 000000000..46162cb70 --- /dev/null +++ b/tests/helpers/invites/createInvite.ts @@ -0,0 +1,14 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; + +export async function createInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + const invite = await bot.helpers.createInvite(channelId, { + maxAge: 86400, + maxUses: 0, + temporary: false, + unique: false, + }); + + // Assertions + assertExists(invite); +} diff --git a/tests/helpers/invites/deleteInvite.ts b/tests/helpers/invites/deleteInvite.ts new file mode 100644 index 000000000..f660c4219 --- /dev/null +++ b/tests/helpers/invites/deleteInvite.ts @@ -0,0 +1,19 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; + +export async function deleteInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + const invite = await bot.helpers.createInvite(channelId, { + maxAge: 86400, + maxUses: 0, + temporary: false, + unique: false, + }); + + // Assertions + assertExists(invite); + + const deletedInvite = await bot.helpers.deleteInvite(channelId, invite.code); + + // Assertions + assertExists(deletedInvite); +} diff --git a/tests/helpers/invites/getChannelInvites.ts b/tests/helpers/invites/getChannelInvites.ts new file mode 100644 index 000000000..287644346 --- /dev/null +++ b/tests/helpers/invites/getChannelInvites.ts @@ -0,0 +1,30 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; + +export async function getChannelInvitesTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + const invite = await bot.helpers.createInvite(channelId, { + maxAge: 86400, + maxUses: 0, + temporary: false, + unique: false, + }); + + // Assertions + assertExists(invite); + + const secondInvite = await bot.helpers.createInvite(channelId, { + maxAge: 86400, + maxUses: 0, + temporary: false, + unique: false, + }); + + // Assertions + assertExists(secondInvite); + + const invites = await bot.helpers.getChannelInvites(channelId); + + if (invites.size < 2) { + throw new Error("The function getChannelInvites didn't return all the invites"); + } +} diff --git a/tests/helpers/invites/getInvite.ts b/tests/helpers/invites/getInvite.ts new file mode 100644 index 000000000..ada2f8770 --- /dev/null +++ b/tests/helpers/invites/getInvite.ts @@ -0,0 +1,19 @@ +import { Bot } from "../../../src/bot.ts"; +import {assertEquals, assertExists} from "../../deps.ts"; + +export async function getInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + const invite = await bot.helpers.createInvite(channelId, { + maxAge: 86400, + maxUses: 0, + temporary: false, + unique: false, + }); + + // Assertions + assertExists(invite); + + const fetchedInvite = await bot.helpers.getInvite(invite.code); + + assertExists(fetchedInvite); + assertEquals(fetchedInvite.code, invite.code); +} diff --git a/tests/helpers/invites/getInvites.ts b/tests/helpers/invites/getInvites.ts new file mode 100644 index 000000000..fbaa728e1 --- /dev/null +++ b/tests/helpers/invites/getInvites.ts @@ -0,0 +1,22 @@ +import { Bot } from "../../../src/bot.ts"; +import {assertEquals, assertExists} from "../../deps.ts"; + +export async function getInvitesTest(bot: Bot, channelId: bigint, guildId: bigint, t: Deno.TestContext) { + const invite = await bot.helpers.createInvite(channelId, { + maxAge: 86400, + maxUses: 0, + temporary: false, + unique: false, + }); + + // Assertions + assertExists(invite); + + const fetchedInvites = await bot.helpers.getInvites(guildId); + + assertExists(fetchedInvites); + + if (fetchedInvites.size === 0) { + throw new Error("The function getInvites didn't return any invites"); + } +} diff --git a/tests/mod.ts b/tests/mod.ts index 22d8117dd..5965da4c0 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -28,6 +28,11 @@ import { pinMessageTests } from "./helpers/messages/pin.ts"; import { removeAllReactionTests, removeReactionEmojiTest, removeReactionTest } from "./helpers/messages/reactions.ts"; import { createChannelTests } from "./helpers/channels/createChannel.ts"; import { deleteChannelTests } from "./helpers/channels/deleteChannel.ts"; +import {createInviteTest} from "./helpers/invites/createInvite.ts"; +import {deleteInviteTest} from "./helpers/invites/deleteInvite.ts"; +import {getChannelInvitesTest} from "./helpers/invites/getChannelInvites.ts"; +import {getInviteTest} from "./helpers/invites/getInvite.ts"; +import {getInvitesTest} from "./helpers/invites/getInvites.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS @@ -446,6 +451,47 @@ Deno.test("[Bot] - Starting Tests", async (t) => { ...sanitizeMode, }), ]); + + // ALL TEST RELATED TO INVITES + await t.step("Invites related tests", async (t) => { + await Promise.all([ + t.step({ + name: "[invite] create an invite", + async fn() { + await createInviteTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] delete an invite", + async fn() { + await deleteInviteTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] get channels invites", + async fn() { + await getChannelInvitesTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] get invite", + async fn() { + await getInviteTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[invite] get invites", + async fn() { + await getInvitesTest(bot, channel.id, guild.id, t); + }, + ...sanitizeMode, + }), + ]); + }); }); // MEMBER TESTS GROUPED