fix: improve unit tests style

This commit is contained in:
Skillz4Killz
2021-11-22 16:34:30 +00:00
committed by GitHub
parent 70e9ef29ac
commit d23ff868c7
46 changed files with 1048 additions and 545 deletions
+3 -3
View File
@@ -20,12 +20,12 @@ export function transformAuditlogEntry(
return { return {
key: change.key, key: change.key,
new: { new: {
id: bot.transformers.snowflake(change.new_value.id!), id: change.new_value.id ? bot.transformers.snowflake(change.new_value.id) : undefined,
name: change.new_value.name, name: change.new_value.name,
}, },
old: { old: {
id: bot.transformers.snowflake(change.old_value.id!), id: change.old_value?.id ? bot.transformers.snowflake(change.old_value.id) : undefined,
name: change.old_value.name, name: change.old_value?.name,
}, },
}; };
case "discovery_splash_hash": case "discovery_splash_hash":
+1 -1
View File
@@ -63,7 +63,7 @@ export type AuditLogChange =
} }
| { | {
newValue: Partial<Role>; newValue: Partial<Role>;
oldValue: Partial<Role>; oldValue?: Partial<Role>;
key: "$add" | "$remove"; key: "$add" | "$remove";
} }
| { | {
+11
View File
@@ -0,0 +1,11 @@
import { bot } from "./mod.ts";
import { memoryBenchmarks } from "../benchmarks/index.ts";
import { sanitizeMode } from "./constants.ts";
Deno.test({
name: "[Memory] Benchmark memory tests",
fn: async (t) => {
await memoryBenchmarks(bot, true);
},
...sanitizeMode,
});
+12
View File
@@ -1 +1,13 @@
export const CACHED_COMMUNITY_GUILD_ID = 907350958810480671n; export const CACHED_COMMUNITY_GUILD_ID = 907350958810480671n;
// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS
export const sanitizeMode = {
sanitizeResources: false,
sanitizeOps: false,
sanitizeExit: false,
};
// USED FOR ROLE CHANGE EVENTS
export const roleChanges = new Map<bigint, bigint[]>();
export const banCounters = new Map<bigint, boolean>();
+24
View File
@@ -0,0 +1,24 @@
import { assertExists } from "../deps.ts";
import { bot,guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[emoji] create an emoji",
fn: async (t) => {
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
});
// Assertions
assertExists(emoji);
// Delay the execution to allow event to be processed
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be created but it was not cached.");
}
},
});
+32
View File
@@ -0,0 +1,32 @@
import { assertExists } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[emoji] delete an emoji without a reason",
fn: async (t) => {
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
});
// Assertions
assertExists(emoji);
// Delay the execution to allow event to be processed
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be created but it was not cached.");
}
await bot.helpers.deleteEmoji(guild.id, emoji.id, "with a reason");
await delayUntil(10000, async () => !bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be deleted but it's still cached.");
}
},
});
+32
View File
@@ -0,0 +1,32 @@
import { assertExists } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[emoji] delete an emoji without a reason",
fn: async (t) => {
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
});
// Assertions
assertExists(emoji);
// Delay the execution to allow event to be processed
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be created but it was not cached.");
}
await bot.helpers.deleteEmoji(guild.id, emoji.id);
await delayUntil(10000, async () => !bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be deleted but it's still cached.");
}
},
});
+37
View File
@@ -0,0 +1,37 @@
import { assertExists } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[emoji] edit an emoji",
fn: async (t) => {
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
});
// Assertions
assertExists(emoji);
// Delay the execution to allow event to be processed
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be created but it was not cached.");
}
await bot.helpers.editEmoji(guild.id, emoji.id, {
name: "blamewolf_infinite",
});
await delayUntil(
10000,
async () => bot.cache.guilds.get(guild.id)?.emojis?.get(emoji.id)?.name === "blamewolf_infinite"
);
if (bot.cache.guilds.get(guild.id)?.emojis?.get(emoji.id)?.name !== "blamewolf_infinite") {
throw new Error("The emoji seemed to be edited but the cache was not updated.");
}
},
});
+31
View File
@@ -0,0 +1,31 @@
import { assertExists } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[emoji] get an emoji",
fn: async (t) => {
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
});
// Assertions
assertExists(emoji);
// Delay the execution to allow event to be processed
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be created but it was not cached.");
}
bot.cache.guilds.get(guild.id)?.emojis?.delete(emoji.id);
const getEmoji = await bot.helpers.getEmoji(guild.id, emoji.id, true);
// Assertions
assertExists(getEmoji);
},
});
+30
View File
@@ -0,0 +1,30 @@
import { assertExists } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[emoji] get multiple emojis",
fn: async (t) => {
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
});
// Assertions
assertExists(emoji);
// Delay the execution to allow event to be processed
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
throw new Error("The emoji seemed to be created but it was not cached.");
}
const emojis = await bot.helpers.getEmojis(guild.id);
if (emojis.size === 0) {
throw new Error("The getEmojis function returned 0 emojis.");
}
},
});
-28
View File
@@ -1,28 +0,0 @@
import { delay } from "../src/util/utils.ts";
// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS
const sanitizeMode = {
sanitizeResources: false,
sanitizeOps: false,
sanitizeExit: false,
};
Deno.test({
name: "- Example Tests",
fn: async (t) => {
await t.step("Nested tests", async (t) => {
await t.step({ name: "this is quick", fn: () => {}, ...sanitizeMode });
await Promise.all([
t.step({
name: "[example] 1",
fn: async (t) => {
await delay(60000);
},
...sanitizeMode,
}),
])
});
},
...sanitizeMode,
});
-27
View File
@@ -3,32 +3,5 @@ import { assertExists } from "../../deps.ts";
import { delayUntil } from "../../utils.ts"; import { delayUntil } from "../../utils.ts";
export async function editEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { export async function editEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
const emoji = await bot.helpers.createEmoji(guildId, {
name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [],
});
// Assertions
assertExists(emoji);
// Delay the execution to allow event to be processed
// await delayUntil(10000, async () => bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id));
// if (!bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id)) {
// throw new Error("The emoji seemed to be created but it was not cached.");
// }
await bot.helpers.editEmoji(guildId, emoji.id, {
name: "blamewolf_infinite",
});
// await delayUntil(
// 10000,
// async () => bot.cache.guilds.get(guildId)?.emojis?.get(emoji.id)?.name === "blamewolf_infinite"
// );
// if (bot.cache.guilds.get(guildId)?.emojis?.get(emoji.id)?.name !== "blamewolf_infinite") {
// throw new Error("The emoji seemed to be edited but the cache was not updated.");
// }
} }
@@ -2,14 +2,5 @@ import { Bot } from "../../../../src/bot.ts";
import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../../src/types/guilds/scheduledEvents.ts"; import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../../src/types/guilds/scheduledEvents.ts";
export async function deleteScheduledEventTests(bot: Bot, guildId: bigint, t: Deno.TestContext) { export async function deleteScheduledEventTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
const event = await bot.helpers.createScheduledEvent(guildId, {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + 1200000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.External,
location: "heaven",
});
await bot.helpers.deleteScheduledEvent(guildId, event.id);
} }
+2 -19
View File
@@ -3,33 +3,16 @@ import { CreateGuildBan } from "../../../src/types/mod.ts";
import { assertEquals } from "../../deps.ts"; import { assertEquals } from "../../deps.ts";
import { delayUntil } from "../../utils.ts"; import { delayUntil } from "../../utils.ts";
const banCounters = new Map<bigint, boolean>();
export async function banTest(bot: Bot, t: Deno.TestContext, guildId: bigint, id: bigint, options?: CreateGuildBan) { export async function banTest(bot: Bot, t: Deno.TestContext, guildId: bigint, id: bigint, options?: CreateGuildBan) {
bot.events.guildBanAdd = function (bot, user, guildId) {
banCounters.set(user.id, true);
};
await bot.helpers.banMember(guildId, id, options);
await delayUntil(10000, () => banCounters.get(id));
assertEquals(banCounters.get(id), true);
} }
export async function getBansTest(bot: Bot, t: Deno.TestContext, guildId: bigint) { export async function getBansTest(bot: Bot, t: Deno.TestContext, guildId: bigint) {
const bans = await bot.helpers.getBans(guildId);
assertEquals(bans.size > 1, true);
} }
export async function unbanTest(bot: Bot, t: Deno.TestContext, guildId: bigint, id: bigint) { export async function unbanTest(bot: Bot, t: Deno.TestContext, guildId: bigint, id: bigint) {
bot.events.guildBanRemove = function (bot, user, guildId) {
banCounters.set(user.id, false);
};
await bot.helpers.unbanMember(guildId, id);
await delayUntil(10000, () => !banCounters.get(id));
assertEquals(banCounters.get(id), false);
} }
-6
View File
@@ -2,11 +2,5 @@ import { Bot } from "../../../src/bot.ts";
import { assertExists } from "../../deps.ts"; import { assertExists } from "../../deps.ts";
export async function fetchSingleMemberTest(bot: Bot, guildId: bigint, t: Deno.TestContext) { export async function fetchSingleMemberTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
await bot.helpers.fetchMembers(guildId, 0, {
userIds: [bot.id],
limit: 1,
});
// Assertions
assertExists(bot.cache.members.get(BigInt(`${bot.id}${guildId}`)));
} }
-14
View File
@@ -1,14 +0,0 @@
import { Bot } from "../../../src/bot.ts";
import { assertEquals } from "../../deps.ts";
export async function getDiscoveryCategoriesTest(bot: Bot, t: Deno.TestContext) {
const categories = await bot.helpers.getDiscoveryCategories();
assertEquals(categories.size > 0, true);
}
export async function validDiscoveryTermTest(bot: Bot, t: Deno.TestContext) {
const valid = await bot.helpers.validDiscoveryTerm("Bots");
assertEquals(valid, true);
}
-3
View File
@@ -2,8 +2,5 @@ import { Bot } from "../../../src/bot.ts";
import { assertExists } from "../../deps.ts"; import { assertExists } from "../../deps.ts";
export async function getUserTests(bot: Bot, t: Deno.TestContext) { export async function getUserTests(bot: Bot, t: Deno.TestContext) {
const user = await bot.helpers.getUser(bot.id);
assertExists(user);
assertExists(bot.transformers.user(bot, user));
} }
-27
View File
@@ -35,32 +35,5 @@ export async function removeRoleTest(
options: { reason?: string }, options: { reason?: string },
t: Deno.TestContext t: Deno.TestContext
) { ) {
const role = await bot.helpers.createRole(guildId, {
name: "hoti",
});
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guildId)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guildId)?.roles.has(role.id));
bot.events.guildMemberUpdate = function (bot, member, user) {
roleChanges.set(user.id, member.roles);
};
await bot.helpers.addRole(guildId, bot.id, role.id, options.reason);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), true);
await bot.helpers.removeRole(guildId, bot.id, role.id, options.reason);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => !roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), false);
} }
+17
View File
@@ -0,0 +1,17 @@
import { assertExists } from "../deps.ts";
import { bot, channel } from "../mod.ts";
Deno.test({
name: "[invite] create an invite",
async fn(t) {
const invite = await bot.helpers.createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: false,
});
// Assertions
assertExists(invite);
},
});
+22
View File
@@ -0,0 +1,22 @@
import { assertExists } from "../deps.ts";
import { bot, channel } from "../mod.ts";
Deno.test({
name: "[invite] delete an invite",
async fn(t) {
const invite = await bot.helpers.createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: false,
});
// Assertions
assertExists(invite);
const deletedInvite = await bot.helpers.deleteInvite(invite.code);
// Assertions
assertExists(deletedInvite);
},
});
+31
View File
@@ -0,0 +1,31 @@
import { assertEquals, assertExists } from "../deps.ts";
import { bot, channel } from "../mod.ts";
Deno.test({
name: "[invite] get channels invites",
async fn(t) {
const invite = await bot.helpers.createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: true,
});
// Assertions
assertExists(invite);
const secondInvite = await bot.helpers.createInvite(channel.id, {
maxAge: 0,
maxUses: 2,
temporary: true,
unique: true,
});
// Assertions
assertExists(secondInvite);
const invites = await bot.helpers.getChannelInvites(channel.id);
assertEquals(invites.size > 1, true);
},
});
+32
View File
@@ -0,0 +1,32 @@
import { assertExists, assertEquals, assertNotEquals } from "../deps.ts";
import { bot, channel, guild } from "../mod.ts";
Deno.test({
name: "[invite] get invite",
async fn(t) {
const invite = await bot.helpers.createInvite(channel.id, {
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);
await t.step({
name: "[invite] get invites",
async fn() {
const fetchedInvites = await bot.helpers.getInvites(guild.id);
assertExists(fetchedInvites);
assertNotEquals(fetchedInvites.size, 0);
},
});
},
});
+22
View File
@@ -0,0 +1,22 @@
import { assertExists, assertNotEquals } from "../deps.ts";
import { bot, channel, guild } from "../mod.ts";
Deno.test({
name: "[invite] get invites",
async fn(t) {
const invite = await bot.helpers.createInvite(channel.id, {
maxAge: 86400,
maxUses: 0,
temporary: false,
unique: false,
});
// Assertions
assertExists(invite);
const fetchedInvites = await bot.helpers.getInvites(guild.id);
assertExists(fetchedInvites);
assertNotEquals(fetchedInvites.size, 0);
},
});
+14
View File
@@ -0,0 +1,14 @@
import { assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[member] format a members avatar url",
fn: async (t) => {
assertEquals(
bot.helpers.avatarURL(130136895395987456n, 8840, {
avatar: 4055337350987360625717955448021200177333n,
}),
"https://cdn.discordapp.com/avatars/130136895395987456/eae5905ad2d18d7c8deca20478b088b5.jpg?size=128"
);
},
});
+93
View File
@@ -0,0 +1,93 @@
import { banCounters } from "../constants.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
// THIS IS WOLF, IF ANYTHING BREAKS BLAME HIM!
const wolfID = 270273690074087427n;
// THIS IS IAN, HE PLAY'S GOLDEN SUN. BAN BEFORE HE MAKES US ADDICTED TO IT!!!
const ianID = 90339695967350784n;
// THESE BAN TESTS SHOULD BE DONE ONE BY ONE
Deno.test({
name: "[member] ban member test group",
fn: async (t) => {
await t.step({
name: "[member] ban user from guild without reason",
fn: async () => {
bot.events.guildBanAdd = function (_, user) {
banCounters.set(user.id, true);
};
await bot.helpers.banMember(guild.id, wolfID);
await delayUntil(10000, () => banCounters.get(wolfID));
assertEquals(banCounters.get(wolfID), true);
},
});
await t.step({
name: "[member] get a single user's ban",
fn: async () => {
assertExists(await bot.helpers.getBan(guild.id, 270273690074087427n));
},
});
await t.step({
name: "[member] ban member from guild with reason",
fn: async () => {
bot.events.guildBanAdd = function (_, user) {
banCounters.set(user.id, true);
};
await bot.helpers.banMember(guild.id, ianID, { reason: "Blame Wolf" });
await delayUntil(10000, () => banCounters.get(ianID));
assertEquals(banCounters.get(wolfID), true);
},
});
await t.step({
name: "[member] get bans on a server",
fn: async () => {
const bans = await bot.helpers.getBans(guild.id);
assertEquals(bans.size > 1, true);
},
});
await t.step({
name: "[member] fetch a single member by id",
fn: async () => {
await bot.helpers.fetchMembers(guild.id, 0, {
userIds: [bot.id],
limit: 1,
});
// Assertions
assertExists(bot.cache.members.get(BigInt(`${bot.id}${guild.id}`)));
},
});
await t.step({
name: "[member] unban member from guild",
fn: async () => {
bot.events.guildBanRemove = function (bot, user, guildId) {
banCounters.set(user.id, false);
};
await Promise.all([bot.helpers.unbanMember(guild.id, wolfID), bot.helpers.unbanMember(guild.id, ianID)]);
await delayUntil(10000, () => !banCounters.get(wolfID) && !banCounters.get(ianID));
assertEquals(banCounters.get(wolfID), false);
assertEquals(banCounters.get(ianID), false);
},
});
},
});
+11
View File
@@ -0,0 +1,11 @@
import { assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[discovery] get categories from discovery",
fn: async (t) => {
const categories = await bot.helpers.getDiscoveryCategories();
assertEquals(categories.size > 0, true);
},
});
+12
View File
@@ -0,0 +1,12 @@
import { assertExists } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[User] get a user and transform",
fn: async (t) => {
const user = await bot.helpers.getUser(bot.id);
assertExists(user);
assertExists(bot.transformers.user(bot, user));
},
});
+9
View File
@@ -0,0 +1,9 @@
import { assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[tranform] snowflake to bigint",
fn: async (t) => {
assertEquals(130136895395987456n, bot.transformers.snowflake("130136895395987456"));
},
});
+11
View File
@@ -0,0 +1,11 @@
import { assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[discovery] Validate a discovery search term",
fn: async (t) => {
const valid = await bot.helpers.validDiscoveryTerm("Bots");
assertEquals(valid, true);
},
});
+44 -401
View File
@@ -1,5 +1,4 @@
// import { UNITTEST_TOKEN } from "../configs.ts"; import { UNITTEST_TOKEN } from "../configs.ts";
import { memoryBenchmarks } from "../benchmarks/index.ts";
import { createBot, createEventHandlers, ChannelTypes, OverwriteTypes, setupBot, startBot } from "../mod.ts"; import { createBot, createEventHandlers, ChannelTypes, OverwriteTypes, setupBot, startBot } from "../mod.ts";
import { assertEquals, assertExists, enableCachePlugin } from "./deps.ts"; import { assertEquals, assertExists, enableCachePlugin } from "./deps.ts";
import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts"; import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts";
@@ -17,7 +16,6 @@ import "./local.ts";
import { getMessageTest } from "./helpers/messages/getMessage.ts"; import { getMessageTest } from "./helpers/messages/getMessage.ts";
import { addReactionTest } from "./helpers/messages/reactions.ts"; import { addReactionTest } from "./helpers/messages/reactions.ts";
import { editMessageTest } from "./helpers/messages/editMessage.ts"; import { editMessageTest } from "./helpers/messages/editMessage.ts";
import { fetchSingleMemberTest } from "./helpers/members/fetchMembers.ts";
import { pinMessageTests } from "./helpers/messages/pin.ts"; import { pinMessageTests } from "./helpers/messages/pin.ts";
import { removeAllReactionTests, removeReactionEmojiTest, removeReactionTest } from "./helpers/messages/reactions.ts"; import { removeAllReactionTests, removeReactionEmojiTest, removeReactionTest } from "./helpers/messages/reactions.ts";
import { createInviteTest } from "./helpers/invites/createInvite.ts"; import { createInviteTest } from "./helpers/invites/createInvite.ts";
@@ -27,18 +25,6 @@ import { getInviteTest } from "./helpers/invites/getInvite.ts";
import { getInvitesTest } from "./helpers/invites/getInvites.ts"; import { getInvitesTest } from "./helpers/invites/getInvites.ts";
import { createChannelTests } from "./helpers/channels/createChannel.ts"; import { createChannelTests } from "./helpers/channels/createChannel.ts";
import { deleteChannelTests } from "./helpers/channels/deleteChannel.ts"; import { deleteChannelTests } from "./helpers/channels/deleteChannel.ts";
import { createEmojiTest } from "./helpers/emojis/createEmoji.ts";
import { deleteEmojiWithoutReasonTest, deleteEmojiWithReasonTest } from "./helpers/emojis/deleteEmoji.ts";
import { editEmojiTest } from "./helpers/emojis/editEmoji.ts";
import { getEmojiTest } from "./helpers/emojis/getEmoji.ts";
import { getEmojisTest } from "./helpers/emojis/getEmojis.ts";
import { getBansTest, unbanTest, banTest } from "./helpers/members/ban.ts";
import { createRoleTests } from "./helpers/roles/createRole.ts";
import { deleteRoleTests } from "./helpers/roles/deleteRole.ts";
import { getRolesTest } from "./helpers/roles/getRoles.ts";
import { editRoleTests } from "./helpers/roles/editRole.ts";
import { addRoleTest, removeRoleTest } from "./helpers/roles/roleChanges.ts";
import { getUserTests } from "./helpers/misc/user.ts";
import { createGuildTests } from "./helpers/guilds/createGuild.ts"; import { createGuildTests } from "./helpers/guilds/createGuild.ts";
import { deleteGuildTests } from "./helpers/guilds/deleteGuild.ts"; import { deleteGuildTests } from "./helpers/guilds/deleteGuild.ts";
import { editGuildTests } from "./helpers/guilds/editGuild.ts"; import { editGuildTests } from "./helpers/guilds/editGuild.ts";
@@ -48,33 +34,20 @@ import { getBanTests } from "./helpers/guilds/getBan.ts";
import { getBansTests } from "./helpers/guilds/getBans.ts"; import { getBansTests } from "./helpers/guilds/getBans.ts";
import { getGuildTests } from "./helpers/guilds/getGuild.ts"; import { getGuildTests } from "./helpers/guilds/getGuild.ts";
import { getVanityURLTests } from "./helpers/guilds/getVanityUrl.ts"; import { getVanityURLTests } from "./helpers/guilds/getVanityUrl.ts";
import { getDiscoveryCategoriesTest, validDiscoveryTermTest } from "./helpers/misc/discoveries.ts";
import { categoryChildrenTest } from "./helpers/channels/categoryChannels.ts"; import { categoryChildrenTest } from "./helpers/channels/categoryChannels.ts";
import { channelOverwriteHasPermissionTest } from "./helpers/channels/channelOverwriteHasPermission.ts"; import { channelOverwriteHasPermissionTest } from "./helpers/channels/channelOverwriteHasPermission.ts";
import { cloneChannelTests } from "./helpers/channels/cloneChannel.ts"; import { cloneChannelTests } from "./helpers/channels/cloneChannel.ts";
import { deleteChannelOverwriteTests } from "./helpers/channels/deleteChannelOverwrite.ts"; import { deleteChannelOverwriteTests } from "./helpers/channels/deleteChannelOverwrite.ts";
import { editChannelTests } from "./helpers/channels/editChannel.ts"; import { editChannelTests } from "./helpers/channels/editChannel.ts";
import { createScheduledEventTests } from "./helpers/guilds/scheduledEvents/createScheduledEvent.ts"; import { CACHED_COMMUNITY_GUILD_ID, sanitizeMode } from "./constants.ts";
import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../src/types/guilds/scheduledEvents.ts";
import { GuildFeatures } from "../src/types/guilds/guildFeatures.ts";
import { editScheduledEventTests } from "./helpers/guilds/scheduledEvents/editScheduledEvent.ts";
import { deleteScheduledEventTests } from "./helpers/guilds/scheduledEvents/deleteScheduledEvent.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "./constants.ts";
// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS const botId = BigInt(atob(UNITTEST_TOKEN.split(".")[0]));
const sanitizeMode = { // const botId = BigInt(atob(Deno.env.get("DISCORD_TOKEN")!.split(".")[0]));
sanitizeResources: false,
sanitizeOps: false,
sanitizeExit: false,
};
// const botId = BigInt(atob(UNITTEST_TOKEN.split(".")[0]));
const botId = BigInt(atob(Deno.env.get("DISCORD_TOKEN")!.split(".")[0]));
let startedAt = 0; let startedAt = 0;
const bot = createBot({ export const bot = createBot({
// token: UNITTEST_TOKEN || Deno.env.get("DISCORD_TOKEN"), token: UNITTEST_TOKEN || Deno.env.get("DISCORD_TOKEN"),
token: Deno.env.get("DISCORD_TOKEN")!, // token: Deno.env.get("DISCORD_TOKEN")!,
botId, botId,
events: createEventHandlers({ events: createEventHandlers({
ready: () => { ready: () => {
@@ -117,7 +90,7 @@ if (bot.cache.guilds.size() <= 10) {
await delayUntil(10000, () => Boolean(startedAt)); await delayUntil(10000, () => Boolean(startedAt));
// CREATE ONE GUILD SO WE CAN REUSE LATER TO SAVE RATE LIMITS // CREATE ONE GUILD SO WE CAN REUSE LATER TO SAVE RATE LIMITS
const guild = await bot.helpers.createGuild({ name: "Discordeno Test" }); export const guild = await bot.helpers.createGuild({ name: "Discordeno Test" });
// Assertions // Assertions
assertExists(guild); assertExists(guild);
@@ -131,142 +104,15 @@ if (!bot.cache.guilds.has(guild.id)) {
throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`); throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`);
} }
const channel = await bot.helpers.createChannel(guild.id, { name: "Discordeno-test" }); export const channel = await bot.helpers.createChannel(guild.id, { name: "Discordeno-test" });
// Assertions // Assertions
assertExists(channel); assertExists(channel);
assertEquals(channel.type, ChannelTypes.GuildText); assertEquals(channel.type, ChannelTypes.GuildText);
const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz"); export const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz");
Deno.test({ import "./benchmark.ts";
name: "[scheduled event] create a guild scheduled event with stage entity",
fn: async (t) => {
await createScheduledEventTests(
bot,
CACHED_COMMUNITY_GUILD_ID,
{
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.StageInstance,
},
t
);
},
...sanitizeMode,
});
Deno.test({
name: "[scheduled event] create a guild scheduled event with stage entity with an end time.",
fn: async (t) => {
await createScheduledEventTests(
bot,
CACHED_COMMUNITY_GUILD_ID,
{
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + (600000 + 1),
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.StageInstance,
},
t
);
},
...sanitizeMode,
});
Deno.test({
name: "[scheduled event] create a guild scheduled event with voice entity",
fn: async (t) => {
await createScheduledEventTests(
bot,
guild.id,
{
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.Voice,
},
t
);
},
...sanitizeMode,
});
Deno.test({
name: "[scheduled event] create a guild scheduled event with voice entity with an end time.",
fn: async (t) => {
await createScheduledEventTests(
bot,
guild.id,
{
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + (600000 + 1),
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.Voice,
},
t
);
},
...sanitizeMode,
});
Deno.test({
name: "[scheduled event] create a guild scheduled event with external entity",
fn: async (t) => {
await createScheduledEventTests(
bot,
guild.id,
{
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + 1200000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.External,
location: "heaven",
},
t
);
},
...sanitizeMode,
});
Deno.test({
name: "[scheduled event] create a guild scheduled event with external entity with an end time.",
fn: async (t) => {
await createScheduledEventTests(
bot,
guild.id,
{
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + (600000 + 1),
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.External,
location: "heaven",
},
t
);
},
...sanitizeMode,
});
Deno.test({
name: "[scheduled event] edit a scheduled event",
fn: async (t) => {
await editScheduledEventTests(bot, CACHED_COMMUNITY_GUILD_ID, t);
},
...sanitizeMode,
});
Deno.test({
name: "[scheduled event] delete a scheduled event",
fn: async (t) => {
await deleteScheduledEventTests(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({ Deno.test({
name: "[guild] format a guild's icon url", name: "[guild] format a guild's icon url",
@@ -722,242 +568,39 @@ Deno.test({
...sanitizeMode, ...sanitizeMode,
}); });
Deno.test({ import "./emoji/createEmoji.ts";
name: "[invite] create an invite", import "./emoji/deleteEmojiWithReason.ts";
async fn(t) { import "./emoji/deleteEmojiWithoutReason.ts";
await createInviteTest(bot, channel.id, t); import "./emoji/editEmoji.ts";
}, import "./emoji/getEmoji.ts";
...sanitizeMode, import "./emoji/getMultipleEmojis.ts";
}); import "./invite/createInvite.ts";
Deno.test({ import "./invite/deleteInvite.ts";
name: "[invite] delete an invite", import "./invite/getChannelInvites.ts";
async fn(t) { import "./invite/getInvite.ts";
await deleteInviteTest(bot, channel.id, t); import "./invite/getInvites.ts";
}, import "./members/avatarlUrl.ts";
...sanitizeMode, import "./members/ban.ts";
}); import "./misc/getDiscoveryCategories.ts";
Deno.test({ import "./misc/getUser.ts";
name: "[invite] get channels invites", import "./misc/snowflake.ts";
async fn(t) { import "./misc/validateDiscovery.ts";
await getChannelInvitesTest(bot, channel.id, t); import "./role/addRole.ts";
}, import "./role/createRoleWithoutReason.ts";
...sanitizeMode, import "./role/createRoleWithReason.ts";
}); import "./role/deleteRoleWithoutReason.ts";
Deno.test({ import "./role/deleteRoleWithReason.ts";
name: "[invite] get invite", import "./role/editRole.ts";
async fn(t) { import "./role/getAllRoles.ts";
await getInviteTest(bot, channel.id, t); import "./role/removeRole.ts";
}, import "./scheduledEvents/createExternalEventWithEndtime.ts";
...sanitizeMode, import "./scheduledEvents/createExternalEventWithoutEndtime.ts";
}); import "./scheduledEvents/createStageEventWithEndtime.ts";
Deno.test({ import "./scheduledEvents/createStageEventWithoutEndtime.ts";
name: "[invite] get invites", import "./scheduledEvents/createVoiceEventWithEndtime.ts";
async fn(t) { import "./scheduledEvents/createVoiceEventWithoutEndtime.ts";
await getInvitesTest(bot, channel.id, guild.id, t); import "./scheduledEvents/deleteEvent.ts";
}, import "./scheduledEvents/editEvent.ts";
...sanitizeMode,
});
// THESE BAN TESTS SHOULD BE DONE ONE BY ONE
Deno.test({
name: "[member] ban user from guild without reason",
fn: async (t) => {
// THIS IS WOLF, IF ANYTHING BREAKS BLAME HIM!
await banTest(bot, t, guild.id, 270273690074087427n, { reason: "Blame Wolf" });
},
...sanitizeMode,
});
Deno.test({
name: "[member] get a single user's ban",
fn: async (t) => {
assertExists(await bot.helpers.getBan(guild.id, 270273690074087427n));
},
...sanitizeMode,
});
Deno.test({
name: "[member] ban member from guild without reason",
fn: async (t) => {
// THIS IS IAN, HE PLAY'S GOLDEN SUN. BAN BEFORE HE MAKES US ADDICTED TO IT!!!
await banTest(bot, t, guild.id, 90339695967350784n);
},
...sanitizeMode,
});
Deno.test({
name: "[member] get bans on a server",
fn: async (t) => {
await getBansTest(bot, t, guild.id);
},
...sanitizeMode,
});
Deno.test({
name: "[member] fetch a single member by id",
fn: async (t) => {
await fetchSingleMemberTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[member] format a members avatar url",
fn: async (t) => {
assertEquals(
bot.helpers.avatarURL(130136895395987456n, 8840, {
avatar: 4055337350987360625717955448021200177333n,
}),
"https://cdn.discordapp.com/avatars/130136895395987456/eae5905ad2d18d7c8deca20478b088b5.jpg?size=128"
);
},
...sanitizeMode,
});
Deno.test({
name: "[member] unban member from guild",
fn: async (t) => {
await Promise.all([
unbanTest(bot, t, guild.id, 270273690074087427n),
unbanTest(bot, t, guild.id, 90339695967350784n),
]);
},
...sanitizeMode,
});
Deno.test({
name: "[emoji] create an emoji",
fn: async (t) => {
await createEmojiTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[emoji] delete an emoji without a reason",
fn: async (t) => {
await deleteEmojiWithoutReasonTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[emoji] delete an emoji with a reason",
fn: async (t) => {
await deleteEmojiWithReasonTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[emoji] edit an emoji",
fn: async (t) => {
await editEmojiTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[emoji] get an emoji",
fn: async (t) => {
await getEmojiTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[emoji] get multiple emojis",
fn: async (t) => {
await getEmojisTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] get all roles on a server",
fn: async (t) => {
await getRolesTest(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] create a role without a reason",
fn: async (t) => {
await createRoleTests(bot, guild.id, {}, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] create a role with a reason",
fn: async (t) => {
await createRoleTests(bot, guild.id, { reason: "Blame wolfy" }, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] delete a role without a reason",
fn: async (t) => {
await deleteRoleTests(bot, guild.id, {}, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] delete a role with a reason",
fn: async (t) => {
await deleteRoleTests(bot, guild.id, { reason: "Blame wolfy" }, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] edit a role",
fn: async (t) => {
await editRoleTests(bot, guild.id, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] add a role to a member",
fn: async (t) => {
await addRoleTest(bot, guild.id, { reason: "Blame wolf" }, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Role] remove a role to a member",
fn: async (t) => {
await removeRoleTest(bot, guild.id, { reason: "Blame wolf" }, t);
},
...sanitizeMode,
});
Deno.test({
name: "[User] get a user and transform",
fn: async (t) => {
await getUserTests(bot, t);
},
...sanitizeMode,
});
Deno.test({
name: "[tranform] snowflake to bigint",
fn: async (t) => {
assertEquals(130136895395987456n, bot.transformers.snowflake("130136895395987456"));
},
...sanitizeMode,
});
Deno.test({
name: "[discovery] Validate a discovery search term",
fn: async (t) => {
await validDiscoveryTermTest(bot, t);
},
...sanitizeMode,
});
Deno.test({
name: "[discovery] get categories from discovery",
fn: async (t) => {
await getDiscoveryCategoriesTest(bot, t);
},
...sanitizeMode,
});
Deno.test({
name: "[Memory] Benchmark memory tests",
fn: async (t) => {
await memoryBenchmarks(bot, true);
},
...sanitizeMode,
});
// await bot.helpers.deleteGuild(guild.id); // await bot.helpers.deleteGuild(guild.id);
// await stopBot(bot); // await stopBot(bot);
+32
View File
@@ -0,0 +1,32 @@
import { roleChanges } from "../constants.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] add a role to a member",
fn: async (t) => {
const role = await bot.helpers.createRole(guild.id, {
name: "hoti",
});
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
bot.events.guildMemberUpdate = function (bot, member, user) {
roleChanges.set(user.id, member.roles);
};
await bot.helpers.addRole(guild.id, bot.id, role.id, "Blame wolf");
// Delay the execution to allow event to be processed
await delayUntil(10000, () => roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), true);
},
});
+20
View File
@@ -0,0 +1,20 @@
import { assertExists } from "../deps.ts";
import { createRoleTests } from "../helpers/roles/createRole.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] create a role with a reason",
fn: async (t) => {
await createRoleTests(bot, guild.id, { reason: "Blame wolfy" }, t);
const role = await bot.helpers.createRole(guild.id, { name: "hoti" }, "Blame wolfy");
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
},
});
+20
View File
@@ -0,0 +1,20 @@
import { assertExists } from "../deps.ts";
import { createRoleTests } from "../helpers/roles/createRole.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] create a role without a reason",
fn: async (t) => {
await createRoleTests(bot, guild.id, {}, t);
const role = await bot.helpers.createRole(guild.id, { name: "hoti" });
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
},
});
+26
View File
@@ -0,0 +1,26 @@
import { assertExists } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] delete a role with a reason",
fn: async (t) => {
const role = await bot.helpers.createRole(guild.id, { name: "hoti" }, "Blame wolfy");
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
await bot.helpers.deleteRole(guild.id, role.id);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => !bot.cache.guilds.get(guild.id)?.roles.has(role.id));
if (bot.cache.guilds.get(guild.id)?.roles.has(role.id)) {
throw new Error(`The role should have been deleted but it is still in cache.`);
}
},
});
+26
View File
@@ -0,0 +1,26 @@
import { assertExists } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] delete a role without a reason",
fn: async (t) => {
const role = await bot.helpers.createRole(guild.id, { name: "hoti" });
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
await bot.helpers.deleteRole(guild.id, role.id);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => !bot.cache.guilds.get(guild.id)?.roles.has(role.id));
if (bot.cache.guilds.get(guild.id)?.roles.has(role.id)) {
throw new Error(`The role should have been deleted but it is still in cache.`);
}
},
});
+30
View File
@@ -0,0 +1,30 @@
import { assertExists,assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] edit a role",
fn: async () => {
const role = await bot.helpers.createRole(guild.id, {
name: "hoti",
});
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
if (!bot.cache.guilds.get(guild.id)?.roles.has(role.id)) {
throw new Error(`The role seemed to be created but it was not cached.`);
}
await bot.helpers.editRole(guild.id, role.id, {
name: "#rememberAyntee",
});
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.get(role.id)?.name === "#rememberAyntee");
assertEquals(bot.cache.guilds.get(guild.id)?.roles.get(role.id)?.name === "#rememberAyntee", true);
},
});
+11
View File
@@ -0,0 +1,11 @@
import { assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
Deno.test({
name: "[Role] get all roles on a server",
fn: async (t) => {
const roles = await bot.helpers.getRoles(guild.id);
assertEquals(bot.cache.guilds.get(guild.id)?.roles.size, roles.size);
},
});
+38
View File
@@ -0,0 +1,38 @@
import { roleChanges } from "../constants.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test({
name: "[Role] remove a role to a member",
fn: async (t) => {
const role = await bot.helpers.createRole(guild.id, {
name: "hoti",
});
assertExists(role);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
bot.events.guildMemberUpdate = function (bot, member, user) {
roleChanges.set(user.id, member.roles);
};
await bot.helpers.addRole(guild.id, bot.id, role.id, "Blame wolfy");
// Delay the execution to allow event to be processed
await delayUntil(10000, () => roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), true);
await bot.helpers.removeRole(guild.id, bot.id, role.id, "Blame wolfy");
// Delay the execution to allow event to be processed
await delayUntil(10000, () => !roleChanges.get(bot.id)?.includes(role.id));
assertEquals(roleChanges.get(bot.id)?.includes(role.id), false);
},
});
@@ -0,0 +1,31 @@
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
Deno.test({
name: "[scheduled event] create a guild scheduled event with external entity with an end time.",
fn: async (t) => {
const options = {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + (600000 + 1),
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.External,
location: "heaven",
};
const event = await bot.helpers.createScheduledEvent(guild.id, options);
// Assertions
assertExists(event.id);
assertEquals(event.location, options.location);
assertEquals(event.name, options.name);
assertEquals(event.description, options.description);
assertEquals(event.scheduledStartTime, options.scheduledStartTime);
assertEquals(event.scheduledEndTime, options.scheduledEndTime);
assertEquals(event.privacyLevel, options.privacyLevel);
assertEquals(event.entityType, options.entityType);
},
});
@@ -0,0 +1,30 @@
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
Deno.test({
name: "[scheduled event] create a guild scheduled event with external entity",
fn: async (t) => {
const options = {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + 1200000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.External,
location: "heaven",
};
const event = await bot.helpers.createScheduledEvent(guild.id, options);
// Assertions
assertExists(event.id);
assertEquals(event.location, options.location);
assertEquals(event.name, options.name);
assertEquals(event.description, options.description);
assertEquals(event.scheduledStartTime, options.scheduledStartTime);
assertEquals(event.scheduledEndTime, options.scheduledEndTime);
assertEquals(event.privacyLevel, options.privacyLevel);
assertEquals(event.entityType, options.entityType);
},
});
@@ -0,0 +1,40 @@
import { ChannelTypes } from "../../mod.ts";
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[scheduled event] create a guild scheduled event with stage entity with an end time.",
fn: async (t) => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "entity",
type: ChannelTypes.GuildStageVoice,
});
const options = {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + (600000 + 1),
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.StageInstance,
channelId: channel.id,
};
const event = await bot.helpers.createScheduledEvent(CACHED_COMMUNITY_GUILD_ID, options);
await bot.helpers.deleteChannel(channel.id);
// Assertions
assertExists(event.id);
assertEquals(event.channelId, options.channelId);
assertEquals(event.name, options.name);
assertEquals(event.description, options.description);
assertEquals(event.scheduledStartTime, options.scheduledStartTime);
assertEquals(event.scheduledEndTime, options.scheduledEndTime);
assertEquals(event.privacyLevel, options.privacyLevel);
assertEquals(event.entityType, options.entityType);
},
});
@@ -0,0 +1,38 @@
import { ChannelTypes } from "../../mod.ts";
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[scheduled event] create a guild scheduled event with stage entity",
fn: async () => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "entity",
type: ChannelTypes.GuildStageVoice,
});
const options = {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.StageInstance,
channelId: channel.id,
};
const event = await bot.helpers.createScheduledEvent(CACHED_COMMUNITY_GUILD_ID, options);
await bot.helpers.deleteChannel(channel.id);
// Assertions
assertExists(event.id);
assertEquals(event.channelId, options.channelId);
assertEquals(event.name, options.name);
assertEquals(event.description, options.description);
assertEquals(event.scheduledStartTime, options.scheduledStartTime);
assertEquals(event.privacyLevel, options.privacyLevel);
assertEquals(event.entityType, options.entityType);
},
});
@@ -0,0 +1,37 @@
import { ChannelTypes } from "../../mod.ts";
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
Deno.test({
name: "[scheduled event] create a guild scheduled event with voice entity with an end time.",
fn: async (t) => {
const channel = await bot.helpers.createChannel(guild.id, {
name: "entity",
type: ChannelTypes.GuildVoice,
});
const options = {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + (600000 + 1),
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.Voice,
channelId: channel.id,
};
const event = await bot.helpers.createScheduledEvent(guild.id, options);
// Assertions
assertExists(event.id);
assertEquals(event.channelId, options.channelId);
assertEquals(event.name, options.name);
assertEquals(event.description, options.description);
assertEquals(event.scheduledStartTime, options.scheduledStartTime);
assertEquals(event.scheduledEndTime, options.scheduledEndTime);
assertEquals(event.privacyLevel, options.privacyLevel);
assertEquals(event.entityType, options.entityType);
},
});
@@ -0,0 +1,35 @@
import { ChannelTypes } from "../../mod.ts";
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
Deno.test({
name: "[scheduled event] create a guild scheduled event with voice entity",
fn: async () => {
const channel = await bot.helpers.createChannel(guild.id, {
name: "entity",
type: ChannelTypes.GuildVoice,
});
const options = {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.Voice,
channelId: channel.id,
};
const event = await bot.helpers.createScheduledEvent(guild.id, options);
// Assertions
assertExists(event.id);
assertEquals(event.channelId, options.channelId);
assertEquals(event.name, options.name);
assertEquals(event.description, options.description);
assertEquals(event.scheduledStartTime, options.scheduledStartTime);
assertEquals(event.privacyLevel, options.privacyLevel);
assertEquals(event.entityType, options.entityType);
},
});
+18
View File
@@ -0,0 +1,18 @@
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { bot, guild } from "../mod.ts";
Deno.test({
name: "[scheduled event] delete a scheduled event",
fn: async (t) => {
const event = await bot.helpers.createScheduledEvent(guild.id, {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
scheduledEndTime: Date.now() + 1200000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.External,
location: "heaven",
});
await bot.helpers.deleteScheduledEvent(guild.id, event.id);
},
});
+76
View File
@@ -0,0 +1,76 @@
import { ChannelTypes } from "../../mod.ts";
import { ScheduledEventPrivacyLevel, ScheduledEventEntityType } from "../../src/types/guilds/scheduledEvents.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts";
import { assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
name: "[scheduled event] edit a scheduled event",
fn: async (t) => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "entity",
type: ChannelTypes.GuildStageVoice,
});
const event = await bot.helpers.createScheduledEvent(CACHED_COMMUNITY_GUILD_ID, {
name: "lfg",
description: "itoh is an imposter",
scheduledStartTime: Date.now() + 600000,
privacyLevel: ScheduledEventPrivacyLevel.GuildOnly,
entityType: ScheduledEventEntityType.StageInstance,
channelId: channel.id,
});
let edited = await bot.helpers.editScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id, {
name: "lfg2",
});
assertEquals(event.name, "lfg");
assertEquals(edited.name, "lfg2");
assertEquals(edited.description, "itoh is an imposter");
edited = await bot.helpers.editScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id, {
description: "skillz is not an imposter",
});
assertEquals(edited.description, "skillz is not an imposter");
let edited2 = await bot.helpers.editScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id, {
scheduledStartTime: edited.scheduledStartTime - 60000,
});
assertEquals(edited.scheduledStartTime > edited2.scheduledStartTime, true);
let edited3 = await bot.helpers.editScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id, {
scheduledStartTime: edited.scheduledStartTime + 600000,
});
assertEquals(edited2.scheduledStartTime < edited3.scheduledStartTime, true);
const voice = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "xxx",
type: ChannelTypes.GuildVoice,
});
edited2 = await bot.helpers.editScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id, {
entityType: ScheduledEventEntityType.Voice,
channelId: voice.id,
});
assertEquals(edited.entityType, ScheduledEventEntityType.StageInstance);
assertEquals(edited2.entityType, ScheduledEventEntityType.Voice);
edited2 = await bot.helpers.editScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id, {
entityType: ScheduledEventEntityType.External,
// @ts-ignore
channelId: null,
scheduledStartTime: Date.now() + 60000,
scheduledEndTime: Date.now() + 600000,
location: "heaven",
});
assertEquals(edited2.entityType, ScheduledEventEntityType.External);
edited3 = await bot.helpers.editScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id, {
entityType: ScheduledEventEntityType.Voice,
channelId: voice.id,
});
assertEquals(edited2.entityType, ScheduledEventEntityType.External);
assertEquals(edited3.entityType, ScheduledEventEntityType.Voice);
await bot.helpers.deleteChannel(voice.id);
await bot.helpers.deleteChannel(channel.id);
},
});