Files
minabot/src/discord/help.test.ts
2026-09-08 08:33:34 +02:00

34 lines
1.7 KiB
TypeScript

import { afterEach, expect, test } from 'bun:test';
import { discordFixture } from './test-fixture';
import { commands } from './commands';
import { help } from './help';
import { discordControls, discordReceipts, users } from '../db/schema';
let f: ReturnType<typeof discordFixture>;
afterEach(() => f?.close());
for (const guild of [false, true]) test(`/help works in ${guild ? 'servers privately' : 'bot DMs'} without creating an account`, async () => {
f = discordFixture();
const before = f.db.select().from(users).all();
const response = await f.run({ data: { name: 'help' } }, guild, '555555555555555555');
expect(response.type).toBe(4);
expect(response.data.flags).toBe(guild ? 64 : undefined);
expect(response.data.allowed_mentions).toEqual({ parse: [] });
for (const command of commands) expect(response.data.content).toContain(`**/${command.name}** — ${command.description}`);
expect(response.data.components[0].components[0].url).toBe(`${f.origin}/`);
expect(f.db.select().from(users).all()).toEqual(before);
expect(f.db.select().from(discordControls).all()).toEqual([]);
expect(f.db.select().from(discordReceipts).all()).toEqual([]);
expect(f.changed).toEqual([]);
});
test('help stays within Discord message limits as command definitions grow', () => {
const response = help(true, 'https://example.com');
expect('content' in response.data! && response.data.content!.length).toBeLessThanOrEqual(2000);
expect(commands.find(c => c.name === 'help')?.contexts).toEqual([0, 1]);
});
test('unknown commands point users to help', async () => {
f = discordFixture();
expect((await f.run({ data: { name: 'unknown' } }, true)).data.content).toContain('/help');
});