mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-15 19:08:17 +00:00
fix: remaining tests
This commit is contained in:
+7
-1
@@ -1199,8 +1199,8 @@ export interface BotGatewayHandlerOptions {
|
||||
GUILD_ROLE_DELETE: typeof handlers.handleGuildRoleDelete;
|
||||
GUILD_ROLE_UPDATE: typeof handlers.handleGuildRoleUpdate;
|
||||
GUILD_SCHEDULED_EVENT_CREATE: typeof handlers.handleGuildScheduledEventCreate;
|
||||
GUILD_SCHEDULED_EVENT_UPDATE: typeof handlers.handleGuildScheduledEventUpdate;
|
||||
GUILD_SCHEDULED_EVENT_DELETE: typeof handlers.handleGuildScheduledEventDelete;
|
||||
GUILD_SCHEDULED_EVENT_UPDATE: typeof handlers.handleGuildScheduledEventUpdate;
|
||||
GUILD_SCHEDULED_EVENT_USER_ADD: typeof handlers.handleGuildScheduledEventUserAdd;
|
||||
GUILD_SCHEDULED_EVENT_USER_REMOVE: typeof handlers.handleGuildScheduledEventUserRemove;
|
||||
GUILD_UPDATE: typeof handlers.handleGuildUpdate;
|
||||
@@ -1263,6 +1263,12 @@ export function createBotGatewayHandlers(
|
||||
GUILD_ROLE_DELETE: options.GUILD_ROLE_DELETE ?? handlers.handleGuildRoleDelete,
|
||||
GUILD_ROLE_UPDATE: options.GUILD_ROLE_UPDATE ?? handlers.handleGuildRoleUpdate,
|
||||
GUILD_UPDATE: options.GUILD_UPDATE ?? handlers.handleGuildUpdate,
|
||||
// guild events
|
||||
GUILD_SCHEDULED_EVENT_CREATE: options.GUILD_SCHEDULED_EVENT_CREATE ?? handlers.handleGuildScheduledEventCreate,
|
||||
GUILD_SCHEDULED_EVENT_DELETE: options.GUILD_SCHEDULED_EVENT_DELETE ?? handlers.handleGuildScheduledEventDelete,
|
||||
GUILD_SCHEDULED_EVENT_UPDATE: options.GUILD_SCHEDULED_EVENT_UPDATE ?? handlers.handleGuildScheduledEventUpdate,
|
||||
GUILD_SCHEDULED_EVENT_USER_ADD: options.GUILD_SCHEDULED_EVENT_USER_ADD ?? handlers.handleGuildScheduledEventUserAdd,
|
||||
GUILD_SCHEDULED_EVENT_USER_REMOVE: options.GUILD_SCHEDULED_EVENT_USER_REMOVE ?? handlers.handleGuildScheduledEventUserRemove,
|
||||
// interactions
|
||||
INTERACTION_CREATE: options.INTERACTION_CREATE ?? handlers.handleInteractionCreate,
|
||||
// invites
|
||||
|
||||
+14
-14
@@ -117,20 +117,20 @@ export function createCache(
|
||||
|
||||
// Interaction sweeper in case users don't reply do slash commands
|
||||
// PS: always reply .-. its good practise
|
||||
setInterval(() => {
|
||||
const values = cache.unrepliedInteractions.values();
|
||||
const now = Date.now();
|
||||
for (let val; (val = values.next().value); ) {
|
||||
// Interaction is older than 15 minutes
|
||||
// and a reply has never been send
|
||||
// so remove it from cache
|
||||
// PS: DON'T USE THIS CODE TO CONVERT DC SNOWFLAKES TO UNIX
|
||||
// SINCE U WILL GET AN INVALID RESULT
|
||||
if ((val >> 22n) + 1420071300000n < now) {
|
||||
cache.unrepliedInteractions.delete(val);
|
||||
}
|
||||
}
|
||||
}, 300000);
|
||||
// setInterval(() => {
|
||||
// const values = cache.unrepliedInteractions.values();
|
||||
// const now = Date.now();
|
||||
// for (let val; (val = values.next().value); ) {
|
||||
// // Interaction is older than 15 minutes
|
||||
// // and a reply has never been send
|
||||
// // so remove it from cache
|
||||
// // PS: DON'T USE THIS CODE TO CONVERT DC SNOWFLAKES TO UNIX
|
||||
// // SINCE U WILL GET AN INVALID RESULT
|
||||
// if ((val >> 22n) + 1420071300000n < now) {
|
||||
// cache.unrepliedInteractions.delete(val);
|
||||
// }
|
||||
// }
|
||||
// }, 300000);
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayl
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
|
||||
if (payload.nonce && payload.chunk_index >= payload.chunk_count - 1) bot.cache.fetchAllMembersProcessingRequests.get(payload.nonce)?.(`Member fetching complete. Nonce: ${payload.nonce}`);
|
||||
|
||||
return {
|
||||
guildId,
|
||||
members: payload.members.map((m) =>
|
||||
|
||||
@@ -2,11 +2,12 @@ import { Bot } from "../../../bot.ts";
|
||||
import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts";
|
||||
|
||||
/** Get a guild scheduled event. */
|
||||
export async function getScheduledEvent(bot: Bot, guildId: bigint, eventId: bigint) {
|
||||
export async function getScheduledEvent(bot: Bot, guildId: bigint, eventId: bigint, options?: { withUserCount?: boolean }) {
|
||||
const event = await bot.rest.runMethod<ScheduledEvent>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId)
|
||||
bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId),
|
||||
{ with_user_count: options?.withUserCount || false}
|
||||
);
|
||||
|
||||
return bot.transformers.scheduledEvent(bot, event);
|
||||
|
||||
@@ -9,13 +9,13 @@ export async function getScheduledEventUsers(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
eventId: bigint,
|
||||
options?: { withMember?: false }
|
||||
options?: GetScheduledEventUsers & { withMember?: false }
|
||||
): Promise<Collection<bigint, DiscordenoUser>>;
|
||||
export async function getScheduledEventUsers(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
eventId: bigint,
|
||||
options?: { withMember: true }
|
||||
options?: GetScheduledEventUsers & { withMember: true }
|
||||
): Promise<Collection<bigint, { user: DiscordenoUser; member: DiscordenoMember }>>;
|
||||
export async function getScheduledEventUsers(
|
||||
bot: Bot,
|
||||
@@ -28,7 +28,7 @@ export async function getScheduledEventUsers(
|
||||
// TODO: validate limit
|
||||
// TODO: is the guild member omit user
|
||||
|
||||
const result = await bot.rest.runMethod<(User & { member?: GuildMember })[]>(
|
||||
const result = await bot.rest.runMethod<({ user: User, member?: GuildMember })[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_SCHEDULED_EVENT_USERS(guildId, eventId),
|
||||
@@ -41,7 +41,7 @@ export async function getScheduledEventUsers(
|
||||
if (!options?.withMember) {
|
||||
return new Collection(
|
||||
result.map((res) => {
|
||||
const user = bot.transformers.user(bot, res);
|
||||
const user = bot.transformers.user(bot, res.user);
|
||||
return [user.id, user];
|
||||
})
|
||||
);
|
||||
@@ -49,7 +49,7 @@ export async function getScheduledEventUsers(
|
||||
|
||||
return new Collection(
|
||||
result.map((res) => {
|
||||
const user = bot.transformers.user(bot, res);
|
||||
const user = bot.transformers.user(bot, res.user);
|
||||
const member = bot.transformers.member(bot, res.member!, guildId, user.id);
|
||||
|
||||
return [user.id, { member, user }];
|
||||
|
||||
@@ -45,5 +45,5 @@ export function fetchMembers(
|
||||
nonce,
|
||||
},
|
||||
});
|
||||
}) as Promise<Collection<bigint, DiscordenoMember>>;
|
||||
}) as Promise<void>;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ export function createRequestBody(rest: RestManager, queuedRequest: { request: R
|
||||
headers["Content-Type"] = "application/json";
|
||||
}
|
||||
|
||||
if (!queuedRequest.payload.body) headers["Content-Length"] = "0";
|
||||
return {
|
||||
headers,
|
||||
body: (queuedRequest.payload.body?.file || JSON.stringify(queuedRequest.payload.body)) as FormData | string,
|
||||
|
||||
@@ -118,7 +118,7 @@ export async function processGlobalQueue(rest: RestManager) {
|
||||
|
||||
// If NOT rate limited remove from queue
|
||||
if (response.status !== 429) {
|
||||
// rest.debug(JSON.stringify((await response.json()).errors));
|
||||
if (response.type)
|
||||
console.log(JSON.stringify(await response.json()));
|
||||
|
||||
request.request.reject(new Error(`[${response.status}] ${error}`));
|
||||
|
||||
@@ -16,11 +16,11 @@ export function transformScheduledEvent(
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
channelId: payload.channel_id ? bot.transformers.snowflake(payload.channel_id) : undefined,
|
||||
creatorId: payload.creator_id ? bot.transformers.snowflake(payload.creator_id) : undefined,
|
||||
creatorId: payload.creator_id ? bot.transformers.snowflake(payload.creator_id) : 0n,
|
||||
scheduledStartTime: Date.parse(payload.scheduled_start_time),
|
||||
scheduledEndTime: payload.scheduled_end_time ? Date.parse(payload.scheduled_end_time) : undefined,
|
||||
entityId: payload.entity_id ? bot.transformers.snowflake(payload.entity_id) : undefined,
|
||||
creator: payload.creator ? bot.transformers.user(bot, payload.creator) : undefined,
|
||||
creator: bot.transformers.user(bot, payload.creator!),
|
||||
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
|
||||
@@ -31,6 +31,11 @@ export type GatewayDispatchEventNames =
|
||||
| "GUILD_ROLE_DELETE"
|
||||
| "GUILD_ROLE_UPDATE"
|
||||
| "GUILD_UPDATE"
|
||||
| "GUILD_SCHEDULED_EVENT_CREATE"
|
||||
| "GUILD_SCHEDULED_EVENT_DELETE"
|
||||
| "GUILD_SCHEDULED_EVENT_UPDATE"
|
||||
| "GUILD_SCHEDULED_EVENT_USER_ADD"
|
||||
| "GUILD_SCHEDULED_EVENT_USER_REMOVE"
|
||||
| "INTERACTION_CREATE"
|
||||
| "INVITE_CREATE"
|
||||
| "INVITE_DELETE"
|
||||
|
||||
@@ -77,7 +77,7 @@ export interface ScheduledEventUserAdd {
|
||||
}
|
||||
|
||||
export interface CreateScheduledEvent {
|
||||
/** the channel id of the scheduled event */
|
||||
/** the channel id of the scheduled event. */
|
||||
channelId?: bigint;
|
||||
/** location of the event */
|
||||
location?: string;
|
||||
@@ -96,29 +96,8 @@ export interface CreateScheduledEvent {
|
||||
}
|
||||
|
||||
export interface EditScheduledEvent {
|
||||
/** the channel id of the scheduled event */
|
||||
channelId: bigint;
|
||||
/** location of the event */
|
||||
location: string;
|
||||
/** the name of the scheduled event */
|
||||
name: string;
|
||||
/** the description of the scheduled event */
|
||||
description: string;
|
||||
/** the time the scheduled event will start */
|
||||
scheduledStartTime: number;
|
||||
/** the time the scheduled event will end if it does end. */
|
||||
scheduledEndTime?: number;
|
||||
/** the privacy level of the scheduled event */
|
||||
privacyLevel: ScheduledEventPrivacyLevel;
|
||||
/** the type of hosting entity associated with a scheduled event */
|
||||
entityType: ScheduledEventEntityType;
|
||||
/** the status of the scheduled event */
|
||||
status: ScheduledEventStatus;
|
||||
}
|
||||
|
||||
export interface EditScheduledEvent {
|
||||
/** the channel id of the scheduled event */
|
||||
channelId: bigint;
|
||||
/** the channel id of the scheduled event. null if switching to external event. */
|
||||
channelId: bigint | null;
|
||||
/** location of the event */
|
||||
location: string;
|
||||
/** the name of the scheduled event */
|
||||
@@ -147,4 +126,8 @@ export interface GetScheduledEventUsers {
|
||||
limit?: number;
|
||||
/** Whether to also have member objects provided. Defaults to false. */
|
||||
withMember?: boolean;
|
||||
/** consider only users before given user id */
|
||||
before?: bigint;
|
||||
/** consider only users after given user id */
|
||||
after?: bigint;
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ export {
|
||||
assertNotEquals,
|
||||
assertThrows,
|
||||
} from "https://deno.land/std@0.113.0/testing/asserts.ts";
|
||||
export * from "https://deno.land/x/discordeno_cache_plugin@0.0.7/mod.ts";
|
||||
export * from "https://deno.land/x/discordeno_cache_plugin@0.0.9/mod.ts";
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
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,
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import { ChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function createChannelTests(bot: Bot, guildId: bigint, options: CreateGuildChannel, t: Deno.TestContext) {
|
||||
export async function createChannelTests(bot: Bot, guildId: bigint, options: CreateGuildChannel, autoDelete: boolean, t: Deno.TestContext) {
|
||||
const channel = await bot.helpers.createChannel(guildId, options);
|
||||
|
||||
// Assertions
|
||||
@@ -31,4 +31,8 @@ export async function createChannelTests(bot: Bot, guildId: bigint, options: Cre
|
||||
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
|
||||
);
|
||||
}
|
||||
|
||||
if (autoDelete) {
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Channel } from "../../../src/types/channels/channel.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../../src/types/util.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function deleteChannelTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
|
||||
@@ -13,6 +15,8 @@ export async function deleteChannelTests(bot: Bot, guildId: bigint, options: { r
|
||||
throw new Error("The channel should have been created but it is not in the cache.");
|
||||
}
|
||||
|
||||
const CHANNEL_DELETE = bot.handlers.CHANNEL_DELETE;
|
||||
|
||||
// Delete the channel now without a reason
|
||||
await bot.helpers.deleteChannel(channel.id, options.reason);
|
||||
// wait to give it time for event
|
||||
|
||||
@@ -60,6 +60,13 @@ export async function editScheduledEventTests(bot: Bot, guildId: bigint, t: Deno
|
||||
});
|
||||
assertEquals(edited2.entityType, ScheduledEventEntityType.External);
|
||||
|
||||
edited3 = await bot.helpers.editScheduledEvent(guildId, 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);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
|
||||
export async function fetchSingleMemberTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const fetchedMember = await bot.helpers.fetchMembers(guildId, 0, {
|
||||
await bot.helpers.fetchMembers(guildId, 0, {
|
||||
userIds: [bot.id],
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(fetchedMember);
|
||||
assertExists(bot.cache.members.get(BigInt(`${bot.id}${guildId}`)));
|
||||
}
|
||||
|
||||
+215
-206
@@ -1,4 +1,4 @@
|
||||
// import { UNITTEST_TOKEN } from "../configs.ts";
|
||||
import { UNITTEST_TOKEN } from "../configs.ts";
|
||||
import { memoryBenchmarks } from "../benchmarks/index.ts";
|
||||
import {
|
||||
channelOverwriteHasPermission,
|
||||
@@ -81,18 +81,13 @@ export const CACHED_COMMUNITY_GUILD_ID = 907350958810480671n;
|
||||
Deno.test({
|
||||
name: "[Bot] - Starting Tests",
|
||||
fn: async (t) => {
|
||||
const token = Deno.env.get("DISCORD_TOKEN")!;
|
||||
if (!token) {
|
||||
throw new Error("DISCORD_TOKEN not found");
|
||||
}
|
||||
|
||||
// const botId = BigInt(atob(UNITTEST_TOKEN.split(".")[0]));
|
||||
const botId = BigInt(atob(token.split(".")[0]));
|
||||
const botId = BigInt(atob(UNITTEST_TOKEN.split(".")[0]));
|
||||
// const botId = BigInt(atob(token.split(".")[0]));
|
||||
|
||||
let startedAt = 0;
|
||||
const bot = createBot({
|
||||
// token: UNITTEST_TOKEN || Deno.env.get("DISCORD_TOKEN"),
|
||||
token: Deno.env.get("DISCORD_TOKEN")!,
|
||||
token: UNITTEST_TOKEN || Deno.env.get("DISCORD_TOKEN"),
|
||||
// token: Deno.env.get("DISCORD_TOKEN")!,
|
||||
botId,
|
||||
events: createEventHandlers({
|
||||
ready: () => {
|
||||
@@ -149,7 +144,8 @@ Deno.test({
|
||||
throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`);
|
||||
}
|
||||
|
||||
// GUILD SCHEDULED EVENTS TESTS
|
||||
let timer = Date.now();
|
||||
console.log('GUILD SCHEDULED EVENTS TESTS',)
|
||||
await t.step("Guild Scheduled Event related tests", async (t) => {
|
||||
await Promise.all([
|
||||
t.step({
|
||||
@@ -283,7 +279,8 @@ Deno.test({
|
||||
]);
|
||||
});
|
||||
|
||||
// GUILD TESTS GROUPED
|
||||
console.log('GUILD TESTS GROUPED', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await t.step("Guild related tests", async (t) => {
|
||||
await Promise.all([
|
||||
t.step({
|
||||
@@ -391,7 +388,8 @@ Deno.test({
|
||||
]);
|
||||
});
|
||||
|
||||
// CHANNEL TESTS GROUPED
|
||||
console.log('CHANNEL TESTS GROUPED', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await t.step("Channel related tests", async (t) => {
|
||||
const channel = await bot.helpers.createChannel(guild.id, { name: "Discordeno-test" });
|
||||
|
||||
@@ -399,11 +397,13 @@ Deno.test({
|
||||
assertExists(channel);
|
||||
assertEquals(channel.type, ChannelTypes.GuildText);
|
||||
|
||||
// ALL MESSAGE RELATED TESTS THAT DEPEND ON AN EXISTING CHANNEL
|
||||
console.log('ALL MESSAGE RELATED TESTS THAT DEPEND ON AN EXISTING CHANNEL', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await t.step("Message related tests", async (t) => {
|
||||
const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz");
|
||||
|
||||
// CONDUCT ALL TESTS RELATED TO A MESSAGE HERE
|
||||
console.log('CONDUCT ALL TESTS RELATED TO A MESSAGE HERE', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await Promise.all([
|
||||
t.step({
|
||||
name: "[message] send message with text",
|
||||
@@ -475,80 +475,81 @@ Deno.test({
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
// t.step({
|
||||
// name: "[message] add a reaction",
|
||||
// fn: async (t) => {
|
||||
// await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] add a custom reaction",
|
||||
// fn: async (t) => {
|
||||
// await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] add multiple reactions",
|
||||
// fn: async (t) => {
|
||||
// await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] add multiple custom reactions",
|
||||
// fn: async (t) => {
|
||||
// await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] add multiple reactions in order",
|
||||
// fn: async (t) => {
|
||||
// await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] add multiple custom reactions in order",
|
||||
// fn: async (t) => {
|
||||
// await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] remove a reaction.",
|
||||
// fn: async (t) => {
|
||||
// await removeReactionTest(bot, channel.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] remove all reactions.",
|
||||
// fn: async (t) => {
|
||||
// await removeAllReactionTests(bot, channel.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] remove emoji reactions.",
|
||||
// fn: async (t) => {
|
||||
// await removeReactionEmojiTest(bot, channel.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[message] pin a message",
|
||||
// fn: async (t) => {
|
||||
// await pinMessageTests(bot, channel.id, message.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
t.step({
|
||||
name: "[message] add a reaction",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] add a custom reaction",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] add multiple reactions",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] add multiple custom reactions",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] add multiple reactions in order",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] add multiple custom reactions in order",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] remove a reaction.",
|
||||
fn: async (t) => {
|
||||
await removeReactionTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] remove all reactions.",
|
||||
fn: async (t) => {
|
||||
await removeAllReactionTests(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] remove emoji reactions.",
|
||||
fn: async (t) => {
|
||||
await removeReactionEmojiTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[message] pin a message",
|
||||
fn: async (t) => {
|
||||
await pinMessageTests(bot, channel.id, message.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
// ALL CHANNEL RELATED TESTS CAN GO HERE
|
||||
console.log('ALL CHANNEL RELATED TESTS CAN GO HERE', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await Promise.all([
|
||||
t.step({
|
||||
name: "[channel] send message with text",
|
||||
@@ -560,7 +561,7 @@ Deno.test({
|
||||
t.step({
|
||||
name: "[channel] create a new text channel",
|
||||
async fn() {
|
||||
await createChannelTests(bot, guild.id, { name: "Discordeno-test" }, t);
|
||||
await createChannelTests(bot, guild.id, { name: "Discordeno-test" }, false, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
@@ -574,26 +575,25 @@ Deno.test({
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildCategory,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[channel] create a new news channel",
|
||||
async fn() {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
CACHED_COMMUNITY_GUILD_ID,
|
||||
{ name: "Discordeno-test", type: ChannelTypes.GuildNews },
|
||||
true,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
// t.step({
|
||||
// name: "[channel] create a new news channel",
|
||||
// async fn() {
|
||||
// await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: ChannelTypes.GUILD_NEWS}, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
|
||||
// t.step({
|
||||
// name: "[channel] create a new store channel",
|
||||
// async fn() {
|
||||
// await createChannelTests(bot, guild.id,{ name: "Discordeno-test", type: ChannelTypes.GUILD_STORE}, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
t.step({
|
||||
name: "[channel] create a new voice channel",
|
||||
async fn() {
|
||||
@@ -604,6 +604,7 @@ Deno.test({
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
@@ -620,6 +621,7 @@ Deno.test({
|
||||
type: ChannelTypes.GuildVoice,
|
||||
bitrate: 32000,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
@@ -636,6 +638,7 @@ Deno.test({
|
||||
type: ChannelTypes.GuildVoice,
|
||||
userLimit: 32,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
@@ -651,6 +654,7 @@ Deno.test({
|
||||
name: "Discordeno-test",
|
||||
rateLimitPerUser: 2423,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
@@ -659,7 +663,7 @@ Deno.test({
|
||||
t.step({
|
||||
name: "[channel] create a new text channel with NSFW",
|
||||
async fn() {
|
||||
await createChannelTests(bot, guild.id, { name: "Discordeno-test", nsfw: true }, t);
|
||||
await createChannelTests(bot, guild.id, { name: "Discordeno-test", nsfw: true }, false, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
@@ -680,32 +684,33 @@ Deno.test({
|
||||
},
|
||||
],
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
// t.step({
|
||||
// name: "[channel] delete a channel with a reason",
|
||||
// async fn() {
|
||||
// await deleteChannelTests(
|
||||
// bot,
|
||||
// guild.id,
|
||||
// {
|
||||
// reason: "with a reason",
|
||||
// },
|
||||
// t
|
||||
// );
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[channel] delete a channel without a reason",
|
||||
// async fn() {
|
||||
// await deleteChannelTests(bot, guild.id, {}, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
t.step({
|
||||
name: "[channel] delete a channel with a reason",
|
||||
async fn() {
|
||||
await deleteChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
reason: "with a reason",
|
||||
},
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[channel] delete a channel without a reason",
|
||||
async fn() {
|
||||
await deleteChannelTests(bot, guild.id, {}, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[channel] filter all category channels",
|
||||
async fn() {
|
||||
@@ -750,7 +755,8 @@ Deno.test({
|
||||
}),
|
||||
]);
|
||||
|
||||
// ALL TEST RELATED TO INVITES
|
||||
console.log('ALL TEST RELATED TO INVITES', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await t.step("Invites related tests", async (t) => {
|
||||
await Promise.all([
|
||||
t.step({
|
||||
@@ -792,76 +798,75 @@ Deno.test({
|
||||
});
|
||||
});
|
||||
|
||||
// MEMBER TESTS GROUPED
|
||||
// await t.step("Members related tests", async (t) => {
|
||||
// // THESE BAN TESTS SHOULD BE DONE ONE BY ONE
|
||||
// await t.step({
|
||||
// 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,
|
||||
// });
|
||||
console.log('MEMBER TESTS GROUPED', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await t.step("Members related tests", async (t) => {
|
||||
// THESE BAN TESTS SHOULD BE DONE ONE BY ONE
|
||||
await t.step({
|
||||
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,
|
||||
});
|
||||
await t.step({
|
||||
name: "[member] get a single user's ban",
|
||||
fn: async (t) => {
|
||||
assertExists(await bot.helpers.getBan(guild.id, 270273690074087427n));
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
await t.step({
|
||||
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,
|
||||
});
|
||||
await t.step({
|
||||
name: "[member] get bans on a server",
|
||||
fn: async (t) => {
|
||||
await getBansTest(bot, t, guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
await Promise.all([
|
||||
t.step({
|
||||
name: "[member] fetch a single member by id",
|
||||
fn: async (t) => {
|
||||
await fetchSingleMemberTest(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
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,
|
||||
}),
|
||||
t.step({
|
||||
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,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
// await t.step({
|
||||
// name: "[member] get a single user's ban",
|
||||
// fn: async (t) => {
|
||||
// assertExists(await bot.helpers.getBan(guild.id, 270273690074087427n));
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// });
|
||||
|
||||
// await t.step({
|
||||
// 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,
|
||||
// });
|
||||
// await t.step({
|
||||
// name: "[member] get bans on a server",
|
||||
// fn: async (t) => {
|
||||
// await getBansTest(bot, t, guild.id);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// });
|
||||
|
||||
// await Promise.all([
|
||||
// t.step({
|
||||
// name: "[member] fetch a single member by id",
|
||||
// fn: async (t) => {
|
||||
// await fetchSingleMemberTest(bot, guild.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// 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,
|
||||
// }),
|
||||
// t.step({
|
||||
// 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,
|
||||
// }),
|
||||
// ]);
|
||||
// });
|
||||
|
||||
// EMOJIS TESTS GROUPED
|
||||
console.log('EMOJIS TESTS GROUPED', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await t.step("Emojis related tests", async (t) => {
|
||||
await Promise.all([
|
||||
t.step({
|
||||
@@ -909,7 +914,8 @@ Deno.test({
|
||||
]);
|
||||
});
|
||||
|
||||
// ROLE RELATED TESTS
|
||||
console.log('ROLE RELATED TESTS', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await t.step({
|
||||
name: "[Role] Role related tests",
|
||||
fn: async (t) => {
|
||||
@@ -950,13 +956,13 @@ Deno.test({
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
// t.step({
|
||||
// name: "[Role] edit a role",
|
||||
// fn: async (t) => {
|
||||
// await editRoleTests(bot, guild.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
t.step({
|
||||
name: "[Role] edit a role",
|
||||
fn: async (t) => {
|
||||
await editRoleTests(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[Role] add a role to a member",
|
||||
fn: async (t) => {
|
||||
@@ -975,7 +981,8 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
// SOME MISC TESTS
|
||||
console.log('SOME MISC TESTS', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
await Promise.all([
|
||||
t.step({
|
||||
name: "[User] get a user and transform",
|
||||
@@ -1005,15 +1012,17 @@ Deno.test({
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
// CONDUCT MEMORY BENCHMARK TESTS
|
||||
]);
|
||||
|
||||
console.log('CONDUCT MEMORY BENCHMARK TESTS', (Date.now() - timer) / 1000, 'seconds');
|
||||
timer = Date.now();
|
||||
|
||||
await t.step({
|
||||
name: "[Memory] Benchmark memory tests",
|
||||
fn: async (t) => {
|
||||
await memoryBenchmarks(bot, true);
|
||||
},
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
await bot.helpers.deleteGuild(guild.id);
|
||||
await stopBot(bot);
|
||||
|
||||
Reference in New Issue
Block a user