mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-10-15 14:25:58 +00:00
Separated polling to telegramPolling.js
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
var TelegramPolling = require('../src/telegramPolling');
|
||||
var Telegram = require('../index');
|
||||
var request = require('request');
|
||||
var should = require('should');
|
||||
@@ -31,27 +32,6 @@ describe('Telegram', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#Polling', function () {
|
||||
it('should emit a `message` on polling', function (done) {
|
||||
var bot = new Telegram(TOKEN);
|
||||
bot.on('message', function (msg) {
|
||||
msg.should.be.an.instanceOf(Object);
|
||||
bot._polling = function () {};
|
||||
done();
|
||||
});
|
||||
bot.getUpdates = function() {
|
||||
return {
|
||||
then: function (cb) {
|
||||
cb([{update_id: 0, message: {}}]);
|
||||
return this;
|
||||
},
|
||||
catch: function () {}
|
||||
};
|
||||
};
|
||||
bot._polling();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#WebHook', function () {
|
||||
it('should reject request if same token not provided', function (done) {
|
||||
var bot = new Telegram(TOKEN, {webHook: true});
|
||||
@@ -378,3 +358,27 @@ describe('Telegram', function () {
|
||||
});
|
||||
|
||||
}); // End Telegram
|
||||
|
||||
|
||||
describe('#TelegramBotPolling', function () {
|
||||
it('should call the callback on polling', function (done) {
|
||||
function onUpdate (update) {
|
||||
update.should.be.an.instanceOf(Object);
|
||||
done();
|
||||
}
|
||||
var polling = new TelegramPolling(null, {interval: 500}, onUpdate);
|
||||
// Not the best way to mock, but it works
|
||||
polling._getUpdates = function() {
|
||||
return {
|
||||
then: function (cb) {
|
||||
cb([{update_id: 10, message: {}}]);
|
||||
return this;
|
||||
},
|
||||
catch: function () {
|
||||
return this;
|
||||
},
|
||||
finally: function () {}
|
||||
};
|
||||
};
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user