Headers: - Every JavaScript file (sources, front, scripts, tests) starts with a /** @file … */ header, in the three levels used by sokko-g: a short description for simple files; Utilisé par / Attention / @see for shared modules; a full header (context, entry points, callers, dependencies, pitfalls) for index.js, the music queue, the web server, the storage manager and the jukebox page script. - No @author, @version or @since: git already knows. - test/fileHeaders.test.js fails `npm run check` when a header is missing or a central file's header is incomplete. Stylesheet (no visual change, checked by comparing every element's computed styles in Chromium at 1280, 800 and 400 px, hover included): - Role header and section comments. - Transparent shades derive from the colour variables with color-mix() instead of copied rgba() values; new tokens for repeated values (text, text on accent, accent gradient, white veils, shadow). - Native nesting for buttons, the live indicator, upload rows and home cards; drop the unused .hero__visual--large and redundant rules. - Utility classes move to the end so they win over components. The library list's u-mt-1, which never applied (.list reset it), is removed to keep the layout as it was. Docs: CONTRIBUTING.md describes the language, header and stylesheet conventions; CLAUDE.md points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
4.1 KiB
JavaScript
119 lines
4.1 KiB
JavaScript
/**
|
|
* @file Vérifie que toutes les commandes se chargent, puis /listcommand, /maketeam, /queue, les
|
|
* commandes vocales et les permissions des commandes d'administration.
|
|
*/
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
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);
|
|
|
|
const { loadCommands } = await import("../src/loadCommands.js");
|
|
|
|
test("all Discord commands expose valid command data", async () => {
|
|
const commands = await loadCommands();
|
|
assert.equal(commands.length, 13);
|
|
for (const command of commands) {
|
|
assert.doesNotThrow(() => command.data.toJSON());
|
|
assert.equal(typeof command.execute, "function");
|
|
assert.ok(command.category, command.data.name);
|
|
}
|
|
});
|
|
|
|
test("/listcommand lists every loaded command under its category", async () => {
|
|
const commands = await loadCommands();
|
|
const { buildCommandList } = await import("../src/commands/utility/listcommand.js");
|
|
const message = buildCommandList(commands);
|
|
for (const command of commands) {
|
|
assert.ok(message.includes(`\`/${command.data.name}\` : ${command.data.description}`));
|
|
}
|
|
assert.match(message, /__Jukebox__\n`\/play`/);
|
|
assert.ok(message.length <= 2000);
|
|
});
|
|
|
|
test("/maketeam splits players on commas when there are any", async () => {
|
|
const { parsePlayers } = await import("../src/commands/game/maketeam.js");
|
|
assert.deepEqual(parsePlayers(" Alice Bob\tChloé "), ["Alice", "Bob", "Chloé"]);
|
|
assert.deepEqual(parsePlayers("Jean Pierre, Marie,, Léo "), ["Jean Pierre", "Marie", "Léo"]);
|
|
});
|
|
|
|
test("administrative commands require Discord permissions", async () => {
|
|
const commands = await loadCommands();
|
|
const protectedCommands = new Set([
|
|
"deletemsgs",
|
|
"invitation",
|
|
"muteall",
|
|
"unmuteall",
|
|
"deafall",
|
|
"undeafall",
|
|
]);
|
|
|
|
for (const command of commands) {
|
|
const data = 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);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("/queue lists the current track and what comes next", async () => {
|
|
const { buildQueueMessage } = await import("../src/commands/jukebox/queue.js");
|
|
const message = buildQueueMessage({
|
|
currentTrack: { title: "Thème *principal*", duration: 187 },
|
|
queue: [{ title: "Suite", duration: 3909 }],
|
|
});
|
|
assert.match(message, /En cours : \*\*Thème \\\*principal\\\* \(3:07\)\*\*/);
|
|
assert.match(message, /1\. Suite \(1:05:09\)/);
|
|
});
|
|
|
|
test("vocal commands act on the caller's voice channel, skipping bots", async () => {
|
|
const { changeVoiceStatus, commandVoiceChannel } = await import("../src/features/utilities.js");
|
|
const { Collection } = await import("discord.js");
|
|
const muted = [];
|
|
const member = (id, { bot = false, fail = false } = {}) => ({
|
|
id,
|
|
user: { bot },
|
|
voice: {
|
|
setMute: async (value) => {
|
|
if (fail) throw new Error("left the channel");
|
|
muted.push([id, value]);
|
|
},
|
|
},
|
|
});
|
|
const callerChannel = {
|
|
isVoiceBased: () => true,
|
|
members: new Collection([
|
|
["a", member("a")],
|
|
["bot", member("bot", { bot: true })],
|
|
["gone", member("gone", { fail: true })],
|
|
["b", member("b")],
|
|
]),
|
|
};
|
|
const configuredChannel = { isVoiceBased: () => true, members: new Collection() };
|
|
const client = { channels: { cache: new Map([["1", configuredChannel]]) } };
|
|
|
|
assert.equal(commandVoiceChannel({ client, member: { voice: { channel: callerChannel } } }), callerChannel);
|
|
assert.equal(commandVoiceChannel({ client, member: { voice: { channel: null } } }), configuredChannel);
|
|
|
|
const originalError = console.error;
|
|
console.error = () => {};
|
|
try {
|
|
await changeVoiceStatus(callerChannel, "mute");
|
|
} finally {
|
|
console.error = originalError;
|
|
}
|
|
assert.deepEqual(muted, [["a", true], ["b", true]]);
|
|
});
|