From f2153a775463fafd4a6b7a1c290069b7f6a1482b Mon Sep 17 00:00:00 2001 From: Yago Date: Sun, 3 Jan 2016 17:03:04 +0100 Subject: [PATCH] Throw error if Unsupported Buffer file type. Test 'should send a video from a Buffer' --- src/telegram.js | 3 +++ test/index.js | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index b9247d8..e2c28bf 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -239,6 +239,9 @@ TelegramBot.prototype._formatSendData = function (type, data) { }; } else if (Buffer.isBuffer(data)) { var filetype = fileType(data); + if (!filetype) { + throw new Error('Unsupported Buffer file type'); + } formData = {}; formData[type] = { value: data, diff --git a/test/index.js b/test/index.js index c18dc3e..5b8a1fa 100644 --- a/test/index.js +++ b/test/index.js @@ -367,6 +367,17 @@ describe('Telegram', function () { done(); }); }); + + /* Currently unsupported (https://github.com/sindresorhus/file-type/pull/44) + it('should send a video from a Buffer', function (done) { + var bot = new Telegram(TOKEN); + var video = fs.readFileSync(__dirname+'/video.mp4'); + bot.sendVideo(USERID, video).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + */ }); describe('#sendVoice', function () {