diff --git a/tests/helpers/invites/create_invite.ts b/tests/helpers/invites/create_invite.ts new file mode 100644 index 000000000..f8864779e --- /dev/null +++ b/tests/helpers/invites/create_invite.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/delete_invite.ts b/tests/helpers/invites/delete_invite.ts new file mode 100644 index 000000000..92cbab673 --- /dev/null +++ b/tests/helpers/invites/delete_invite.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/get_channels_invites.ts b/tests/helpers/invites/get_channels_invites.ts new file mode 100644 index 000000000..048bb576f --- /dev/null +++ b/tests/helpers/invites/get_channels_invites.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/get_invite.ts b/tests/helpers/invites/get_invite.ts new file mode 100644 index 000000000..b78854093 --- /dev/null +++ b/tests/helpers/invites/get_invite.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/get_invites.ts b/tests/helpers/invites/get_invites.ts new file mode 100644 index 000000000..53f7cdfa6 --- /dev/null +++ b/tests/helpers/invites/get_invites.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 f511b2430..afb100c7b 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -26,6 +26,11 @@ import { editMessageTest } from "./helpers/messages/edit_message.ts"; import { fetchSingleMemberTest } from "./helpers/members/fetch_members.ts"; import { pinMessageTests } from "./helpers/messages/pin.ts"; import { removeAllReactionTests, removeReactionEmojiTest, removeReactionTest } from "./helpers/messages/reactions.ts"; +import { createInviteTest } from "./helpers/invites/create_invite.ts"; +import { deleteInviteTest } from "./helpers/invites/delete_invite.ts"; +import { getChannelInvitesTest } from "./helpers/invites/get_channels_invites.ts"; +import { getInviteTest } from "./helpers/invites/get_invite.ts"; +import { getInvitesTest } from "./helpers/invites/get_invites.ts"; import { createChannelTests } from "./helpers/channels/create_channel.ts"; import { deleteChannelTests } from "./helpers/channels/delete_channel.ts"; import { createEmojiTest } from "./helpers/emojis/create_emoji.ts"; @@ -451,6 +456,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