Merge remote-tracking branch 'upstream/fp-attempt-9001' into fp-attempt-9001

# Conflicts:
#	tests/mod.ts
This commit is contained in:
Quentin Nicolini
2021-10-30 19:41:27 +02:00
5 changed files with 44 additions and 72 deletions
+7 -6
View File
@@ -2,6 +2,8 @@ import { Bot } from "../../../src/bot.ts";
import { assertEquals, assertExists } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
const reactionCounters = new Map<bigint, number>();
export async function addReactionTest(
bot: Bot,
guildId: bigint,
@@ -59,18 +61,17 @@ export async function addReactionTest(
}
}
let reactions = 0;
reactionCounters.set(message.id, 0);
bot.events.reactionAdd = function (bot, payload) {
if (payload.messageId !== message.id) return;
reactions++;
const current = reactionCounters.get(payload.messageId) || 0;
reactionCounters.set(payload.messageId, current + 1);
};
if (options.single) await bot.helpers.addReaction(message.channelId, message.id, emojiId);
else await bot.helpers.addReactions(message.channelId, message.id, emojiIds, options.ordered);
await delayUntil(10000, () => reactions === (options.single ? 1 : emojiIds.length));
await delayUntil(10000, () => reactionCounters.get(message.id) === (options.single ? 1 : emojiIds.length));
assertEquals(reactions, options.single ? 1 : emojiIds.length);
assertEquals(reactionCounters.get(message.id), options.single ? 1 : emojiIds.length);
}
-38
View File
@@ -4,7 +4,6 @@ import { assertEquals, assertExists } from "./deps.ts";
import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts";
import { getMessagesTest } from "./helpers/messages/getMessages.ts";
import { deleteMessagesWithoutReasonTest, deleteMessagesWithReasonTest } from "./helpers/messages/deleteMessages.ts";
import { editMessageTest } from "./helpers/messages/editMessage.ts";
import { delayUntil } from "./utils.ts";
import {
sendMessageWithComponents,
@@ -93,142 +92,105 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
t.step({
name: "[message] send message with text",
fn: async (t) => {
console.log("start", 1);
await sendMessageWithTextTest(bot, channel.id, t);
console.log("pass", 1);
},
...sanitizeMode,
}),
t.step({
name: "[message] send message with embeds",
fn: async (t) => {
console.log("start", 2);
await sendMessageWithEmbedsTest(bot, channel.id, t);
console.log("pass", 2);
},
...sanitizeMode,
}),
// t.step({
// name: "[message] send message with components",
// fn: async (t) => {
// console.log('start', 2.5)
// await sendMessageWithComponents(bot, channel.id, t);
// console.log('pass', 2.5)
// },
// ...sanitizeMode,
// }),
t.step({
name: "[message] delete message without a reason",
fn: async (t) => {
console.log("start", 3);
await deleteMessageWithoutReasonTest(bot, channel.id, t);
console.log("pass", 3);
},
...sanitizeMode,
}),
t.step({
name: "[message] delete message with a reason",
fn: async (t) => {
console.log("start", 4);
await deleteMessageWithReasonTest(bot, channel.id, t);
console.log("pass", 4);
},
...sanitizeMode,
}),
t.step({
name: "[message] delete messages without a reason",
fn: async (t) => {
console.log("start", 5);
await deleteMessagesWithoutReasonTest(bot, channel.id, t);
console.log("pass", 5);
},
...sanitizeMode,
}),
t.step({
name: "[message] delete messages with a reason",
fn: async (t) => {
console.log("start", 6);
await deleteMessagesWithReasonTest(bot, channel.id, t);
console.log("pass", 6);
},
...sanitizeMode,
}),
t.step({
name: "[message] fetch a message",
fn: async (t) => {
console.log("start", 6.1);
await getMessageTest(bot, channel.id, t);
console.log("pass", 6.1);
},
...sanitizeMode,
}),
t.step({
name: "[message] fetch messages",
fn: async (t) => {
console.log("start", 6.2);
await getMessagesTest(bot, channel.id, t);
console.log("pass", 6.2);
},
...sanitizeMode,
}),
t.step({
name: "[message] add a reaction",
fn: async (t) => {
console.log("start", 7);
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t);
console.log("pass", 7);
},
...sanitizeMode,
}),
t.step({
name: "[message] add a custom reaction",
fn: async (t) => {
console.log("start", 8);
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t);
console.log("pass", 8);
},
...sanitizeMode,
}),
t.step({
name: "[message] add multiple reactions",
fn: async (t) => {
console.log("start", 9);
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t);
console.log("pass", 9);
},
...sanitizeMode,
}),
t.step({
name: "[message] add multiple custom reactions",
fn: async (t) => {
console.log("start", 10);
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t);
console.log("pass", 10);
},
...sanitizeMode,
}),
t.step({
name: "[message] add multiple reactions in order",
fn: async (t) => {
console.log("start", 11);
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t);
console.log("pass", 11);
},
...sanitizeMode,
}),
t.step({
name: "[message] add multiple custom reactions in order",
fn: async (t) => {
console.log("start", 12);
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t);
console.log("pass", 12);
},
...sanitizeMode,
}),
t.step({
name: "[message] edit message",
fn: async (t) => {
await editMessageTest(bot, channel.id, t);
},
...sanitizeMode,
}),