diff --git a/test/README.md b/test/README.md index db6a07c..0e5a091 100644 --- a/test/README.md +++ b/test/README.md @@ -23,3 +23,4 @@ npm run test npm run eslint # static-analysis npm run mocha # mocha tests ``` +Note: The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. \ No newline at end of file diff --git a/test/data/chat_photo.png b/test/data/chat_photo.png new file mode 100644 index 0000000..ee0756d Binary files /dev/null and b/test/data/chat_photo.png differ diff --git a/test/telegram.js b/test/telegram.js index 5f445ab..d45f4ca 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -812,8 +812,113 @@ describe('TelegramBot', function telegramSuite() { describe.skip('#unbanChatMember', function unbanChatMemberSuite() {}); + describe.skip('#restrictChatMember', function restrictChatMemberSuite() {}); + + describe.skip('#promoteChatMember', function promoteChatMemberSuite() {}); + describe.skip('#answerCallbackQuery', function answerCallbackQuerySuite() {}); + describe('#exportChatInviteLink', function exportChatInviteLinkSuite() { + before(function before() { + utils.handleRatelimit(bot, 'exportChatInviteLink', this); + }); + it('should export the group invite link', function test() { + return bot.exportChatInviteLink(GROUPID).then(resp => { + assert(resp.match(/^https:\/\/t\.me\/joinchat\/.+$/i), 'is a telegram invite link'); + }); + }); + }); + + describe('#setChatPhoto', function setChatPhotoSuite() { + this.timeout(timeout); + before(function before() { + utils.handleRatelimit(bot, 'setChatPhoto', this); + }); + it('should set a chat photo from file', function test() { + const photo = `${__dirname}/data/chat_photo.png`; + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + it('should set a chat photo from fs.readStream', function test() { + const photo = fs.createReadStream(`${__dirname}/data/chat_photo.png`); + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + it('should set a chat photo from request Stream', function test() { + const photo = request(`${staticUrl}/chat_photo.png`); + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + it('should set a chat photo from a Buffer', function test() { + const photo = fs.readFileSync(`${__dirname}/data/chat_photo.png`); + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#deleteChatPhoto', function deleteChatPhotoSuite() { + before(function before() { + utils.handleRatelimit(bot, 'deleteChatPhoto', this); + }); + it('should delete the chat photo', function test() { + return bot.deleteChatPhoto(GROUPID).then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#setChatTitle', function setChatTitleSuite() { + before(function before() { + utils.handleRatelimit(bot, 'setChatTitle', this); + }); + it('should set the chat title', function test() { + return bot.setChatTitle(GROUPID, 'ntba test group').then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#setChatDescription', function setChatDescriptionSuite() { + before(function before() { + utils.handleRatelimit(bot, 'setChatDescription', this); + }); + it('should set the chat description', function test() { + return bot.setChatDescription(GROUPID, 'node-telegram-bot-api test group').then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#pinChatMessage', function pinChatMessageSuite() { + let messageId; + before(function before() { + utils.handleRatelimit(bot, 'pinChatMessage', this); + return bot.sendMessage(GROUPID, 'To be pinned').then(resp => { + messageId = resp.message_id; + }); + }); + it('should pin chat message', function test() { + return bot.pinChatMessage(GROUPID, messageId).then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#unpinChatMessage', function unpinChatMessageSuite() { + before(function before() { + utils.handleRatelimit(bot, 'unpinChatMessage', this); + }); + it('should unpin chat message', function test() { + return bot.unpinChatMessage(GROUPID).then(resp => { + assert.equal(resp, true); + }); + }); + }); + describe('#editMessageText', function editMessageTextSuite() { before(function before() { utils.handleRatelimit(bot, 'sendMessage', this);