mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
tests: add invites tests (#855)
* tests: add invites tests Co-authored-by: TriForMine <TriForMine@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
/** Returns an invite for the given code. */
|
/** Returns an invite for the given code or throws an error if the invite doesn't exists. */
|
||||||
export async function getInvite(inviteCode: string) {
|
export async function getInvite(inviteCode: string) {
|
||||||
const result: DiscordInvite = await rest.runMethod(
|
const result: DiscordInvite = await rest.runMethod(
|
||||||
"get",
|
"get",
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { cache } from "../../src/cache.ts";
|
||||||
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
|
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
|
||||||
|
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||||
|
import { botId } from "../../src/bot.ts";
|
||||||
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
|
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
|
||||||
|
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
|
||||||
|
import { getInvite } from "../../src/helpers/invites/get_invite.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[invite] create invite",
|
||||||
|
async fn() {
|
||||||
|
const channel = await createChannel(tempData.guildId, {
|
||||||
|
name: "invite-channel",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(channel);
|
||||||
|
|
||||||
|
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||||
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
|
if (!cache.channels.has(channel.id)) {
|
||||||
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const invite = await createInvite(channel.id, {
|
||||||
|
maxAge: 86400,
|
||||||
|
maxUses: 0,
|
||||||
|
temporary: false, // @ts-ignore
|
||||||
|
unique: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(invite);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
await getInvite(invite.code) !== undefined,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { cache } from "../../src/cache.ts";
|
||||||
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
|
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
|
||||||
|
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||||
|
import { botId } from "../../src/bot.ts";
|
||||||
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
|
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
|
||||||
|
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
|
||||||
|
import { getInvite } from "../../src/helpers/invites/get_invite.ts";
|
||||||
|
import { deleteInvite } from "../../src/helpers/invites/delete_invite.ts";
|
||||||
|
import { getChannelInvites } from "../../src/helpers/invites/get_channel_invites.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[invite] delete invite",
|
||||||
|
async fn() {
|
||||||
|
const channel = await createChannel(tempData.guildId, {
|
||||||
|
name: "invite-channel",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(channel);
|
||||||
|
|
||||||
|
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||||
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
|
if (!cache.channels.has(channel.id)) {
|
||||||
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const invite = await createInvite(channel.id, {
|
||||||
|
maxAge: 86400,
|
||||||
|
maxUses: 0,
|
||||||
|
temporary: false, // @ts-ignore
|
||||||
|
unique: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(invite);
|
||||||
|
|
||||||
|
await deleteInvite(channel.id, invite.code);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
(await getChannelInvites(channel.id))?.size,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { cache } from "../../src/cache.ts";
|
||||||
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
|
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
|
||||||
|
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||||
|
import { botId } from "../../src/bot.ts";
|
||||||
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
|
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
|
||||||
|
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
|
||||||
|
import { getInvite } from "../../src/helpers/invites/get_invite.ts";
|
||||||
|
import { getChannelInvites } from "../../src/helpers/invites/get_channel_invites.ts";
|
||||||
|
import { delay } from "../../src/util/utils.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[invite] get channel invites",
|
||||||
|
async fn() {
|
||||||
|
const channel = await createChannel(tempData.guildId, {
|
||||||
|
name: "invite-channel",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(channel);
|
||||||
|
|
||||||
|
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||||
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
|
if (!cache.channels.has(channel.id)) {
|
||||||
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const invite = await createInvite(channel.id, {
|
||||||
|
maxAge: 86400,
|
||||||
|
maxUses: 0,
|
||||||
|
temporary: false, // @ts-ignore
|
||||||
|
unique: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(invite);
|
||||||
|
|
||||||
|
const secondInvite = await createInvite(channel.id, {
|
||||||
|
maxAge: 32400,
|
||||||
|
maxUses: 5,
|
||||||
|
temporary: true, // @ts-ignore
|
||||||
|
unique: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(secondInvite);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
(await getChannelInvites(channel.id))?.size,
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { cache } from "../../src/cache.ts";
|
||||||
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
import { delayUntil } from "../util/delay_until.ts";
|
||||||
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
|
import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts";
|
||||||
|
import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
||||||
|
import { botId } from "../../src/bot.ts";
|
||||||
|
import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts";
|
||||||
|
import { startTyping } from "../../src/helpers/channels/start_typing.ts";
|
||||||
|
import { createInvite } from "../../src/helpers/invites/create_invite.ts";
|
||||||
|
import { getInvite } from "../../src/helpers/invites/get_invite.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[invite] get invite",
|
||||||
|
async fn() {
|
||||||
|
const channel = await createChannel(tempData.guildId, {
|
||||||
|
name: "invite-channel",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(channel);
|
||||||
|
|
||||||
|
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||||
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
|
if (!cache.channels.has(channel.id)) {
|
||||||
|
throw new Error(
|
||||||
|
"The channel seemed to be created but it was not cached.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const invite = await createInvite(channel.id, {
|
||||||
|
maxAge: 86400,
|
||||||
|
maxUses: 0,
|
||||||
|
temporary: false, // @ts-ignore
|
||||||
|
unique: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(invite);
|
||||||
|
|
||||||
|
const fetchedInvite = await getInvite(invite.code);
|
||||||
|
|
||||||
|
assertExists(fetchedInvite);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
fetchedInvite.code,
|
||||||
|
invite.code,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
import { assertEquals } from "../deps.ts";
|
||||||
|
import { getInvites } from "../../src/helpers/invites/get_invites.ts";
|
||||||
|
import { cache } from "../../src/cache.ts";
|
||||||
|
|
||||||
|
async function ifItFailsBlameWolf(type: "getter" | "raw") {
|
||||||
|
let invites;
|
||||||
|
|
||||||
|
if (type === "raw") {
|
||||||
|
invites = await getInvites(tempData.guildId);
|
||||||
|
} else {
|
||||||
|
const guild = cache.guilds.get(tempData.guildId);
|
||||||
|
invites = await guild?.invites();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals((invites?.size || 0) >= 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[invite] get invites",
|
||||||
|
async fn() {
|
||||||
|
await ifItFailsBlameWolf("raw");
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "[invite] guild.invites()",
|
||||||
|
async fn() {
|
||||||
|
await ifItFailsBlameWolf("getter");
|
||||||
|
},
|
||||||
|
...defaultTestOptions,
|
||||||
|
});
|
||||||
@@ -34,6 +34,13 @@ import "./emojis/edit_emoji.ts";
|
|||||||
import "./emojis/get_emoji.ts";
|
import "./emojis/get_emoji.ts";
|
||||||
import "./emojis/get_emojis.ts";
|
import "./emojis/get_emojis.ts";
|
||||||
|
|
||||||
|
// Invites tests
|
||||||
|
import "./invites/create_invite.ts";
|
||||||
|
import "./invites/delete_invite.ts";
|
||||||
|
import "./invites/get_channel_invites.ts";
|
||||||
|
import "./invites/get_invite.ts";
|
||||||
|
import "./invites/get_invites.ts";
|
||||||
|
|
||||||
// Messages tests
|
// Messages tests
|
||||||
import "./messages/add_reaction.ts";
|
import "./messages/add_reaction.ts";
|
||||||
import "./messages/add_reactions.ts";
|
import "./messages/add_reactions.ts";
|
||||||
|
|||||||
Reference in New Issue
Block a user