|
| 1 | +import type { ChatInputCommandInteraction } from 'discord.js' |
| 2 | +import { MessageFlags } from 'discord.js' |
| 3 | +import { describe, expect, it, vi } from 'vitest' |
| 4 | +import { reply } from '../src/runtime/server/utils/reply' |
| 5 | + |
| 6 | +describe('reply', () => { |
| 7 | + const MockClient = vi.fn() |
| 8 | + const mockInteraction = () => { |
| 9 | + const mock = { |
| 10 | + reply: vi.fn(), |
| 11 | + editReply: vi.fn(), |
| 12 | + } |
| 13 | + return [mock as unknown as ChatInputCommandInteraction, mock] as const |
| 14 | + } |
| 15 | + |
| 16 | + it('should return a reply function', () => { |
| 17 | + const replyFunction = reply('Hello, world!') |
| 18 | + expect(replyFunction).toBeInstanceOf(Function) |
| 19 | + }) |
| 20 | + |
| 21 | + it('should reply with the correct content', async () => { |
| 22 | + const [interaction, mock] = mockInteraction() |
| 23 | + const client = new MockClient() |
| 24 | + reply('Hello, world!').call(client, interaction as unknown as ChatInputCommandInteraction, client) |
| 25 | + expect(mock.reply).toHaveBeenCalledExactlyOnceWith({ |
| 26 | + content: 'Hello, world!', |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should edit reply with the correct content', async () => { |
| 31 | + const [interaction, mock] = mockInteraction() |
| 32 | + const client = new MockClient() |
| 33 | + reply.edit('Hello, world!').call(client, interaction as unknown as ChatInputCommandInteraction, client) |
| 34 | + expect(mock.editReply).toHaveBeenCalledExactlyOnceWith({ |
| 35 | + content: 'Hello, world!', |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + it('should reply with ephemeral flag', async () => { |
| 40 | + const [interaction, mock] = mockInteraction() |
| 41 | + const client = new MockClient() |
| 42 | + reply.ephemeral('This is ephemeral!').call(client, interaction as unknown as ChatInputCommandInteraction, client) |
| 43 | + expect(mock.reply).toHaveBeenCalledExactlyOnceWith({ |
| 44 | + content: 'This is ephemeral!', |
| 45 | + flags: MessageFlags.Ephemeral, |
| 46 | + }) |
| 47 | + }) |
| 48 | +}) |
0 commit comments