A fake transport that captures sends and lets the test inject inbound messages.
(platform: 'telegram' | 'discord' = 'telegram')
| 4 | |
| 5 | /** A fake transport that captures sends and lets the test inject inbound messages. */ |
| 6 | function fakeTransport(platform: 'telegram' | 'discord' = 'telegram') { |
| 7 | let onMsg: (m: Incoming) => void = () => {}; |
| 8 | const sent: Array<{ chatId: string; text: string; buttons?: Button[][] }> = []; |
| 9 | let n = 0; |
| 10 | const t: Transport = { |
| 11 | platform, maxLen: 4000, minEditIntervalMs: 0, |
| 12 | start: async (cb) => { onMsg = cb; }, |
| 13 | stop: async () => {}, |
| 14 | send: async (chatId, text, buttons) => { sent.push({ chatId, text, buttons }); return { id: `m${++n}` } as MessageRef; }, |
| 15 | edit: async () => {}, |
| 16 | ackCallback: async () => {}, |
| 17 | }; |
| 18 | const inject = (m: Partial<Incoming>) => onMsg({ platform, chatId: 'c1', userId: 'u1', text: '', ...m } as Incoming); |
| 19 | return { t, sent, inject }; |
| 20 | } |
| 21 | |
| 22 | const allowAll = { telegram: { allowedUsers: ['u1'] }, discord: { allowedUsers: ['u1'] } }; |
| 23 | const flush = () => new Promise(r => setTimeout(r, 0)); |