mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
fix: pass tests
This commit is contained in:
@@ -10,10 +10,8 @@ export async function getChannel(bot: Bot, channelId: bigint) {
|
||||
);
|
||||
|
||||
// IF A CHANNEL DOESN'T EXIST, DISCORD RETURNS `{}`
|
||||
return result.id
|
||||
? bot.transformers.channel(bot, {
|
||||
channel: result,
|
||||
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
|
||||
})
|
||||
: undefined;
|
||||
return bot.transformers.channel(bot, {
|
||||
channel: result,
|
||||
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ export async function getBan(bot: Bot, guildId: bigint, memberId: bigint) {
|
||||
bot.constants.routes.GUILD_BAN(guildId, memberId),
|
||||
);
|
||||
|
||||
if (!result?.user) return;
|
||||
|
||||
return {
|
||||
reason: result.reason,
|
||||
user: bot.transformers.user(bot, result.user),
|
||||
|
||||
@@ -18,9 +18,6 @@ export async function getGuild(
|
||||
bot.constants.routes.GUILD(guildId, options.counts),
|
||||
);
|
||||
|
||||
// Sometimes the guild is not found, so we need to check for it.
|
||||
if (!result.id) return;
|
||||
|
||||
return bot.transformers.guild(bot, {
|
||||
guild: result,
|
||||
shardId: bot.utils.calculateShardId(bot.gateway, guildId),
|
||||
|
||||
@@ -9,7 +9,5 @@ export async function getWebhook(bot: Bot, webhookId: bigint) {
|
||||
bot.constants.routes.WEBHOOK_ID(webhookId),
|
||||
);
|
||||
|
||||
if (!result?.id) return;
|
||||
|
||||
return bot.transformers.webhook(bot, result);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ export async function runMethod<T = any>(
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
errorStack.message = result.statusText as Error["message"];
|
||||
const err = await result.json().catch(() => {});
|
||||
errorStack.message = err.message ?? result.statusText as Error["message"];
|
||||
console.error(`Error: ${errorStack.message}`);
|
||||
throw errorStack;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { assertExists, assertRejects } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
|
||||
|
||||
@@ -17,7 +17,6 @@ Deno.test({
|
||||
await bot.helpers.deleteChannel(channel.id, "with a reason");
|
||||
|
||||
// Check if channel still exists
|
||||
const exists = await bot.helpers.getChannel(channel.id);
|
||||
assertEquals(exists, undefined);
|
||||
await assertRejects(() => bot.helpers.getChannel(channel.id));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { assertExists, assertRejects } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
|
||||
|
||||
@@ -18,7 +18,6 @@ Deno.test({
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
|
||||
// Check if channel still exists
|
||||
const exists = await bot.helpers.getChannel(channel.id);
|
||||
assertEquals(exists, undefined);
|
||||
await assertRejects(() => bot.helpers.getChannel(channel.id));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ButtonStyles, ChannelTypes, delay, MessageComponentTypes } from "../../../mod.ts";
|
||||
import { assertEquals, assertExists, assertNotEquals } from "../../deps.ts";
|
||||
import { assertEquals, assertExists, assertNotEquals, assertRejects } from "../../deps.ts";
|
||||
import { loadBot } from "../../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
|
||||
|
||||
@@ -167,8 +167,7 @@ Deno.test({
|
||||
assertEquals(message.content, "Hello Skillz");
|
||||
|
||||
await bot.helpers.deleteMessage(channel.id, message.id, "Test");
|
||||
const deletedMessage = await bot.helpers.getMessage(channel.id, message.id);
|
||||
assertEquals(deletedMessage, undefined);
|
||||
await assertRejects(() => bot.helpers.getMessage(channel.id, message.id));
|
||||
});
|
||||
|
||||
// Delete the message without a reason
|
||||
@@ -180,8 +179,7 @@ Deno.test({
|
||||
assertEquals(message.content, "Hello Skillz");
|
||||
|
||||
await bot.helpers.deleteMessage(channel.id, message.id);
|
||||
const deletedMessage = await bot.helpers.getMessage(channel.id, message.id);
|
||||
assertEquals(deletedMessage, undefined);
|
||||
await assertRejects(() => bot.helpers.getMessage(channel.id, message.id));
|
||||
});
|
||||
|
||||
// Bulk delete messages with a reason
|
||||
@@ -199,10 +197,8 @@ Deno.test({
|
||||
assertEquals(message2.content, "Hello Skillz 2");
|
||||
|
||||
await bot.helpers.deleteMessages(channel.id, [message1.id, message2.id], "Test");
|
||||
const deletedMessage1 = await bot.helpers.getMessage(channel.id, message1.id);
|
||||
assertEquals(deletedMessage1, undefined);
|
||||
const deletedMessage2 = await bot.helpers.getMessage(channel.id, message2.id);
|
||||
assertEquals(deletedMessage2, undefined);
|
||||
await assertRejects(() => bot.helpers.getMessage(channel.id, message1.id));
|
||||
await assertRejects(() => bot.helpers.getMessage(channel.id, message2.id));
|
||||
});
|
||||
|
||||
// Bulk delete messages without a reason
|
||||
@@ -221,10 +217,8 @@ Deno.test({
|
||||
|
||||
await bot.helpers.deleteMessages(channel.id, [message1.id, message2.id]);
|
||||
await delay(3000);
|
||||
const deletedMessage1 = await bot.helpers.getMessage(channel.id, message1.id);
|
||||
assertEquals(deletedMessage1, undefined);
|
||||
const deletedMessage2 = await bot.helpers.getMessage(channel.id, message2.id);
|
||||
assertEquals(deletedMessage2, undefined);
|
||||
await assertRejects(() => bot.helpers.getMessage(channel.id, message1.id));
|
||||
await assertRejects(() => bot.helpers.getMessage(channel.id, message2.id));
|
||||
});
|
||||
|
||||
// Get a message
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ChannelTypes, ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../mod.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { assertEquals, assertExists, assertRejects } from "../../deps.ts";
|
||||
import { loadBot } from "../../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
|
||||
|
||||
@@ -179,8 +179,7 @@ Deno.test({
|
||||
"[scheduled event] delete the guild scheduled event.",
|
||||
async () => {
|
||||
await bot.helpers.deleteScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id);
|
||||
const fetchedEvent = await bot.helpers.getScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id);
|
||||
assertEquals(fetchedEvent, undefined);
|
||||
await assertRejects(() => bot.helpers.getScheduledEvent(CACHED_COMMUNITY_GUILD_ID, event.id));
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ChannelTypes } from "../../mod.ts";
|
||||
import { assertEquals, assertExists, assertNotEquals } from "../deps.ts";
|
||||
import { assertEquals, assertExists, assertNotEquals, assertRejects } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
|
||||
Deno.test({
|
||||
@@ -88,8 +88,7 @@ Deno.test({
|
||||
|
||||
// Get vanity URL
|
||||
await t.step("[guild] Get vanity URL", async () => {
|
||||
const vanityUrl = await bot.helpers.getVanityUrl(guild.id);
|
||||
assertEquals(vanityUrl.code, undefined);
|
||||
await assertRejects(() => bot.helpers.getVanityUrl(guild.id));
|
||||
});
|
||||
|
||||
// Emoji related tests
|
||||
@@ -128,8 +127,7 @@ Deno.test({
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
|
||||
const exists = await bot.helpers.getEmoji(guild.id, emoji.id);
|
||||
assertEquals(exists.id, undefined);
|
||||
await assertRejects(() => bot.helpers.getEmoji(guild.id, emoji.id!));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -149,8 +147,7 @@ Deno.test({
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id, "with a reason");
|
||||
|
||||
const exists = await bot.helpers.getEmoji(guild.id, emoji.id);
|
||||
assertEquals(exists.id, undefined);
|
||||
await assertRejects(() => bot.helpers.getEmoji(guild.id, emoji.id!));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -265,9 +262,8 @@ Deno.test({
|
||||
// Delete a guild
|
||||
await t.step("[guild] Delete a guild", async () => {
|
||||
await bot.helpers.deleteGuild(guild.id);
|
||||
//
|
||||
const exists = await bot.helpers.getGuild(guild.id);
|
||||
assertEquals(exists, undefined);
|
||||
// Make sure the guild was deleted
|
||||
await assertRejects(() => bot.helpers.getGuild(guild.id));
|
||||
});
|
||||
} catch (error) {
|
||||
// If any errors arise, delete the guild
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { assertEquals, assertExists, assertRejects } from "../../deps.ts";
|
||||
import { loadBot } from "../../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
|
||||
|
||||
@@ -66,7 +66,7 @@ Deno.test({
|
||||
bot.helpers.unbanMember(CACHED_COMMUNITY_GUILD_ID, ianID),
|
||||
]);
|
||||
|
||||
assertEquals(await bot.helpers.getBan(CACHED_COMMUNITY_GUILD_ID, wolfID), undefined);
|
||||
await assertRejects(() => bot.helpers.getBan(CACHED_COMMUNITY_GUILD_ID, wolfID));
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// START FILE FOR REST PROCESS
|
||||
import { dotenv } from "./deps.ts";
|
||||
import { BASE_URL, createRestManager } from "../mod.ts";
|
||||
import { dotenv } from "./deps.ts";
|
||||
|
||||
dotenv({ export: true, path: `${Deno.cwd()}/.env` });
|
||||
|
||||
@@ -88,8 +88,11 @@ async function handleRequest(conn: Deno.Conn) {
|
||||
error,
|
||||
);
|
||||
requestEvent.respondWith(
|
||||
new Response(JSON.stringify(error), {
|
||||
status: error.code ?? 469,
|
||||
new Response(JSON.stringify({
|
||||
message: error.message,
|
||||
|
||||
}), {
|
||||
status: error.code ?? 469,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { assertEquals, assertExists, assertRejects } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
|
||||
|
||||
@@ -16,9 +16,7 @@ Deno.test({
|
||||
await bot.helpers.deleteWebhook(webhook.id);
|
||||
|
||||
// Fetch the webhook to validate it was deleted
|
||||
const deletedWebhook = await bot.helpers.getWebhook(webhook.id);
|
||||
|
||||
assertEquals(deletedWebhook, undefined);
|
||||
await assertRejects(() => bot.helpers.getWebhook(webhook.id));
|
||||
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { assertEquals, assertExists, assertRejects } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
|
||||
|
||||
@@ -17,9 +17,7 @@ Deno.test({
|
||||
await bot.helpers.deleteWebhookWithToken(webhook.id, webhook.token);
|
||||
|
||||
// Fetch the webhook to validate it was deleted
|
||||
const deletedWebhook = await bot.helpers.getWebhook(webhook.id);
|
||||
|
||||
assertEquals(deletedWebhook, undefined);
|
||||
await assertRejects(() => bot.helpers.getWebhook(webhook.id));
|
||||
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user