All checks were successful
Deploy Palico Bot / deploy (push) Successful in 6s
- /invitation checks the bot can view and post in the channel, and turns Discord's 50001/50013 into a clear reply instead of a generic error - The DM route logs one line per request (user ID and status, never the text) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2 KiB
JavaScript
68 lines
2 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
Object.assign(process.env, {
|
|
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",
|
|
INVITE_LINK: "https://discord.gg/AbC-12",
|
|
});
|
|
|
|
const { command } = await import("../src/commands/utility/invitation.js");
|
|
|
|
function fakeInteraction({ canPost = true, sendError = null } = {}) {
|
|
const replies = [];
|
|
const sent = [];
|
|
return {
|
|
replies,
|
|
sent,
|
|
memberPermissions: { has: () => true },
|
|
options: { getString: () => null },
|
|
client: {},
|
|
guild: {
|
|
id: "1",
|
|
members: { me: {} },
|
|
invites: { fetch: async () => ({ code: "AbC-12", temporary: true, maxUses: 0 }) },
|
|
},
|
|
channel: {
|
|
isTextBased: () => true,
|
|
permissionsFor: () => ({ has: () => canPost }),
|
|
async send(message) {
|
|
if (sendError) throw sendError;
|
|
sent.push(message);
|
|
},
|
|
},
|
|
async reply(message) {
|
|
replies.push(message);
|
|
},
|
|
async deferReply() {},
|
|
async editReply(message) {
|
|
replies.push(message);
|
|
},
|
|
};
|
|
}
|
|
|
|
test("/invitation publishes the checked link", async () => {
|
|
const interaction = fakeInteraction();
|
|
await command.execute(interaction);
|
|
assert.equal(interaction.sent.length, 1);
|
|
assert.match(interaction.sent[0].content, /discord\.gg\/AbC-12/);
|
|
assert.match(interaction.replies.at(-1), /^Message publié/);
|
|
});
|
|
|
|
test("/invitation explains when the bot cannot post in the channel", async () => {
|
|
const missingAccess = Object.assign(new Error("Missing Access"), { code: 50001 });
|
|
for (const options of [{ canPost: false }, { sendError: missingAccess }]) {
|
|
const interaction = fakeInteraction(options);
|
|
await command.execute(interaction);
|
|
assert.equal(interaction.sent.length, 0);
|
|
assert.match(interaction.replies.at(-1), /je n'ai pas accès à ce salon/);
|
|
}
|
|
});
|