Files
flint/tests/defineCommand.test.ts
T
2026-04-14 22:32:27 +02:00

61 lines
1.7 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { defineCommand } from "../src/core/commands/defineCommand.js";
test("defineCommand refuse un argument requis apres un optionnel", () => {
assert.throws(() => {
defineCommand({
meta: { name: "broken", category: "test" },
args: [
{ name: "optional", type: "string", required: false, descriptionKey: "args.optional" },
{ name: "required", type: "string", required: true, descriptionKey: "args.required" },
],
execute: async () => undefined,
});
});
});
test("defineCommand refuse un cooldown invalide", () => {
assert.throws(() => {
defineCommand({
meta: { name: "brokenCooldown", category: "test" },
cooldown: 0,
execute: async () => undefined,
});
});
});
test("defineCommand applique les valeurs par defaut", () => {
const command = defineCommand({
meta: { name: "ok", category: "test" },
execute: async () => undefined,
});
assert.deepEqual(command.args, []);
assert.deepEqual(command.permissions, []);
assert.deepEqual(command.examples, []);
assert.equal(command.sensitive, false);
assert.equal(command.cooldown, undefined);
});
test("defineCommand refuse une commande sensible sans permission", () => {
assert.throws(() => {
defineCommand({
meta: { name: "sensitiveNoPerm", category: "test" },
sensitive: true,
execute: async () => undefined,
});
});
});
test("defineCommand marque sensible automatiquement si permissions presentes", () => {
const command = defineCommand({
meta: { name: "secured", category: "test" },
permissions: ["ManageGuild"],
execute: async () => undefined,
});
assert.equal(command.sensitive, true);
});