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; 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'); });