mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 09:50:07 +00:00
fix invite and ban tests
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
import { GetInvite } from "../../types/invites/get_invite.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns an invite for the given code or throws an error if the invite doesn't exists. */
|
||||
export async function getInvite(bot: Bot, inviteCode: string, options?: GetInvite) {
|
||||
return await bot.rest.runMethod<InviteMetadata>(bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.INVITE(inviteCode),
|
||||
{
|
||||
with_counts: options?.withCounts,
|
||||
with_expiration: options?.withExpiration,
|
||||
}
|
||||
);
|
||||
return await bot.rest.runMethod<InviteMetadata>(bot.rest, "get", bot.constants.endpoints.INVITE(inviteCode), {
|
||||
with_counts: options?.withCounts || false,
|
||||
with_expiration: options?.withExpiration || false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,8 +87,9 @@ 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.type._errors));
|
||||
|
||||
// rest.debug(JSON.stringify((await response.json()).errors));
|
||||
console.log(JSON.stringify((await response.json())));
|
||||
|
||||
request.request.reject(new Error(`[${response.status}] ${error}`));
|
||||
} else {
|
||||
if (request.payload.retryCount++ >= rest.maxRetryCount) {
|
||||
|
||||
@@ -6,17 +6,17 @@ export async function getChannelInvitesTest(bot: Bot, channelId: bigint, t: Deno
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: false,
|
||||
unique: true,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(invite);
|
||||
|
||||
const secondInvite = await bot.helpers.createInvite(channelId, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: false,
|
||||
maxAge: 0,
|
||||
maxUses: 2,
|
||||
temporary: true,
|
||||
unique: true,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
|
||||
@@ -1,24 +1,35 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildBan } from "../../../src/types/mod.ts";
|
||||
import { assertEquals } from "../../deps.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) {
|
||||
await bot.helpers.ban(guildId, 456226577798135808n);
|
||||
bot.events.guildBanAdd = function (bot, user, guildId) {
|
||||
banCounters.set(user.id, true);
|
||||
};
|
||||
|
||||
await bot.helpers.ban(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) {
|
||||
await bot.helpers.getBans(guildId);
|
||||
}
|
||||
|
||||
export async function banTestWReason(
|
||||
bot: Bot,
|
||||
t: Deno.TestContext,
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
options?: CreateGuildBan
|
||||
) {
|
||||
await bot.helpers.ban(guildId, 456226577798135808n, { reason: "Blame Wolf" });
|
||||
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) {
|
||||
await bot.helpers.unban(guildId, 456226577798135808n);
|
||||
bot.events.guildBanRemove = function (bot, user, guildId) {
|
||||
banCounters.set(user.id, false);
|
||||
};
|
||||
|
||||
await bot.helpers.unban(guildId, id);
|
||||
|
||||
await delayUntil(10000, () => !banCounters.get(id));
|
||||
|
||||
assertEquals(banCounters.get(id), false);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function pinMessageTests(bot: Bot, channelId: bigint, messageId: bigint, t: Deno.TestContext) {
|
||||
let pinned = false;
|
||||
@@ -10,9 +11,13 @@ export async function pinMessageTests(bot: Bot, channelId: bigint, messageId: bi
|
||||
|
||||
await bot.helpers.pinMessage(channelId, messageId);
|
||||
|
||||
await delayUntil(10000, () => pinned);
|
||||
|
||||
assertEquals(true, pinned);
|
||||
|
||||
await bot.helpers.unpinMessage(channelId, messageId);
|
||||
|
||||
await delayUntil(10000, () => !pinned);
|
||||
|
||||
assertEquals(false, pinned);
|
||||
}
|
||||
|
||||
146
tests/mod.ts
146
tests/mod.ts
@@ -39,7 +39,7 @@ import { deleteEmojiWithoutReasonTest, deleteEmojiWithReasonTest } from "./helpe
|
||||
import { editEmojiTest } from "./helpers/emojis/edit_emoji.ts";
|
||||
import { getEmojiTest } from "./helpers/emojis/get_emoji.ts";
|
||||
import { getEmojisTest } from "./helpers/emojis/get_emojis.ts";
|
||||
import { getBansTest, unbanTest, banTest, banTestWReason } from "./helpers/members/ban.ts";
|
||||
import { getBansTest, unbanTest, banTest } from "./helpers/members/ban.ts";
|
||||
|
||||
Deno.test("[Bot] - Starting Tests", async (t) => {
|
||||
// CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS
|
||||
@@ -63,7 +63,7 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
|
||||
},
|
||||
// debug: console.log,
|
||||
}),
|
||||
intents: ["Guilds", "GuildEmojis", "GuildMessages", "GuildMessageReactions"],
|
||||
intents: ["Guilds", "GuildEmojis", "GuildMessages", "GuildMessageReactions", "GuildBans"],
|
||||
cache: {
|
||||
isAsync: false,
|
||||
},
|
||||
@@ -462,47 +462,81 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
|
||||
// ALL TEST RELATED TO INVITES
|
||||
await t.step("Invites related tests", async (t) => {
|
||||
await Promise.all([
|
||||
// t.step({
|
||||
// name: "[invite] create an invite",
|
||||
// async fn() {
|
||||
// await createInviteTest(bot, channel.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[invite] delete an invite",
|
||||
// async fn() {
|
||||
// await deleteInviteTest(bot, channel.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[invite] get channels invites",
|
||||
// async fn() {
|
||||
// await getChannelInvitesTest(bot, channel.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[invite] get invite",
|
||||
// async fn() {
|
||||
// await getInviteTest(bot, channel.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[invite] get invites",
|
||||
// async fn() {
|
||||
// await getInvitesTest(bot, channel.id, guild.id, t);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
t.step({
|
||||
name: "[invite] create an invite",
|
||||
async fn() {
|
||||
await createInviteTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[invite] delete an invite",
|
||||
async fn() {
|
||||
await deleteInviteTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[invite] get channels invites",
|
||||
async fn() {
|
||||
await getChannelInvitesTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[invite] get invite",
|
||||
async fn() {
|
||||
await getInviteTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
t.step({
|
||||
name: "[invite] get invites",
|
||||
async fn() {
|
||||
await getInvitesTest(bot, channel.id, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
// MEMBER TESTS GROUPED
|
||||
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",
|
||||
@@ -523,34 +557,16 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
|
||||
},
|
||||
...sanitizeMode,
|
||||
}),
|
||||
// t.step({
|
||||
// name: "[member] getBans from guild",
|
||||
// fn: async (t) => {
|
||||
// await getBansTest(bot, t, guild.id);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[member] unban member from guild",
|
||||
// fn: async (t) => {
|
||||
// await unbanTest(bot, t, guild.id, 456226577798135808n);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[member] ban member from guild without reason",
|
||||
// fn: async (t) => {
|
||||
// await banTest(bot, t, guild.id, 456226577798135808n);
|
||||
// },
|
||||
// ...sanitizeMode,
|
||||
// }),
|
||||
// t.step({
|
||||
// name: "[member] ban member from guild without reason",
|
||||
// fn: async (t) => {
|
||||
// await banTestWReason(bot, t, guild.id, 456226577798135808n, { reason: "Blame Wolf" });
|
||||
// },
|
||||
// ...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,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user