Skip to content

Commit 98a51d6

Browse files
committed
test: add unit tests for reply utility function
1 parent 2dc57d3 commit 98a51d6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/reply.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)