fix: add threads unit tests

This commit is contained in:
Skillz4Killz
2022-05-11 13:14:09 +00:00
committed by GitHub
parent f40ff4631e
commit 06ae1101d8
5 changed files with 119 additions and 3 deletions
@@ -0,0 +1,22 @@
import { assertExists } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Delete a thread", async (t) => {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {
reason: "idk",
rateLimitPerUser: 5,
name: "tread carefully",
autoArchiveDuration: 60,
});
const threadMessage = await bot.helpers.sendMessage(thread.id, { content: "message in a bottle" });
assertExists(threadMessage.id);
await bot.helpers.deleteChannel(thread.id);
await bot.helpers.deleteChannel(channel.id);
});
@@ -0,0 +1,33 @@
import { assertExists, assertNotEquals } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Edit and archive a thread", async (t) => {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {
reason: "idk",
rateLimitPerUser: 5,
name: "tread carefully",
autoArchiveDuration: 60,
});
const threadMessage = await bot.helpers.sendMessage(thread.id, { content: "message in a bottle" });
assertExists(threadMessage.id);
const edited = await bot.helpers.editChannel(thread.id, {
archived: true,
name: "new name",
autoArchiveDuration: 1440,
locked: !thread.locked,
rateLimitPerUser: (thread.rateLimitPerUser || 0) + 1,
});
assertNotEquals(thread.archived, edited.archived);
assertNotEquals(thread.name, edited.name);
assertNotEquals(thread.rateLimitPerUser, edited.rateLimitPerUser);
assertNotEquals(thread.autoArchiveDuration, edited.autoArchiveDuration);
assertNotEquals(thread.locked, edited.locked);
await bot.helpers.deleteChannel(channel.id);
});
@@ -0,0 +1,29 @@
import { assertEquals, assertExists, assertNotEquals } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Get active threads", async (t) => {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {
reason: "idk",
rateLimitPerUser: 5,
name: "tread carefully",
autoArchiveDuration: 60,
});
const threadMessage = await bot.helpers.sendMessage(thread.id, { content: "message in a bottle" });
assertExists(threadMessage.id);
const edited = await bot.helpers.editChannel(thread.id, {
archived: true,
});
assertNotEquals(thread.archived, edited.archived);
const activeThreads = await bot.helpers.getActiveThreads(CACHED_COMMUNITY_GUILD_ID);
assertEquals(Boolean(activeThreads.threads.size), true);
assertEquals(Boolean(activeThreads.members.size), true);
await bot.helpers.deleteChannel(channel.id);
});
@@ -0,0 +1,33 @@
import { assertEquals, assertExists, assertNotEquals } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Get archived threads", async (t) => {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {
reason: "idk",
rateLimitPerUser: 5,
name: "tread carefully",
autoArchiveDuration: 60,
});
const archived = await bot.helpers.getArchivedThreads(channel.id);
assertEquals(archived.threads.size, 0);
assertEquals(archived.members.size, 0);
const threadMessage = await bot.helpers.sendMessage(thread.id, { content: "message in a bottle" });
assertExists(threadMessage.id);
const edited = await bot.helpers.editChannel(thread.id, {
archived: true,
});
assertNotEquals(thread.archived, edited.archived);
const archivedNow = await bot.helpers.getArchivedThreads(channel.id);
assertEquals(Boolean(archivedNow.threads.size), true);
assertEquals(Boolean(archivedNow.members.size), true);
await bot.helpers.deleteChannel(channel.id);
});
+2 -3
View File
@@ -13,8 +13,7 @@ Deno.test("[thread] Start a thread", async (t) => {
autoArchiveDuration: 60,
});
assertExists(thread);
assertExists(thread.id);
await bot.helpers.deleteChannel(channel.id)
await bot.helpers.deleteChannel(channel.id);
});