/
mention.test.ts
64 lines (53 loc) · 1.28 KB
/
mention.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { appMention } from './mention'
// モック関数
const mockSay = jest.fn()
const mockClient = {
conversations: {
replies: jest.fn(),
members: jest.fn(),
info: jest.fn()
}
}
const mockEvent = {
channel: 'test_channel',
thread_ts: 'test_thread_ts',
ts: 'test_ts'
}
const mockAsk = jest.fn()
jest.mock('./utils', () => ({
ask: () => mockAsk()
}))
describe('appMention', () => {
beforeEach(() => {
mockClient.conversations.replies.mockClear()
mockSay.mockClear()
mockAsk.mockClear()
})
it('should handle app mention event', async () => {
mockClient.conversations.replies.mockResolvedValueOnce({
messages: [
{
text: 'test message',
user: 'test_user'
}
]
})
mockAsk.mockResolvedValueOnce('GPTの回答')
const args = {
event: mockEvent as any,
client: mockClient as any,
say: mockSay
}
await appMention(args)
expect(mockClient.conversations.replies).toHaveBeenCalledWith({
channel: 'test_channel',
ts: 'test_thread_ts'
})
expect(mockSay).toHaveBeenCalledTimes(1)
expect(mockSay).toHaveBeenNthCalledWith(1, {
text: 'GPTの回答',
thread_ts: 'test_ts'
})
})
// 他のテストケースを追加してください
})