mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 09:20:08 +00:00
Merge pull request #1400 from TriForMine/unit-tests-invites
[Unit Tests] Helpers: invites
This commit is contained in:
14
tests/helpers/invites/create_invite.ts
Normal file
14
tests/helpers/invites/create_invite.ts
Normal file
@@ -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);
|
||||
}
|
||||
19
tests/helpers/invites/delete_invite.ts
Normal file
19
tests/helpers/invites/delete_invite.ts
Normal file
@@ -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);
|
||||
}
|
||||
30
tests/helpers/invites/get_channels_invites.ts
Normal file
30
tests/helpers/invites/get_channels_invites.ts
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
19
tests/helpers/invites/get_invite.ts
Normal file
19
tests/helpers/invites/get_invite.ts
Normal file
@@ -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);
|
||||
}
|
||||
22
tests/helpers/invites/get_invites.ts
Normal file
22
tests/helpers/invites/get_invites.ts
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
46
tests/mod.ts
46
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
|
||||
|
||||
Reference in New Issue
Block a user