2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-28 12:57:38 +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 Telegram = require('../index');
var Promise = require('bluebird');
var request = require('request');
var should = require('should');
var fs = require('fs');
@ -517,23 +518,14 @@ describe('Telegram', function () {
describe('#TelegramBotPolling', function () {
it('should call the callback on polling', function (done) {
function onUpdate (update) {
update.should.be.an.instanceOf(Object);
var opts = {interval: 100, timeout: 1};
var polling = new TelegramPolling(TOKEN, opts, function () {
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 () {}
};
});
// The second time _getUpdates is called it will return a message
// Really dirty but it works
polling._getUpdates = function () {
return new Promise.resolve([{update_id: 10, message: {}}]);
};
});
});