Test: clean up CI and test (#2555)

* style: format Deno.test\("(.+)", async \(\) => \{\n([\S\s]*?)^\}\);

* style: format Deno.test\("(.+)", \(\) => \{\n([\S\s]*?)^\}\);

* style: format Deno.test\("(.+)", async \(t\) => \{\n([\S\s]*?)^\}\);

* style: format async function

* chore: turn all to async

* chore: format add t

* style: function format

* chore: add integration and unit test difference

* ci: combine test

* ci: remove if

* ci: add parallel flag

* ci: add UNIT_TEST_GUILD_ID

* ci: static deno version

* ci: add concurrency to Integration test

* ci: bump actions/checkout to v3
This commit is contained in:
Jonathan Ho
2022-10-26 10:41:26 -05:00
committed by GitHub
parent c07f2454ef
commit 1c7859fea9
56 changed files with 860 additions and 675 deletions
-19
View File
@@ -1,19 +0,0 @@
name: Check Formatting
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
deno: ["v1.x"]
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@main
with:
deno-version: ${{ matrix.deno }}
- name: Check Formatting
run: deno fmt --check
+50 -24
View File
@@ -3,40 +3,70 @@ name: Test
on:
pull_request:
push:
paths:
- "handlers/**"
- "helpers/**"
- "plugins/**"
- "packages/**"
- "rest/**"
- "tests/**"
- "transformers/**"
- "template/**"
- "types/**"
- "util/**"
- "gateway/**"
jobs:
test:
format-test:
name: Format Test
runs-on: ubuntu-latest
strategy:
matrix:
deno: ["v1.x"]
steps:
- uses: actions/checkout@v2
- run: git submodule update --init --recursive
- uses: actions/checkout@v3
- uses: denoland/setup-deno@main
with:
deno-version: ${{ matrix.deno }}
deno-version: v1.x
- name: Check Formatting
run: deno fmt --check
type-test:
name: Type Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@main
with:
deno-version: v1.x
- name: Check dependencies
run: deno check mod.ts
- name: Check plugins
run: deno check plugins/mod.ts
- name: Check Templates
run: deno check template/beginner/mod.ts template/minimal/mod.ts
- name: Run test script for maintainers
integration-test:
name: Integration Test
runs-on: ubuntu-latest
concurrency: integration-test
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@main
with:
deno-version: v1.x
- name: Run integration
# if: ${{ github.actor == 'Skillz4Killz' || github.actor == 'itohatweb' }}
run: deno test --coverage=coverage -A tests/
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
UNIT_TEST_GUILD_ID: ${{ secrets.UNIT_TEST_GUILD_ID }}
TEST_ENV: INTEGRATION
PROXY_REST_SECRET: ${{ secrets.PROXY_REST_SECRET }}
PROXY_REST_URL: ${{ secrets.PROXY_REST_URL }}
- name: Create coverage report
if: github.ref == 'refs/heads/main'
run: deno coverage --exclude=tests ./coverage --lcov > coverage.lcov
- name: Collect and upload the coverage report
if: github.ref == 'refs/heads/main'
uses: codecov/codecov-action@v1.0.10
with:
file: ./coverage.lcov
unit-test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@main
with:
deno-version: v1.x
- name: Run integration
run: deno test --coverage=coverage --parallel -A tests/
env:
TEST_ENV: UNIT
- name: Create coverage report
if: github.ref == 'refs/heads/main'
run: deno coverage --exclude=tests ./coverage --lcov > coverage.lcov
@@ -45,7 +75,3 @@ jobs:
uses: codecov/codecov-action@v1.0.10
with:
file: ./coverage.lcov
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
PROXY_REST_SECRET: ${{ secrets.PROXY_REST_SECRET }}
PROXY_REST_URL: ${{ secrets.PROXY_REST_URL }}
+1
View File
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new category channel",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+1
View File
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new news channel",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+1
View File
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test" });
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel with NSFW",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel with permission overwrites",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel with a rate limit per user",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+1
View File
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new voice channel",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new voice channel with a bitrate",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new voice channel with a user limit",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+1
View File
@@ -4,6 +4,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] delete a channel with a reason",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
@@ -4,6 +4,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] delete a channel without a reason",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
// Create a channel to delete
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] edit a channel",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "editChannel" });
+1
View File
@@ -4,6 +4,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] Get a channel",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+2 -1
View File
@@ -4,7 +4,8 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] Get all channels",
async fn() {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const [first, second] = await Promise.all([
bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "first" }),
+1
View File
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test({
name: "[invite] create an invite",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+2 -1
View File
@@ -1,10 +1,11 @@
import { ButtonStyles, ChannelTypes, delay, MessageComponentTypes } from "../../../mod.ts";
import { assertEquals, assertExists, assertNotEquals, assertRejects } from "../../deps.ts";
import { assertEquals, assertExists, assertRejects } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test({
name: "[messages] Run message related unit tests",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+2 -1
View File
@@ -4,7 +4,8 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test({
name: "[message] reaction related unit tests",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "reactions" });
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test({
name: "[channel] Delete a channel overwrite",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+1
View File
@@ -5,6 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[stage] Create a stage instance",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const stage = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
+18 -14
View File
@@ -2,21 +2,25 @@ 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,
});
Deno.test({
name: "[thread] Delete a thread",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(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 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(thread.id);
await bot.helpers.deleteChannel(channel.id);
await bot.helpers.deleteChannel(channel.id);
},
});
+29 -25
View File
@@ -2,32 +2,36 @@ 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,
});
Deno.test({
name: "[thread] Edit and archive a thread",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(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 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);
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);
await bot.helpers.deleteChannel(channel.id);
},
});
+20 -16
View File
@@ -1,23 +1,27 @@
import { assertEquals, assertExists, assertNotEquals } from "../../deps.ts";
import { assertEquals, assertExists } 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,
});
Deno.test({
name: "[thread] Get active threads",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(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 threadMessage = await bot.helpers.sendMessage(thread.id, { content: "message in a bottle" });
assertExists(threadMessage.id);
const activeThreads = await bot.helpers.getActiveThreads(CACHED_COMMUNITY_GUILD_ID);
assertEquals(Boolean(activeThreads.threads.size), true);
const activeThreads = await bot.helpers.getActiveThreads(CACHED_COMMUNITY_GUILD_ID);
assertEquals(Boolean(activeThreads.threads.size), true);
await bot.helpers.deleteChannel(channel.id);
await bot.helpers.deleteChannel(channel.id);
},
});
@@ -2,32 +2,36 @@ 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,
});
Deno.test({
name: "[thread] Get archived threads",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(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.getPublicArchivedThreads(channel.id);
assertEquals(archived.threads.size, 0);
assertEquals(archived.members.size, 0);
const archived = await bot.helpers.getPublicArchivedThreads(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 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 edited = await bot.helpers.editChannel(thread.id, {
archived: true,
});
assertNotEquals(thread.archived, edited.archived);
const archivedNow = await bot.helpers.getPublicArchivedThreads(channel.id);
assertEquals(Boolean(archivedNow.threads.size), true);
assertEquals(Boolean(archivedNow.members.size), true);
const archivedNow = await bot.helpers.getPublicArchivedThreads(channel.id);
assertEquals(Boolean(archivedNow.threads.size), true);
assertEquals(Boolean(archivedNow.members.size), true);
await bot.helpers.deleteChannel(channel.id);
await bot.helpers.deleteChannel(channel.id);
},
});
@@ -2,27 +2,31 @@ import { assertExists } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] join and leave 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,
});
Deno.test({
name: "[thread] join and leave a thread",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(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 threadMessage = await bot.helpers.sendMessage(thread.id, { content: "message in a bottle" });
assertExists(threadMessage.id);
await t.step("[thread] leave a thread", async () => {
await bot.helpers.leaveThread(thread.id);
});
await t.step("[thread] leave a thread", async () => {
await bot.helpers.leaveThread(thread.id);
});
await t.step("[thread] join a thread", async () => {
await bot.helpers.joinThread(thread.id);
});
await t.step("[thread] join a thread", async () => {
await bot.helpers.joinThread(thread.id);
});
await bot.helpers.deleteChannel(channel.id);
await bot.helpers.deleteChannel(channel.id);
},
});
+17 -13
View File
@@ -1,19 +1,23 @@
import { assertEquals, assertExists, assertNotEquals } from "../../deps.ts";
import { assertExists } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Start 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,
});
Deno.test({
name: "[thread] Start a thread",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(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,
});
assertExists(thread.id);
assertExists(thread.id);
await bot.helpers.deleteChannel(channel.id);
await bot.helpers.deleteChannel(channel.id);
},
});
+2 -1
View File
@@ -3,7 +3,8 @@ import { assertEquals } from "./deps.ts";
Deno.test({
name: "[utils] delay 2000 ms",
async fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const before = Date.now();
await delay(2000);
const after = Date.now();
+210 -203
View File
@@ -3,186 +3,46 @@ import { assertEquals, assertExists } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[automod] Run automod tests", async (t) => {
const bot = loadBot();
Deno.test({
name: "[automod] Run automod tests",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
await t.step("[automod] Create a MessageSend rule for Keyword with BlockMessage action.", async () => {
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.BlockMessage,
await t.step("[automod] Create a MessageSend rule for Keyword with BlockMessage action.", async () => {
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
],
});
assertExists(rule.id);
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.BlockMessage);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
});
await t.step("[automod] Create a MessageSend rule for Keyword with SendAlertMessage action.", async () => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
});
assertExists(channel.id);
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.SendAlertMessage,
metadata: {
channelId: channel.id,
actions: [
{
type: AutoModerationActionType.BlockMessage,
},
},
],
],
});
assertExists(rule.id);
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.BlockMessage);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
});
assertExists(rule.id);
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.SendAlertMessage);
assertEquals(fetchedRule.actions[0].metadata?.channelId, channel.id);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
await bot.helpers.deleteChannel(channel.id);
});
await t.step("[automod] Create a MessageSend rule for Keyword with Timeout action.", async () => {
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.Timeout,
metadata: {
durationSeconds: 10,
},
},
],
});
assertExists(rule.id);
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.Timeout);
assertEquals(fetchedRule.actions[0].metadata?.durationSeconds, 10);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
});
await t.step("[automod] Create a MessageSend rule for Keyword with BlockMessage & Timeout action.", async () => {
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.BlockMessage,
},
{
type: AutoModerationActionType.Timeout,
metadata: {
durationSeconds: 10,
},
},
],
});
assertExists(rule.id);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
});
await t.step("[automod] Create a MessageSend rule for Keyword with SendAlertMessage & Timeout action.", async () => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
});
assertExists(channel.id);
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.SendAlertMessage,
metadata: {
channelId: channel.id,
},
},
{
type: AutoModerationActionType.Timeout,
metadata: {
durationSeconds: 10,
},
},
],
});
assertExists(rule.id);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
await bot.helpers.deleteChannel(channel.id);
});
await t.step(
"[automod] Create a MessageSend rule for Keyword with BlockMessage & SendAlertMessage & Timeout action.",
async (t) => {
await t.step("[automod] Create a MessageSend rule for Keyword with SendAlertMessage action.", async () => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
});
@@ -196,15 +56,84 @@ Deno.test("[automod] Run automod tests", async (t) => {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.BlockMessage,
},
{
type: AutoModerationActionType.SendAlertMessage,
metadata: {
channelId: channel.id,
},
},
],
});
assertExists(rule.id);
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.SendAlertMessage);
assertEquals(fetchedRule.actions[0].metadata?.channelId, channel.id);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
await bot.helpers.deleteChannel(channel.id);
});
await t.step("[automod] Create a MessageSend rule for Keyword with Timeout action.", async () => {
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.Timeout,
metadata: {
durationSeconds: 10,
},
},
],
});
assertExists(rule.id);
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.Timeout);
assertEquals(fetchedRule.actions[0].metadata?.durationSeconds, 10);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
});
await t.step("[automod] Create a MessageSend rule for Keyword with BlockMessage & Timeout action.", async () => {
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.BlockMessage,
},
{
type: AutoModerationActionType.Timeout,
metadata: {
@@ -216,30 +145,108 @@ Deno.test("[automod] Run automod tests", async (t) => {
assertExists(rule.id);
// Get the rule again to make sure it was created correctly
await t.step("[automod] Get a automod rule", async () => {
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertExists(fetchedRule.actions[1].metadata);
assertExists(fetchedRule.actions[2].metadata);
assertEquals(fetchedRule.actions[1].metadata.channelId, channel.id);
assertEquals(fetchedRule.actions[2].metadata.durationSeconds, 10);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.BlockMessage);
assertEquals(fetchedRule.actions[1].type, AutoModerationActionType.SendAlertMessage);
assertEquals(fetchedRule.actions[2].type, AutoModerationActionType.Timeout);
});
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
await bot.helpers.deleteChannel(channel.id);
},
);
});
await t.step(
"[automod] Create a MessageSend rule for Keyword with SendAlertMessage & Timeout action.",
async () => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
});
assertExists(channel.id);
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.SendAlertMessage,
metadata: {
channelId: channel.id,
},
},
{
type: AutoModerationActionType.Timeout,
metadata: {
durationSeconds: 10,
},
},
],
});
assertExists(rule.id);
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
await bot.helpers.deleteChannel(channel.id);
},
);
await t.step(
"[automod] Create a MessageSend rule for Keyword with BlockMessage & SendAlertMessage & Timeout action.",
async (t) => {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
});
assertExists(channel.id);
const rule = await bot.helpers.createAutomodRule(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
eventType: AutoModerationEventTypes.MessageSend,
triggerType: AutoModerationTriggerTypes.Keyword,
triggerMetadata: {
keywordFilter: ["iblamewolf"],
},
actions: [
{
type: AutoModerationActionType.BlockMessage,
},
{
type: AutoModerationActionType.SendAlertMessage,
metadata: {
channelId: channel.id,
},
},
{
type: AutoModerationActionType.Timeout,
metadata: {
durationSeconds: 10,
},
},
],
});
assertExists(rule.id);
// Get the rule again to make sure it was created correctly
await t.step("[automod] Get a automod rule", async () => {
const fetchedRule = await bot.helpers.getAutomodRule(
CACHED_COMMUNITY_GUILD_ID,
rule.id,
);
assertExists(fetchedRule.id);
assertEquals(fetchedRule.name, rule.name);
assertEquals(fetchedRule.eventType, AutoModerationEventTypes.MessageSend);
assertEquals(fetchedRule.triggerType, AutoModerationTriggerTypes.Keyword);
assertEquals(fetchedRule.triggerMetadata?.keywordFilter?.[0], "iblamewolf");
assertExists(fetchedRule.actions);
assertExists(fetchedRule.actions[0]);
assertExists(fetchedRule.actions[1].metadata);
assertExists(fetchedRule.actions[2].metadata);
assertEquals(fetchedRule.actions[1].metadata.channelId, channel.id);
assertEquals(fetchedRule.actions[2].metadata.durationSeconds, 10);
assertEquals(fetchedRule.actions[0].type, AutoModerationActionType.BlockMessage);
assertEquals(fetchedRule.actions[1].type, AutoModerationActionType.SendAlertMessage);
assertEquals(fetchedRule.actions[2].type, AutoModerationActionType.Timeout);
});
await bot.helpers.deleteAutomodRule(CACHED_COMMUNITY_GUILD_ID, rule.id);
await bot.helpers.deleteChannel(channel.id);
},
);
},
});
+12 -8
View File
@@ -2,12 +2,16 @@ import { MfaLevels } from "../../mod.ts";
import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
Deno.test("[guild] edit guild mfa level", async () => {
const bot = loadBot();
const guild = await bot.helpers.createGuild({ name: "test" });
await bot.helpers.editGuildMfaLevel(guild.id, MfaLevels.Elevated, "test");
assertEquals((await bot.helpers.getGuild(guild.id)).mfaLevel, MfaLevels.Elevated);
await bot.helpers.editGuildMfaLevel(guild.id, MfaLevels.None, "revert test");
assertEquals((await bot.helpers.getGuild(guild.id)).mfaLevel, MfaLevels.None);
await bot.helpers.deleteGuild(guild.id);
Deno.test({
name: "[guild] edit guild mfa level",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const guild = await bot.helpers.createGuild({ name: "test" });
await bot.helpers.editGuildMfaLevel(guild.id, MfaLevels.Elevated, "test");
assertEquals((await bot.helpers.getGuild(guild.id)).mfaLevel, MfaLevels.Elevated);
await bot.helpers.editGuildMfaLevel(guild.id, MfaLevels.None, "revert test");
assertEquals((await bot.helpers.getGuild(guild.id)).mfaLevel, MfaLevels.None);
await bot.helpers.deleteGuild(guild.id);
},
});
+3 -2
View File
@@ -5,7 +5,8 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test({
name: "[events] unit tests for events",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
// create a guild scheduled event with external entity with an end time
@@ -191,7 +192,7 @@ Deno.test({
await t.step(
{
name: "[scheduled event] edit a scheduled event",
fn: async (t) => {
async fn(t) {
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "entity",
type: ChannelTypes.GuildStageVoice,
+8 -4
View File
@@ -2,8 +2,12 @@ import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[voice] Get voice regions", async () => {
const bot = loadBot();
const regions = await bot.helpers.getVoiceRegions(CACHED_COMMUNITY_GUILD_ID);
assertEquals(regions.size > 1, true);
Deno.test({
name: "[voice] Get voice regions",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const regions = await bot.helpers.getVoiceRegions(CACHED_COMMUNITY_GUILD_ID);
assertEquals(regions.size > 1, true);
},
});
+8 -7
View File
@@ -4,6 +4,7 @@ import { loadBot } from "../mod.ts";
Deno.test({
name: "[guild] Create a guild",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
@@ -96,7 +97,7 @@ Deno.test({
// Create an emoji
await t.step({
name: "[emoji] create an emoji",
fn: async (t) => {
async fn(t) {
const bot = loadBot();
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
@@ -114,7 +115,7 @@ Deno.test({
// delete an emoji without a reason
await t.step({
name: "[emoji] delete an emoji without a reason",
fn: async (t) => {
async fn(t) {
const bot = loadBot();
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
@@ -134,7 +135,7 @@ Deno.test({
// delete an emoji with a reason
await t.step({
name: "[emoji] delete an emoji with a reason",
fn: async (t) => {
async fn(t) {
const bot = loadBot();
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
@@ -154,7 +155,7 @@ Deno.test({
// edit an emoji name
await t.step({
name: "[emoji] Edit an emoji name",
fn: async (t) => {
async fn(t) {
const bot = loadBot();
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
@@ -181,7 +182,7 @@ Deno.test({
// edit an emoji roles
await t.step({
name: "[emoji] Edit an emoji's roles",
fn: async (t) => {
async fn(t) {
const bot = loadBot();
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
@@ -212,7 +213,7 @@ Deno.test({
// get an emoji
await t.step({
name: "[emoji] get an emoji",
fn: async (t) => {
async fn(t) {
const bot = loadBot();
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
@@ -233,7 +234,7 @@ Deno.test({
await t.step({
name: "[emoji] get all guild emojis",
fn: async (t) => {
async fn(t) {
const bot = loadBot();
const emoji = await bot.helpers.createEmoji(guild.id, {
name: "blamewolf",
+13 -7
View File
@@ -12,19 +12,21 @@ const ltsID = 379643682984296448n;
// THESE BAN TESTS SHOULD BE DONE ONE BY ONE
Deno.test({
name: "[member] ban member test group",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
// ban user from guild without reason
await t.step({
name: "[member] ban user from guild without reason",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
await bot.helpers.banMember(CACHED_COMMUNITY_GUILD_ID, wolfID);
// get a single user's ban
await t.step({
name: "[member] get a single user's ban",
fn: async () => {
async fn(t) {
assertExists(await bot.helpers.getBan(CACHED_COMMUNITY_GUILD_ID, wolfID));
},
});
@@ -34,7 +36,8 @@ Deno.test({
// ban member from guild with a reason
await t.step({
name: "[member] ban member from guild with a reason",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
await bot.helpers.banMember(CACHED_COMMUNITY_GUILD_ID, ianID, { reason: "Blame Wolf" });
assertExists(await bot.helpers.getBan(CACHED_COMMUNITY_GUILD_ID, ianID));
},
@@ -49,7 +52,8 @@ Deno.test({
// get bans on a server
await t.step({
name: "[member] get bans on a server",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const bans = await bot.helpers.getBans(CACHED_COMMUNITY_GUILD_ID);
assertEquals(bans.size > 1, true);
},
@@ -58,7 +62,8 @@ Deno.test({
// fetch a single member by id
await t.step({
name: "[member] fetch a single member by id",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const member = await bot.helpers.getMember(CACHED_COMMUNITY_GUILD_ID, bot.id);
assertExists(member?.id);
@@ -68,7 +73,8 @@ Deno.test({
// unban member from guild
await t.step({
name: "[member] unban member from guild",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
await Promise.all([
bot.helpers.unbanMember(CACHED_COMMUNITY_GUILD_ID, wolfID),
bot.helpers.unbanMember(CACHED_COMMUNITY_GUILD_ID, ianID),
+11 -7
View File
@@ -1,12 +1,16 @@
import { assertExists } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
Deno.test("[member] get dm channel and send a message", async () => {
const bot = loadBot();
// Itoh Alt ID
const channel = await bot.helpers.getDmChannel(750661528360845322n);
assertExists(channel?.id);
Deno.test({
name: "[member] get dm channel and send a message",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
// Itoh Alt ID
const channel = await bot.helpers.getDmChannel(750661528360845322n);
assertExists(channel?.id);
const message = await bot.helpers.sendMessage(channel.id, { content: "https://i.imgur.com/doG55NR.png" });
assertExists(message?.content);
const message = await bot.helpers.sendMessage(channel.id, { content: "https://i.imgur.com/doG55NR.png" });
assertExists(message?.content);
},
});
+12 -8
View File
@@ -2,14 +2,18 @@ import { assertEquals } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[misc] edit a bot's nickname", async function () {
const bot = loadBot();
Deno.test({
name: "[misc] edit a bot's nickname",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const nick = "lts20050703";
const member = await bot.helpers.editBotMember(CACHED_COMMUNITY_GUILD_ID, { nick });
assertEquals(member.nick, nick);
const nick = "lts20050703";
const member = await bot.helpers.editBotMember(CACHED_COMMUNITY_GUILD_ID, { nick });
assertEquals(member.nick, nick);
// Change nickname back
const member2 = await bot.helpers.editBotMember(CACHED_COMMUNITY_GUILD_ID, { nick: null });
assertEquals(member2.nick, undefined);
// Change nickname back
const member2 = await bot.helpers.editBotMember(CACHED_COMMUNITY_GUILD_ID, { nick: null });
assertEquals(member2.nick, undefined);
},
});
+17 -9
View File
@@ -2,16 +2,24 @@ import { assertEquals, assertExists } from "../../deps.ts";
import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[member] fetches the bot and compares the bot's id with the fetched member's id", async () => {
const bot = loadBot();
const member = await bot.helpers.getMember(CACHED_COMMUNITY_GUILD_ID, bot.id);
assertExists(member?.id);
assertEquals(member?.id, bot.id);
Deno.test({
name: "[member] fetches the bot and compares the bot's id with the fetched member's id",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const member = await bot.helpers.getMember(CACHED_COMMUNITY_GUILD_ID, bot.id);
assertExists(member?.id);
assertEquals(member?.id, bot.id);
},
});
Deno.test("[member] Gets a member list and checks if the bot is in the member list", async () => {
const bot = loadBot();
Deno.test({
name: "[member] Gets a member list and checks if the bot is in the member list",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const members = await bot.helpers.getMembers(CACHED_COMMUNITY_GUILD_ID, { "limit": 10 });
assertEquals(members.has(bot.id), true);
const members = await bot.helpers.getMembers(CACHED_COMMUNITY_GUILD_ID, { "limit": 10 });
assertEquals(members.has(bot.id), true);
},
});
+1
View File
@@ -4,6 +4,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[role] role unit tests",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const role = await bot.helpers.createRole(CACHED_COMMUNITY_GUILD_ID, {
+1 -1
View File
@@ -4,7 +4,7 @@
// Deno.test({
// name: "[Memory] Benchmark memory tests",
// fn: async (t) => {
// async fn (t) {
// const bot = enableCachePlugin(loadBot());
// await memoryBenchmarks(bot, {
+12 -8
View File
@@ -1,13 +1,17 @@
import { assertEquals, assertExists } from "../deps.ts";
import { loadBot } from "../mod.ts";
Deno.test("[misc] Get gateway bot information", async () => {
const bot = loadBot();
const data = await bot.helpers.getGatewayBot();
Deno.test({
name: "[misc] Get gateway bot information",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const data = await bot.helpers.getGatewayBot();
assertExists(data);
assertEquals(data.url, "wss://gateway.discord.gg");
assertEquals(data.shards, 1);
assertEquals(data.sessionStartLimit.total, 1000);
assertEquals(data.sessionStartLimit.maxConcurrency, 1);
assertExists(data);
assertEquals(data.url, "wss://gateway.discord.gg");
assertEquals(data.shards, 1);
assertEquals(data.sessionStartLimit.total, 1000);
assertEquals(data.sessionStartLimit.maxConcurrency, 1);
},
});
+8 -4
View File
@@ -1,8 +1,12 @@
import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
Deno.test("[application] Get application info", async () => {
const bot = loadBot();
const application = await bot.helpers.getApplicationInfo();
assertEquals(application.id, bot.id);
Deno.test({
name: "[application] Get application info",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const application = await bot.helpers.getApplicationInfo();
assertEquals(application.id, bot.id);
},
});
+2 -1
View File
@@ -3,7 +3,8 @@ import { loadBot } from "../mod.ts";
Deno.test({
name: "[User] get a user and transform",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const user = await bot.helpers.getUser(bot.id);
assertExists(user?.id);
+9 -5
View File
@@ -1,9 +1,13 @@
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[Misc] Rate Limit Test", async () => {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "test" });
await Promise.all(Array(10).map(() => bot.helpers.sendMessage(channel.id, { content: "Rate Limit Test" })));
await bot.helpers.deleteChannel(channel.id);
Deno.test({
name: "[Misc] Rate Limit Test",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "test" });
await Promise.all(Array(10).map(() => bot.helpers.sendMessage(channel.id, { content: "Rate Limit Test" })));
await bot.helpers.deleteChannel(channel.id);
},
});
+2 -1
View File
@@ -3,7 +3,8 @@ import { loadBot } from "../mod.ts";
Deno.test({
name: "[tranform] snowflake to bigint",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
assertEquals(130136895395987456n, bot.transformers.snowflake("130136895395987456"));
},
+9 -5
View File
@@ -1,9 +1,13 @@
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[typing] start typing", async () => {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "typing" });
await bot.helpers.startTyping(channel.id);
await bot.helpers.deleteChannel(channel.id);
Deno.test({
name: "[typing] start typing",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "typing" });
await bot.helpers.startTyping(channel.id);
await bot.helpers.deleteChannel(channel.id);
},
});
+25 -21
View File
@@ -3,29 +3,33 @@ import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[stickers] Create guild sticker", async () => {
const bot = loadBot();
const sticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
Deno.test({
name: "[stickers] Create guild sticker",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const sticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
assertEquals(sticker.name, "sticker name");
assertEquals(sticker.description, "sticker description");
assertEquals(sticker.tags, "sticker tags");
assertEquals(sticker.name, "sticker name");
assertEquals(sticker.description, "sticker description");
assertEquals(sticker.tags, "sticker tags");
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "test" });
const message = await bot.helpers.sendMessage(channel.id, { stickerIds: [sticker.id] });
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "test" });
const message = await bot.helpers.sendMessage(channel.id, { stickerIds: [sticker.id] });
assertEquals(message.stickerItems?.[0].formatType, StickerFormatTypes.Png);
assertEquals(message.stickerItems?.[0].id, sticker.id);
assertEquals(message.stickerItems?.[0].name, sticker.name);
assertEquals(message.stickerItems?.[0].formatType, StickerFormatTypes.Png);
assertEquals(message.stickerItems?.[0].id, sticker.id);
assertEquals(message.stickerItems?.[0].name, sticker.name);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id);
await bot.helpers.deleteChannel(channel.id);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id);
await bot.helpers.deleteChannel(channel.id);
},
});
+17 -13
View File
@@ -2,17 +2,21 @@ import { assertRejects } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[stickers] Delete guild sticker", async () => {
const bot = loadBot();
const sticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id);
await assertRejects(() => bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id));
Deno.test({
name: "[stickers] Delete guild sticker",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const sticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id);
await assertRejects(() => bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id));
},
});
+24 -20
View File
@@ -2,25 +2,29 @@ import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[stickers] Edit guild sticker", async () => {
const bot = loadBot();
const createSticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
description: "test",
tags: "test",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const editSticker = await bot.helpers.editGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
});
assertEquals(editSticker.name, "sticker name");
assertEquals(editSticker.description, "sticker description");
assertEquals(editSticker.tags, "sticker tags");
Deno.test({
name: "[stickers] Edit guild sticker",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const createSticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "test",
description: "test",
tags: "test",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const editSticker = await bot.helpers.editGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
});
assertEquals(editSticker.name, "sticker name");
assertEquals(editSticker.description, "sticker description");
assertEquals(editSticker.tags, "sticker tags");
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, editSticker.id);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, editSticker.id);
},
});
+20 -16
View File
@@ -2,21 +2,25 @@ import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[stickers] Get guild sticker", async () => {
const bot = loadBot();
const createSticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const getSticker = await bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id);
assertEquals(getSticker.name, "sticker name");
assertEquals(getSticker.description, "sticker description");
assertEquals(getSticker.tags, "sticker tags");
Deno.test({
name: "[stickers] Get guild sticker",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const createSticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker name",
description: "sticker description",
tags: "sticker tags",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const getSticker = await bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id);
assertEquals(getSticker.name, "sticker name");
assertEquals(getSticker.description, "sticker description");
assertEquals(getSticker.tags, "sticker tags");
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, getSticker.id);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, getSticker.id);
},
});
+28 -24
View File
@@ -2,28 +2,32 @@ import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[stickers] Get guild stickers", async () => {
const bot = loadBot();
const sticker1 = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker 1",
description: "sticker 1",
tags: "sticker tags 1",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const sticker2 = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker 2",
description: "sticker 2",
tags: "sticker tags 2",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const stickers = await bot.helpers.getGuildStickers(CACHED_COMMUNITY_GUILD_ID);
assertEquals(stickers.size > 1, true);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker1.id);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker2.id);
Deno.test({
name: "[stickers] Get guild stickers",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const sticker1 = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker 1",
description: "sticker 1",
tags: "sticker tags 1",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const sticker2 = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, {
name: "sticker 2",
description: "sticker 2",
tags: "sticker tags 2",
file: {
blob: await (await fetch("https://i.imgur.com/ejqd6Ro.png")).blob(),
name: "ddlogo.png",
},
});
const stickers = await bot.helpers.getGuildStickers(CACHED_COMMUNITY_GUILD_ID);
assertEquals(stickers.size > 1, true);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker1.id);
await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker2.id);
},
});
+8 -4
View File
@@ -1,8 +1,12 @@
import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
Deno.test("[stickers] Get sticker", async () => {
const bot = loadBot();
const sticker = await bot.helpers.getSticker(749054660769218631n);
assertEquals(sticker.name, "Wave");
Deno.test({
name: "[stickers] Get sticker",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const sticker = await bot.helpers.getSticker(749054660769218631n);
assertEquals(sticker.name, "Wave");
},
});
+99 -57
View File
@@ -1,13 +1,13 @@
import { formatImageURL, hasProperty, iconBigintToHash, iconHashToBigInt, validateLength } from "../mod.ts";
import { Collection, formatImageURL, hasProperty, iconBigintToHash, iconHashToBigInt, validateLength } from "../mod.ts";
import { bigintToSnowflake, snowflakeToBigint } from "../util/bigint.ts";
import { removeTokenPrefix } from "../util/token.ts";
import { assertEquals, assertExists, assertNotEquals } from "./deps.ts";
import { loadBot } from "./mod.ts";
import { Collection } from "../mod.ts";
import { delayUntil } from "./utils.ts";
Deno.test({
name: "[token] Remove token prefix when Bot is prefixed.",
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals("discordeno is best lib", removeTokenPrefix("Bot discordeno is best lib"));
},
@@ -15,44 +15,58 @@ Deno.test({
Deno.test({
name: "[token] Remove token prefix when Bot is NOT prefixed.",
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals("discordeno is best lib", removeTokenPrefix("discordeno is best lib"));
},
});
Deno.test("[bigint] - Transform a snowflake string to bigint", () => {
const text = "130136895395987456";
const big = 130136895395987456n;
const result = snowflakeToBigint(text);
Deno.test({
name: "[bigint] - Transform a snowflake string to bigint",
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const text = "130136895395987456";
const big = 130136895395987456n;
const result = snowflakeToBigint(text);
assertEquals(big, result);
assertNotEquals(text, result);
assertEquals(big, result);
assertNotEquals(text, result);
},
});
Deno.test("[bigint] - Transform a bigint to a string", () => {
const text = "130136895395987456";
const big = 130136895395987456n;
const result = bigintToSnowflake(big);
Deno.test({
name: "[bigint] - Transform a bigint to a string",
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const text = "130136895395987456";
const big = 130136895395987456n;
const result = bigintToSnowflake(big);
assertEquals(text, result);
assertNotEquals(big, result);
assertEquals(text, result);
assertNotEquals(big, result);
},
});
Deno.test("[emoji] Create an emoji url", async () => {
const bot = loadBot();
assertEquals(
bot.helpers.getEmojiURL(785403373817823272n, false),
"https://cdn.discordapp.com/emojis/785403373817823272.png",
);
assertEquals(
bot.helpers.getEmojiURL(785403373817823272n, true),
"https://cdn.discordapp.com/emojis/785403373817823272.gif",
);
Deno.test({
name: "[emoji] Create an emoji url",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
assertEquals(
bot.helpers.getEmojiURL(785403373817823272n, false),
"https://cdn.discordapp.com/emojis/785403373817823272.png",
);
assertEquals(
bot.helpers.getEmojiURL(785403373817823272n, true),
"https://cdn.discordapp.com/emojis/785403373817823272.gif",
);
},
});
Deno.test({
name: "[guild] format a guild's icon url",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
assertEquals(
bot.helpers.getGuildIconURL(785384884197392384n, 3837424427068676005442449262648382018748n),
@@ -63,7 +77,8 @@ Deno.test({
Deno.test({
name: "[guild] format a guild's banner url",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
assertEquals(
@@ -77,7 +92,8 @@ Deno.test({
Deno.test({
name: "[guild] format a guild's splash url",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
assertEquals(
bot.helpers.getGuildSplashURL(785384884197392384n, 3837424427068676005442449262648382018748n),
@@ -88,7 +104,8 @@ Deno.test({
Deno.test({
name: "[utils] format image url",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(formatImageURL(`https://skillz.is.pro`), "https://skillz.is.pro.jpg?size=128");
assertEquals(formatImageURL(`https://skillz.is.pro`, 1024), "https://skillz.is.pro.jpg?size=1024");
assertEquals(formatImageURL(`https://skillz.is.pro`, 1024, "gif"), "https://skillz.is.pro.gif?size=1024");
@@ -103,70 +120,80 @@ const a_iconBigInt = 3503487521485885045056617826984736090062n;
Deno.test({
name: "[utils] icon hash to bigint",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(iconHashToBigInt(iconHash), iconBigInt);
},
});
Deno.test({
name: "[utils] icon bigint to hash",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(iconBigintToHash(iconBigInt), iconHash);
},
});
Deno.test({
name: "[utils] icon hash to bigint a_ (animated)",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(iconHashToBigInt(a_iconHash), a_iconBigInt);
},
});
Deno.test({
name: "[utils] icon bigint to hash a_ (animated)",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(iconBigintToHash(a_iconBigInt), a_iconHash);
},
});
Deno.test({
name: "[utils] Validate length is too low",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(validateLength("test", { min: 5 }), false);
},
});
Deno.test({
name: "[utils] Validate length is too high",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(validateLength("test", { max: 3 }), false);
},
});
Deno.test({
name: "[utils] Validate length is NOT just right in between.",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(validateLength("test", { min: 5, max: 3 }), false);
},
});
Deno.test({
name: "[utils] Validate length is NOT too low",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(validateLength("test", { min: 3 }), true);
},
});
Deno.test({
name: "[utils] Validate length is NOT too high",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(validateLength("test", { max: 5 }), true);
},
});
Deno.test({
name: "[utils] Validate length is just right in between.",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(validateLength("test", { min: 3, max: 6 }), true);
},
});
@@ -175,21 +202,24 @@ const obj = { prop: "lts372005" };
Deno.test({
name: "[utils] hasProperty does HAVE property",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(hasProperty(obj, "prop"), true);
},
});
Deno.test({
name: "[utils] hasProperty does NOT HAVE property",
fn() {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(hasProperty(obj, "lts372005"), false);
},
});
Deno.test({
name: "[member] format a members avatar url",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
assertEquals(
@@ -203,14 +233,16 @@ Deno.test({
Deno.test({
name: "[collection] Create a collection",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const collection = new Collection();
assertExists(collection);
await t.step({
name: "[collection] collection values to array",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const testCollection = new Collection([["best", "tri"], ["proficient", "yui"]]);
assertEquals(testCollection.array(), ["tri", "yui"]);
@@ -219,7 +251,8 @@ Deno.test({
await t.step({
name: "[collection] get a random value",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const testCollection = new Collection([["best", "tri"]]);
assertEquals(["best", "tri"].includes(testCollection.random() ?? ""), true);
@@ -229,7 +262,8 @@ Deno.test({
await t.step({
name: "[collection] Set a value without maxSize",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
collection.set("best developer", "triformine");
assertEquals(collection.size, 1);
assertEquals(collection.get("best developer"), "triformine");
@@ -238,14 +272,14 @@ Deno.test({
await t.step({
name: "[collection] get the value of the first element",
fn: async (t) => {
async fn(t) {
assertEquals(collection.first(), "triformine");
},
});
await t.step({
name: "[collection] get the value of the last element",
fn: async (t) => {
async fn(t) {
assertEquals(collection.last(), "yes");
},
});
@@ -254,7 +288,8 @@ Deno.test({
await t.step({
name: "[collection] Create a collection with maxSize",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const maxSize = 2;
const maxCollection = new Collection([], {
@@ -267,7 +302,7 @@ Deno.test({
await t.step({
name: "[collection] Test if maxSize works properly",
fn: async (t) => {
async fn(t) {
maxCollection.set("foo", "bar");
maxCollection.set("me", "you");
@@ -279,7 +314,7 @@ Deno.test({
await t.step({
name: "[collection] Test if forceSet ignore maxSize",
fn: async (t) => {
async fn(t) {
maxCollection.forceSet("this", "not");
assertEquals(maxCollection.size, 3);
@@ -294,7 +329,8 @@ Deno.test({
await t.step({
name: "[collection] find by key or value",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(testCollection.find((v, k) => v === 2), 2);
assertEquals(testCollection.find((v, k) => k === "b"), 2);
},
@@ -302,7 +338,8 @@ Deno.test({
await t.step({
name: "[collection] filter by key or value",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(testCollection.filter((v, k) => v === 3).size, 1);
assertEquals(testCollection.filter((v, k) => k === "d").size, 0);
},
@@ -310,14 +347,16 @@ Deno.test({
await t.step({
name: "[collection] map",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(testCollection.map((k, v) => `${v}${k}`), ["a1", "b2", "c3"]);
},
});
await t.step({
name: "[collection] some",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(testCollection.some((v, _) => v === 1), true);
assertEquals(testCollection.some((v, _) => v === 4), false);
},
@@ -325,7 +364,8 @@ Deno.test({
await t.step({
name: "[collection] every",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(testCollection.every((v, _) => v !== 0), true);
assertEquals(testCollection.every((v, _) => v === 1), false);
},
@@ -333,14 +373,16 @@ Deno.test({
await t.step({
name: "[collection] reduce",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
assertEquals(testCollection.reduce((acc, val) => acc + val, 0), 6);
},
});
await t.step({
name: "[collection] start sweeper",
fn: async (t) => {
ignore: Deno.env.get("TEST_ENV") === "INTEGRATION",
async fn(t) {
const sweeperCollection = new Collection([["a", 1], ["b", 2]], {
sweeper: {
filter: (v, _) => v === 1,
+3 -2
View File
@@ -1,10 +1,11 @@
import { assertEquals, assertExists, assertRejects } from "../deps.ts";
import { assertExists, assertRejects } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[webhook] delete a webhook",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "deleteWebhook" });
+2 -1
View File
@@ -4,7 +4,8 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[webhook] delete a webhook",
fn: async () => {
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "deleteWebhook" });
+39 -35
View File
@@ -2,45 +2,49 @@ import { assertEquals, assertExists, assertNotEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[webhooks] Send a message with a webhook", async (t) => {
const bot = loadBot();
Deno.test({
name: "[webhooks] Send a message with a webhook",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "webhooks" });
assertExists(channel?.id);
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "webhooks" });
assertExists(channel?.id);
const webhook = await bot.helpers.createWebhook(channel.id, {
name: "gigi",
});
assertExists(webhook.token);
const message = await bot.helpers.sendWebhookMessage(webhook.id, webhook.token, {
content: "discordeno is best lib",
wait: true,
});
assertExists(message?.id);
await t.step("[webhooks] Get a webhook message", async () => {
const fetched = await bot.helpers.getWebhookMessage(webhook.id, webhook.token!, message.id);
assertExists(fetched);
assertEquals(fetched.content, message.content);
});
await t.step("[webhooks] Edit a webhook message", async () => {
const edited = await bot.helpers.editWebhookMessage(webhook.id, webhook.token!, message.id, {
content: "different",
const webhook = await bot.helpers.createWebhook(channel.id, {
name: "gigi",
});
assertExists(edited);
assertNotEquals(edited.content, message.content);
});
await t.step("[webhooks] Delete a webhook message", async () => {
assertExists(webhook.token);
await bot.helpers.deleteWebhookMessage(webhook.id, webhook.token, message.id);
});
await bot.helpers.deleteChannel(channel.id);
const message = await bot.helpers.sendWebhookMessage(webhook.id, webhook.token, {
content: "discordeno is best lib",
wait: true,
});
assertExists(message?.id);
await t.step("[webhooks] Get a webhook message", async () => {
const fetched = await bot.helpers.getWebhookMessage(webhook.id, webhook.token!, message.id);
assertExists(fetched);
assertEquals(fetched.content, message.content);
});
await t.step("[webhooks] Edit a webhook message", async () => {
const edited = await bot.helpers.editWebhookMessage(webhook.id, webhook.token!, message.id, {
content: "different",
});
assertExists(edited);
assertNotEquals(edited.content, message.content);
});
await t.step("[webhooks] Delete a webhook message", async () => {
assertExists(webhook.token);
await bot.helpers.deleteWebhookMessage(webhook.id, webhook.token, message.id);
});
await bot.helpers.deleteChannel(channel.id);
},
});
+49 -45
View File
@@ -2,61 +2,65 @@ import { assertEquals, assertExists, assertNotEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test("[webhooks] Webhook related tests", async (t) => {
const bot = loadBot();
Deno.test({
name: "[webhooks] Webhook related tests",
ignore: Deno.env.get("TEST_ENV") === "UNIT",
async fn(t) {
const bot = loadBot();
// Create a channel
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "wbhook" });
// Create a channel
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "wbhook" });
await t.step("[webhooks] Create a webhook", async (t) => {
const webhook = await bot.helpers.createWebhook(channel.id, {
name: "idk",
});
assertExists(webhook);
assertEquals(webhook.name, "idk");
await t.step("[webhooks] Create a webhook", async (t) => {
const webhook = await bot.helpers.createWebhook(channel.id, {
name: "idk",
});
assertExists(webhook);
assertEquals(webhook.name, "idk");
await t.step("[webhooks] Edit a webhook", async (t) => {
const edited = await bot.helpers.editWebhook(webhook.id, {
name: "edited",
await t.step("[webhooks] Edit a webhook", async (t) => {
const edited = await bot.helpers.editWebhook(webhook.id, {
name: "edited",
});
assertNotEquals(webhook.name, edited.name);
});
assertNotEquals(webhook.name, edited.name);
});
await t.step("[webhooks] Edit a webhook with token", async () => {
assertExists(webhook.token);
const edited = await bot.helpers.editWebhookWithToken(webhook.id, webhook.token, {
name: "editedtoken",
});
await t.step("[webhooks] Edit a webhook with token", async () => {
assertExists(webhook.token);
const edited = await bot.helpers.editWebhookWithToken(webhook.id, webhook.token, {
name: "editedtoken",
assertNotEquals(webhook.name, edited.name);
});
assertNotEquals(webhook.name, edited.name);
await t.step("[webhooks] Get a webhook", async () => {
const fetched = await bot.helpers.getWebhook(webhook.id);
assertExists(fetched);
assertEquals(webhook.id, fetched.id);
});
await t.step("[webhooks] Get a webhook with a token", async () => {
assertExists(webhook.token);
const fetched = await bot.helpers.getWebhookWithToken(webhook.id, webhook.token);
assertEquals(webhook.id, fetched.id);
});
});
await t.step("[webhooks] Get a webhook", async () => {
const fetched = await bot.helpers.getWebhook(webhook.id);
assertExists(fetched);
assertEquals(webhook.id, fetched.id);
await t.step("[webhooks] Get channel webhooks", async (t) => {
const second = await bot.helpers.createWebhook(channel.id, { name: "what nonsense" });
assertExists(second);
const fetched = await bot.helpers.getChannelWebhooks(channel.id);
assertEquals(fetched.size > 1, true);
await t.step("[webhooks] Get guild webhooks", async () => {
const guildWebhooks = await bot.helpers.getGuildWebhooks(channel.guildId);
assertEquals(guildWebhooks.size > 1, true);
});
});
await t.step("[webhooks] Get a webhook with a token", async () => {
assertExists(webhook.token);
const fetched = await bot.helpers.getWebhookWithToken(webhook.id, webhook.token);
assertEquals(webhook.id, fetched.id);
});
});
await t.step("[webhooks] Get channel webhooks", async (t) => {
const second = await bot.helpers.createWebhook(channel.id, { name: "what nonsense" });
assertExists(second);
const fetched = await bot.helpers.getChannelWebhooks(channel.id);
assertEquals(fetched.size > 1, true);
await t.step("[webhooks] Get guild webhooks", async () => {
const guildWebhooks = await bot.helpers.getGuildWebhooks(channel.guildId);
assertEquals(guildWebhooks.size > 1, true);
});
});
await bot.helpers.deleteChannel(channel.id);
await bot.helpers.deleteChannel(channel.id);
},
});