mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
[Unit Tests] Helpers: invites
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user