Files
flint/tests/templateVariables.test.ts
T
Puechberty Arthur e47cb68bc7 feat: implement command definition, registration, and execution framework
- Add `defineCommand` function to validate and normalize command inputs.
- Introduce `deployApplicationCommands` for deploying slash commands to Discord.
- Create `CommandRegistry` class for managing command registration and retrieval.
- Implement `buildSlashPayload` to construct slash command payloads with localization support.
- Add usage utilities for prefix and slash commands.
- Develop `CommandExecutor` to handle command execution with permission checks and cooldown management.
- Create member message rendering service for welcome and leave messages with customizable templates.
- Introduce presence template variables for dynamic bot status updates.
- Implement template variable utilities for rendering and extracting variables from strings.
2026-04-13 21:10:51 +02:00

48 lines
1.3 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
extractTemplateVariables,
hasTemplateVariable,
renderTemplate,
} from "../src/utils/templateVariables.js";
test("renderTemplate remplace les variables et applique les alias", () => {
const output = renderTemplate(
"Hello {{name}} from {{guilds}}",
{
name: "Arthur",
guild_count: "42",
},
{
aliases: {
guilds: "guild_count",
},
},
);
assert.equal(output, "Hello Arthur from 42");
});
test("renderTemplate conserve les variables inconnues par defaut", () => {
const output = renderTemplate("Missing {{unknown}}", {}, { keepUnknown: true });
assert.equal(output, "Missing {{unknown}}");
});
test("extractTemplateVariables normalise les alias", () => {
const variables = extractTemplateVariables("{{bot}} {{guilds}}", {
bot: "bot_name",
guilds: "guild_count",
});
assert.deepEqual(variables.sort(), ["bot_name", "guild_count"]);
});
test("hasTemplateVariable detecte les variables connues", () => {
const hasKnown = hasTemplateVariable("{{prefix}} {{other}}", ["prefix", "guild_count"]);
assert.equal(hasKnown, true);
const hasUnknownOnly = hasTemplateVariable("{{other}}", ["prefix", "guild_count"]);
assert.equal(hasUnknownOnly, false);
});