2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

src/telegram: Add tests for Bot API v3.1 methods

References:

  * PR: https://github.com/yagop/node-telegram-bot-api/pull/369
  * PR-by: @kamikazechaser
  * Parent-PR: https://github.com/yagop/node-telegram-bot-api/pull/362
  * Parent-PR-by: @Lord-Protector
This commit is contained in:
GochoMugo 2017-07-05 09:04:39 +03:00
parent 83d3235cc5
commit 96b90c2d56
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4
3 changed files with 106 additions and 0 deletions

View File

@ -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.

BIN
test/data/chat_photo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -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);