mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 05:17:41 +00:00
#TelegramBotPolling test a bit clear
This commit is contained in:
parent
5b93c4a4e1
commit
bcafbfb0ac
@ -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 () {}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user