From 6a7c088a63ede8a11421c35261ff48f54e87dc8e Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Sameja Date: Fri, 26 Oct 2018 14:47:11 +0530 Subject: [PATCH] [v4.0] Add tests and add minor improvement Follow up update to #625 - Tests for both methods (sendAnimation, editMediaMessage) have been added. editMediaMessage is nested under sendAnimation, hence both tests are technically under a single block. - Add an improvement/minor fix to the editMediaMessage method, where we now stringify the first parameter (media) object interally within the library. This allows the lib user to simply pass an object as the 1st param without stringifying it. --- src/telegram.js | 2 +- test/telegram.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/telegram.js b/src/telegram.js index 88bb9f2..7dca2c2 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1228,7 +1228,7 @@ class TelegramBot extends EventEmitter { * @see https://core.telegram.org/bots/api#editmessagemedia */ editMessageMedia(media, form = {}) { - form.media = media; + form.media = stringify(media); return this._request('editMessageMedia', { form }); } diff --git a/test/telegram.js b/test/telegram.js index 103d868..acb153e 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -1436,4 +1436,28 @@ describe('TelegramBot', function telegramSuite() { }); }); }); + + describe('#sendAnimation', function sendAnimationSuite() { + before(function before() { + utils.handleRatelimit(bot, 'sendAnimation', this); + }); + it('should send a gif as an animation', function test() { + return bot.sendAnimation(USERID, `${__dirname}/data/photo.gif`).then(resp => { + assert.ok(is.object(resp)); + assert.ok(is.object(resp.document)); + + describe('#editMessageMedia', function editMessageMediaSuite() { + before(function before() { + utils.handleRatelimit(bot, 'editMessageMedia', this); + }); + it('should edit a media message', function test() { + return bot.editMessageMedia({ type: 'animation', media: resp.document.file_id, caption: 'media message edited'}, { chat_id: resp.chat.id, message_id: resp.message_id}).then(editedResp => { + assert.ok(is.object(editedResp)); + assert.ok(is.string(editedResp.caption)); + }); + }); + }); + }); + }); + }); }); // End Telegram