Harden bot, storage and web API
This commit is contained in:
parent
e974bc6660
commit
20624a5c9c
43 changed files with 1265 additions and 1012 deletions
58
test/commands.test.js
Normal file
58
test/commands.test.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
|
||||
const ENVIRONMENT = {
|
||||
NODE_ENV: "test",
|
||||
DISCORD_GUILD_ID: "1",
|
||||
SHINUWA_USER_ID: "1",
|
||||
WEB_SERVER_PORT: "3000",
|
||||
WEB_API_KEY: "test-key",
|
||||
DISCORD_APPLICATION_ID: "1",
|
||||
DISCORD_TOKEN: "test-token",
|
||||
VOICE_CHANNEL_ID: "1",
|
||||
TEXT_CHANNEL_ID: "1",
|
||||
GAME_SERVERS_MESSAGE_ID: "1",
|
||||
};
|
||||
Object.assign(process.env, ENVIRONMENT);
|
||||
|
||||
async function loadCommands() {
|
||||
const files = fs
|
||||
.readdirSync("src/commands", { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.flatMap((directory) =>
|
||||
fs
|
||||
.readdirSync(`src/commands/${directory.name}`)
|
||||
.filter((file) => file.endsWith(".js"))
|
||||
.map((file) => `../src/commands/${directory.name}/${file}`)
|
||||
);
|
||||
return Promise.all(files.map((file) => import(file)));
|
||||
}
|
||||
|
||||
test("all Discord commands expose valid command data", async () => {
|
||||
const modules = await loadCommands();
|
||||
assert.equal(modules.length, 9);
|
||||
for (const module of modules) {
|
||||
assert.doesNotThrow(() => module.command.data.toJSON());
|
||||
assert.equal(typeof module.command.execute, "function");
|
||||
}
|
||||
});
|
||||
|
||||
test("administrative commands require Discord permissions", async () => {
|
||||
const modules = await loadCommands();
|
||||
const protectedCommands = new Set([
|
||||
"deletemsgs",
|
||||
"muteall",
|
||||
"unmuteall",
|
||||
"deafall",
|
||||
"undeafall",
|
||||
]);
|
||||
|
||||
for (const module of modules) {
|
||||
const data = module.command.data.toJSON();
|
||||
if (protectedCommands.has(data.name)) {
|
||||
assert.notEqual(data.default_member_permissions, undefined, data.name);
|
||||
assert.notEqual(data.default_member_permissions, null, data.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue