fix: test bugs

This commit is contained in:
Skillz4Killz
2021-12-23 19:39:13 +00:00
committed by GitHub
parent 8214b64557
commit 001afae921
17 changed files with 47 additions and 50 deletions
+14 -9
View File
@@ -1,12 +1,10 @@
import type { CreateChannelInvite } from "../../types/invites/createChannelInvite.ts";
import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts";
import { Errors } from "../../types/discordeno/errors.ts";
import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
import { Invite } from "../../types/invites/invite.ts";
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
export async function createInvite(bot: Bot, channelId: bigint, options: CreateChannelInvite = {}) {
const result = await bot.rest.runMethod<InviteMetadata>(
const result = await bot.rest.runMethod<Invite>(
bot.rest,
"post",
bot.constants.endpoints.CHANNEL_INVITES(channelId),
@@ -22,10 +20,17 @@ export async function createInvite(bot: Bot, channelId: bigint, options: CreateC
);
return {
uses: result.uses,
maxUses: result.max_uses,
maxAge: result.max_age,
temporary: result.temporary,
createdAt: result.created_at,
code: result.code,
guildId: result.guild?.id ? bot.transformers.snowflake(result.guild.id) : undefined,
channelId: result.channel?.id ? bot.transformers.snowflake(result.channel.id) : undefined,
inviter: result.inviter ? bot.transformers.user(bot, result.inviter) : undefined,
targetType: result.target_type,
targetUser: result.target_user ? bot.transformers.user(bot, result.target_user) : undefined,
targetApplicationId: result.target_application?.id
? bot.transformers.snowflake(result.target_application.id)
: undefined,
approximatePresenceCount: result.approximate_presence_count,
approximateMemberCount: result.approximate_member_count,
expiresAt: result.expires_at ? Date.parse(result.expires_at) : undefined,
};
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { Bot } from "../bot.ts";
import { InviteCreate, TargetTypes, User, Application } from "../types/mod.ts";
import { InviteCreate, TargetTypes, Invite } from "../types/mod.ts";
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
import { DiscordenoApplication } from "./application.ts";
import { DiscordenoUser } from "./member.ts";
+1 -1
View File
@@ -30,7 +30,7 @@ export interface ExecuteWebhook {
users?: bigint[];
};
/** the components to include with the message */
components: MessageComponents;
components?: MessageComponents;
}
export type DiscordExecuteWebhook = SnakeCasedPropertiesDeep<Omit<ExecuteWebhook, "wait">>;
+2 -2
View File
@@ -6,5 +6,5 @@ export {
assertThrows,
assertThrowsAsync
} from "https://deno.land/std@0.115.1/testing/asserts.ts";
export * from "https://deno.land/x/discordeno_cache_plugin@0.0.13/mod.ts";
export * from "https://deno.land/x/discordeno_permissions_plugin@0.0.7/mod.ts";
export * from "https://deno.land/x/discordeno_cache_plugin@0.0.19/mod.ts";
export * from "https://deno.land/x/discordeno_permissions_plugin@0.0.13/mod.ts";
+1 -1
View File
@@ -23,7 +23,7 @@ Deno.test({
bot.guilds.get(guild.id)?.emojis?.delete(emoji.id);
const getEmoji = await bot.helpers.getEmoji(guild.id, emoji.id, true);
const getEmoji = await bot.helpers.getEmoji(guild.id, emoji.id);
// Assertions
assertExists(getEmoji);
+4 -8
View File
@@ -4,11 +4,9 @@ import { bot, guild } from "../mod.ts";
Deno.test({
name: "[guild] format a guild's icon url",
fn: () => {
assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined);
assertEquals(bot.helpers.guildIconURL(guild.id, guild.icon), undefined);
assertEquals(
bot.helpers.guildIconURL(785384884197392384n, {
icon: 3837424427068676005442449262648382018748n,
}),
bot.helpers.guildIconURL(785384884197392384n, 3837424427068676005442449262648382018748n),
"https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
);
},
@@ -30,11 +28,9 @@ Deno.test({
Deno.test({
name: "[guild] format a guild's splash url",
fn: () => {
assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined);
assertEquals(bot.helpers.guildSplashURL(guild.id, guild.splash), undefined);
assertEquals(
bot.helpers.guildSplashURL(785384884197392384n, {
splash: 3837424427068676005442449262648382018748n,
}),
bot.helpers.guildSplashURL(785384884197392384n, 3837424427068676005442449262648382018748n),
"https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
);
},
+1 -1
View File
@@ -3,7 +3,7 @@ import { bot } from "../../mod.ts";
import { delayUntil } from "../../utils.ts";
async function ifItFailsBlameWolf(channelId: bigint, reason?: string) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
+2 -2
View File
@@ -3,8 +3,8 @@ import { bot } from "../../mod.ts";
import { delayUntil } from "../../utils.ts";
async function ifItFailsBlameWolf(channelId: bigint, reason?: string) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const secondMessage = await bot.helpers.sendMessage(channelId, "Hello World 2!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
const secondMessage = await bot.helpers.sendMessage(channelId, { content: "Hello World 2!" });
// Assertions
assertExists(message);
+2 -2
View File
@@ -3,7 +3,7 @@ import { bot } from "../../mod.ts";
import { delayUntil } from "../../utils.ts";
export async function editMessageTest(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!"});
// Assertions
assertExists(message);
@@ -15,7 +15,7 @@ export async function editMessageTest(channelId: bigint) {
}
// Edit the message
await bot.helpers.editMessage(channelId, message.id, "Goodbye World!");
await bot.helpers.editMessage(channelId, message.id, {content: "Goodbye World!"});
// Wait to give it time for MESSAGE_UPDATE event
// await delayUntil(10000, async () => bot.messages.get(message.id)?.content === "Goodbye World!");
+1 -1
View File
@@ -4,7 +4,7 @@ import { bot } from "../../mod.ts";
import { delayUntil } from "../../utils.ts";
export async function getMessageTest(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
+3 -3
View File
@@ -3,9 +3,9 @@ import { bot } from "../../mod.ts";
import { delayUntil } from "../../utils.ts";
export async function getMessagesTest(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const secondMessage = await bot.helpers.sendMessage(channelId, "Hello World 2!");
const thirdMessage = await bot.helpers.sendMessage(channelId, "Hello World 3!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
const secondMessage = await bot.helpers.sendMessage(channelId, {content: "Hello World 2!"});
const thirdMessage = await bot.helpers.sendMessage(channelId, {content: "Hello World 3!"});
// Assertions
assertExists(message);
+4 -4
View File
@@ -10,7 +10,7 @@ export async function addReactionTest(
channelId: bigint,
options: { custom: boolean; single: boolean; ordered: boolean }
) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
@@ -76,7 +76,7 @@ export async function addReactionTest(
}
export async function removeAllReactionTests(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
@@ -117,7 +117,7 @@ export async function removeAllReactionTests(channelId: bigint) {
}
export async function removeReactionTest(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
@@ -159,7 +159,7 @@ export async function removeReactionTest(channelId: bigint) {
}
export async function removeReactionEmojiTest(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
+2 -2
View File
@@ -5,7 +5,7 @@ import { MessageComponentTypes } from "../../../src/types/messages/components/me
import { ButtonStyles } from "../../../src/types/messages/components/buttonStyles.ts";
import { bot } from "../../mod.ts";
async function ifItFailsBlameWolf(channelId: bigint, content: string | CreateMessage) {
async function ifItFailsBlameWolf(channelId: bigint, content: CreateMessage) {
const message = await bot.helpers.sendMessage(channelId, content);
// Assertions
assertExists(message);
@@ -18,7 +18,7 @@ async function ifItFailsBlameWolf(channelId: bigint, content: string | CreateMes
}
export async function sendMessageWithTextTest(channelId: bigint) {
await ifItFailsBlameWolf(channelId, "Hello World!");
await ifItFailsBlameWolf(channelId, { content: "Hello World!" });
}
export async function sendMessageWithComponents(channelId: bigint) {
+1 -1
View File
@@ -3,5 +3,5 @@ import { bot } from "../mod.ts";
Deno.test("[member] get dm channel and send a message", async () => {
// Itoh Alt ID
const channel = await bot.helpers.getDmChannel(750661528360845322n);
await bot.helpers.sendMessage(channel.id, "https://i.imgur.com/doG55NR.png");
await bot.helpers.sendMessage(channel.id, {content: "https://i.imgur.com/doG55NR.png"});
});
+4 -4
View File
@@ -15,7 +15,7 @@ export async function addReactionTest(
channelId: bigint,
options: { custom: boolean; single: boolean; ordered: boolean },
) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
@@ -81,7 +81,7 @@ export async function addReactionTest(
}
export async function removeAllReactionTests(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
@@ -122,7 +122,7 @@ export async function removeAllReactionTests(channelId: bigint) {
}
export async function removeReactionTest(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
@@ -164,7 +164,7 @@ export async function removeReactionTest(channelId: bigint) {
}
export async function removeReactionEmojiTest(channelId: bigint) {
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
const message = await bot.helpers.sendMessage(channelId, { content: "Hello World!" });
// Assertions
assertExists(message);
+2 -2
View File
@@ -1,4 +1,4 @@
import { assertExists } from "../deps.ts";
import { assertExists, assertEquals } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test({
@@ -7,6 +7,6 @@ Deno.test({
const user = await bot.helpers.getUser(bot.id);
assertExists(user);
assertExists(bot.transformers.user(bot, user));
assertEquals(user.id, bot.id);
},
});
+2 -6
View File
@@ -1,5 +1,5 @@
import { UNITTEST_TOKEN } from "../configs.ts";
import { createBot, createEventHandlers, ChannelTypes, OverwriteTypes, startBot } from "../mod.ts";
import { createBot, createEventHandlers, ChannelTypes, startBot } from "../mod.ts";
import { assertEquals, assertExists, enableCachePlugin } from "./deps.ts";
import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts";
import { getMessagesTest } from "./helpers/messages/getMessages.ts";
@@ -14,12 +14,8 @@ import {
// CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST
import "./local.ts";
import { getMessageTest } from "./helpers/messages/getMessage.ts";
import { addReactionTest } from "./helpers/messages/reactions.ts";
import { editMessageTest } from "./helpers/messages/editMessage.ts";
import { pinMessageTests } from "./helpers/messages/pin.ts";
import { removeAllReactionTests, removeReactionEmojiTest, removeReactionTest } from "./helpers/messages/reactions.ts";
import { createChannelTests } from "./helpers/channels/createChannel.ts";
import { deleteChannelTests } from "./helpers/channels/deleteChannel.ts";
import { createGuildTests } from "./helpers/guilds/createGuild.ts";
import { deleteGuildTests } from "./helpers/guilds/deleteGuild.ts";
import { editGuildTests } from "./helpers/guilds/editGuild.ts";
@@ -103,7 +99,7 @@ export const channel = await bot.helpers.createChannel(guild.id, { name: "Discor
assertExists(channel);
assertEquals(channel.type, ChannelTypes.GuildText);
export const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz");
export const message = await bot.helpers.sendMessage(channel.id, { content: "Hello Skillz" });
import "./benchmark.ts";