fix: upload binary files to Telegram with source payload

This commit is contained in:
MythEclipse
2026-05-18 08:18:55 +07:00
parent 9aedc59b69
commit 91986d1d51
2 changed files with 35 additions and 7 deletions
+28
View File
@@ -18,6 +18,15 @@ mock.module('telegraf', () => {
],
}),
),
sendDocument: mock(() =>
Promise.resolve({
message_id: 54321,
document: {
file_id: 'document_id',
file_unique_id: 'document_unique_id',
},
}),
),
};
}
},
@@ -71,6 +80,25 @@ describe('Telegram API Utilities', () => {
});
});
it('should forward documents with source and filename payload', async () => {
const bot = getBot();
const chunk = Buffer.from('fake document data');
const fileName = 'document.pdf';
const result = await forwardToStorage(chunk, fileName, true);
expect(bot.telegram.sendDocument).toHaveBeenCalledWith(
-1003996572954,
{ source: chunk, filename: fileName },
{ caption: `📁 ${fileName}` },
);
expect(result).toEqual({
telegramFileId: 'document_id',
telegramFileUniqueId: 'document_unique_id',
storageMessageId: 54321,
});
});
it('should handle error when forwarding fails', async () => {
const bot = getBot();
bot.telegram.sendPhoto = mock(() => Promise.reject(new Error('Telegram send failed')));