-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathtelegram.test.ts
More file actions
77 lines (66 loc) · 2.04 KB
/
Copy pathtelegram.test.ts
File metadata and controls
77 lines (66 loc) · 2.04 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
import { describe, expect, it } from 'vitest'
import { TelegramBlock } from '@/blocks/blocks/telegram'
describe('TelegramBlock', () => {
const paramsFn = TelegramBlock.tools.config?.params
if (!paramsFn) {
throw new Error('TelegramBlock.tools.config.params function is missing')
}
it.concurrent('accepts a public URL string for telegram_send_photo', () => {
const result = paramsFn({
operation: 'telegram_send_photo',
botToken: 'token',
chatId: ' 123 ',
photo: ' https://example.com/a.jpg ',
caption: 'hello',
})
expect(result).toEqual({
botToken: 'token',
chatId: '123',
photo: 'https://example.com/a.jpg',
caption: 'hello',
})
})
it.concurrent('accepts a file-like object for telegram_send_photo (uses url)', () => {
const result = paramsFn({
operation: 'telegram_send_photo',
botToken: 'token',
chatId: '123',
photo: { id: 'f1', url: 'https://example.com/file.png' },
})
expect(result).toMatchObject({
photo: 'https://example.com/file.png',
})
})
it.concurrent('accepts JSON-stringified file objects in advanced mode', () => {
const result = paramsFn({
operation: 'telegram_send_photo',
botToken: 'token',
chatId: '123',
photo: JSON.stringify({ id: 'f1', url: 'https://example.com/file.png' }),
})
expect(result).toMatchObject({
photo: 'https://example.com/file.png',
})
})
it.concurrent('throws a user-facing error when photo is missing/blank', () => {
expect(() =>
paramsFn({
operation: 'telegram_send_photo',
botToken: 'token',
chatId: '123',
photo: ' ',
})
).toThrow('Photo is required.')
})
it.concurrent('accepts a public URL string for telegram_send_video', () => {
const result = paramsFn({
operation: 'telegram_send_video',
botToken: 'token',
chatId: '123',
video: 'https://example.com/v.mp4',
})
expect(result).toMatchObject({
video: 'https://example.com/v.mp4',
})
})
})