|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { TelegramBlock } from '@/blocks/blocks/telegram' |
| 3 | + |
| 4 | +describe('TelegramBlock', () => { |
| 5 | + const paramsFn = TelegramBlock.tools.config?.params |
| 6 | + |
| 7 | + if (!paramsFn) { |
| 8 | + throw new Error('TelegramBlock.tools.config.params function is missing') |
| 9 | + } |
| 10 | + |
| 11 | + it.concurrent('accepts a public URL string for telegram_send_photo', () => { |
| 12 | + const result = paramsFn({ |
| 13 | + operation: 'telegram_send_photo', |
| 14 | + botToken: 'token', |
| 15 | + chatId: ' 123 ', |
| 16 | + photo: ' https://example.com/a.jpg ', |
| 17 | + caption: 'hello', |
| 18 | + }) |
| 19 | + |
| 20 | + expect(result).toEqual({ |
| 21 | + botToken: 'token', |
| 22 | + chatId: '123', |
| 23 | + photo: 'https://example.com/a.jpg', |
| 24 | + caption: 'hello', |
| 25 | + }) |
| 26 | + }) |
| 27 | + |
| 28 | + it.concurrent('accepts a file-like object for telegram_send_photo (uses url)', () => { |
| 29 | + const result = paramsFn({ |
| 30 | + operation: 'telegram_send_photo', |
| 31 | + botToken: 'token', |
| 32 | + chatId: '123', |
| 33 | + photo: { id: 'f1', url: 'https://example.com/file.png' }, |
| 34 | + }) |
| 35 | + |
| 36 | + expect(result).toMatchObject({ |
| 37 | + photo: 'https://example.com/file.png', |
| 38 | + }) |
| 39 | + }) |
| 40 | + |
| 41 | + it.concurrent('accepts JSON-stringified file objects in advanced mode', () => { |
| 42 | + const result = paramsFn({ |
| 43 | + operation: 'telegram_send_photo', |
| 44 | + botToken: 'token', |
| 45 | + chatId: '123', |
| 46 | + photo: JSON.stringify({ id: 'f1', url: 'https://example.com/file.png' }), |
| 47 | + }) |
| 48 | + |
| 49 | + expect(result).toMatchObject({ |
| 50 | + photo: 'https://example.com/file.png', |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + it.concurrent('throws a user-facing error when photo is missing/blank', () => { |
| 55 | + expect(() => |
| 56 | + paramsFn({ |
| 57 | + operation: 'telegram_send_photo', |
| 58 | + botToken: 'token', |
| 59 | + chatId: '123', |
| 60 | + photo: ' ', |
| 61 | + }) |
| 62 | + ).toThrow('Photo is required.') |
| 63 | + }) |
| 64 | + |
| 65 | + it.concurrent('accepts a public URL string for telegram_send_video', () => { |
| 66 | + const result = paramsFn({ |
| 67 | + operation: 'telegram_send_video', |
| 68 | + botToken: 'token', |
| 69 | + chatId: '123', |
| 70 | + video: 'https://example.com/v.mp4', |
| 71 | + }) |
| 72 | + |
| 73 | + expect(result).toMatchObject({ |
| 74 | + video: 'https://example.com/v.mp4', |
| 75 | + }) |
| 76 | + }) |
| 77 | +}) |
0 commit comments