From 001afae921e0e7e693ec2034fb1cbb4cacbbbf0a Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Thu, 23 Dec 2021 19:39:13 +0000 Subject: [PATCH] fix: test bugs --- src/helpers/invites/createInvite.ts | 23 ++++++++++++++--------- src/transformers/invite.ts | 2 +- src/types/webhooks/executeWebhook.ts | 2 +- tests/deps.ts | 4 ++-- tests/emoji/getEmoji.ts | 2 +- tests/guilds/urls.ts | 12 ++++-------- tests/helpers/messages/deleteMessage.ts | 2 +- tests/helpers/messages/deleteMessages.ts | 4 ++-- tests/helpers/messages/editMessage.ts | 4 ++-- tests/helpers/messages/getMessage.ts | 2 +- tests/helpers/messages/getMessages.ts | 6 +++--- tests/helpers/messages/reactions.ts | 8 ++++---- tests/helpers/messages/sendMessage.ts | 4 ++-- tests/members/getDmChannel.ts | 2 +- tests/messages/reactions.ts | 8 ++++---- tests/misc/getUser.ts | 4 ++-- tests/mod.ts | 8 ++------ 17 files changed, 47 insertions(+), 50 deletions(-) diff --git a/src/helpers/invites/createInvite.ts b/src/helpers/invites/createInvite.ts index 7ba836210..1a59b7bc5 100644 --- a/src/helpers/invites/createInvite.ts +++ b/src/helpers/invites/createInvite.ts @@ -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( + const result = await bot.rest.runMethod( 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, }; } diff --git a/src/transformers/invite.ts b/src/transformers/invite.ts index 36f1e0d2a..acd01029d 100644 --- a/src/transformers/invite.ts +++ b/src/transformers/invite.ts @@ -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"; diff --git a/src/types/webhooks/executeWebhook.ts b/src/types/webhooks/executeWebhook.ts index a52f0ad80..f2424a2e8 100644 --- a/src/types/webhooks/executeWebhook.ts +++ b/src/types/webhooks/executeWebhook.ts @@ -30,7 +30,7 @@ export interface ExecuteWebhook { users?: bigint[]; }; /** the components to include with the message */ - components: MessageComponents; + components?: MessageComponents; } export type DiscordExecuteWebhook = SnakeCasedPropertiesDeep>; diff --git a/tests/deps.ts b/tests/deps.ts index 8e9b98d7a..2619f20e9 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -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"; diff --git a/tests/emoji/getEmoji.ts b/tests/emoji/getEmoji.ts index cf3c1fd5e..856fb05ae 100644 --- a/tests/emoji/getEmoji.ts +++ b/tests/emoji/getEmoji.ts @@ -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); diff --git a/tests/guilds/urls.ts b/tests/guilds/urls.ts index b37d3aa6c..512284b10 100644 --- a/tests/guilds/urls.ts +++ b/tests/guilds/urls.ts @@ -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" ); }, diff --git a/tests/helpers/messages/deleteMessage.ts b/tests/helpers/messages/deleteMessage.ts index a6a718e55..64475dfed 100644 --- a/tests/helpers/messages/deleteMessage.ts +++ b/tests/helpers/messages/deleteMessage.ts @@ -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); diff --git a/tests/helpers/messages/deleteMessages.ts b/tests/helpers/messages/deleteMessages.ts index a285c6b5f..59df6474e 100644 --- a/tests/helpers/messages/deleteMessages.ts +++ b/tests/helpers/messages/deleteMessages.ts @@ -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); diff --git a/tests/helpers/messages/editMessage.ts b/tests/helpers/messages/editMessage.ts index 91100fb8e..2e75f482f 100644 --- a/tests/helpers/messages/editMessage.ts +++ b/tests/helpers/messages/editMessage.ts @@ -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!"); diff --git a/tests/helpers/messages/getMessage.ts b/tests/helpers/messages/getMessage.ts index 578cc3982..edc36def4 100644 --- a/tests/helpers/messages/getMessage.ts +++ b/tests/helpers/messages/getMessage.ts @@ -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); diff --git a/tests/helpers/messages/getMessages.ts b/tests/helpers/messages/getMessages.ts index c719eb271..64ef3831a 100644 --- a/tests/helpers/messages/getMessages.ts +++ b/tests/helpers/messages/getMessages.ts @@ -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); diff --git a/tests/helpers/messages/reactions.ts b/tests/helpers/messages/reactions.ts index c891f96cd..553c767c2 100644 --- a/tests/helpers/messages/reactions.ts +++ b/tests/helpers/messages/reactions.ts @@ -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); diff --git a/tests/helpers/messages/sendMessage.ts b/tests/helpers/messages/sendMessage.ts index 05792e0c4..7aa9fbad0 100644 --- a/tests/helpers/messages/sendMessage.ts +++ b/tests/helpers/messages/sendMessage.ts @@ -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) { diff --git a/tests/members/getDmChannel.ts b/tests/members/getDmChannel.ts index fd6e4b232..dddde457c 100644 --- a/tests/members/getDmChannel.ts +++ b/tests/members/getDmChannel.ts @@ -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"}); }); diff --git a/tests/messages/reactions.ts b/tests/messages/reactions.ts index 7bd762fdd..c2ff49983 100644 --- a/tests/messages/reactions.ts +++ b/tests/messages/reactions.ts @@ -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); diff --git a/tests/misc/getUser.ts b/tests/misc/getUser.ts index d21030347..9599f6b46 100644 --- a/tests/misc/getUser.ts +++ b/tests/misc/getUser.ts @@ -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); }, }); diff --git a/tests/mod.ts b/tests/mod.ts index c22c7c893..9a4a6a505 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -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";