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

#TelegramBotPolling test a bit clear

This commit is contained in:
Yago 2016-03-13 13:44:06 +01:00
parent 5b93c4a4e1
commit bcafbfb0ac

View File

@ -2,6 +2,7 @@
var TelegramPolling = require('../src/telegramPolling'); var TelegramPolling = require('../src/telegramPolling');
var Telegram = require('../index'); var Telegram = require('../index');
var Promise = require('bluebird');
var request = require('request'); var request = require('request');
var should = require('should'); var should = require('should');
var fs = require('fs'); var fs = require('fs');
@ -517,23 +518,14 @@ describe('Telegram', function () {
describe('#TelegramBotPolling', function () { describe('#TelegramBotPolling', function () {
it('should call the callback on polling', function (done) { it('should call the callback on polling', function (done) {
function onUpdate (update) { var opts = {interval: 100, timeout: 1};
update.should.be.an.instanceOf(Object); var polling = new TelegramPolling(TOKEN, opts, function () {
done(); done();
} });
var polling = new TelegramPolling(null, {interval: 500}, onUpdate); // The second time _getUpdates is called it will return a message
// Not the best way to mock, but it works // Really dirty but it works
polling._getUpdates = function() { polling._getUpdates = function () {
return { return new Promise.resolve([{update_id: 10, message: {}}]);
then: function (cb) {
cb([{update_id: 10, message: {}}]);
return this;
},
catch: function () {
return this;
},
finally: function () {}
};
}; };
}); });
}); });