Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enricostara committed Aug 22, 2015
1 parent ffb042a commit deb46b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "telegram.link",
"version": "0.6.2",
"version": "0.6.3",
"description": "Telegram API library",
"keywords": [
"telegram",
Expand Down
13 changes: 13 additions & 0 deletions test/telegram.link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,17 @@ describe('TelegramLink', function () {
});
});

describe('#un/registerOnUpdates()', function () {

it('should returns ok', function (done) {
var client = telegramLink.createClient({authKey: {}}, primaryDC, function () {
var callback = function() {};
client.registerOnUpdates(callback);
(client._channel.getParser().listeners('api.type.Updates')[0] === callback).should.be.true();
client.unregisterOnUpdates(callback);
(client._channel.getParser().listeners('api.type.Updates').length).should.be.equal(0);
done();
});
});
});
});
14 changes: 9 additions & 5 deletions test/utility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ var utility = require('lib/utility');

describe('utility', function () {
describe('#callService()', function () {
var theCallback;
var emitter = {
isReady: function() { return true; },
once: function(event, callback) {
console.log('once ', event);
callback.should.be.equal('callback');
(typeof callback).should.be.equal('function');
theCallback = callback;
},
emit: function(event, error) {
console.log('emit ', event, error.stack);
emit: function(event, obj) {
console.log('emit ', event, obj);
theCallback(obj);
}
};
it('should returns ok', function (done) {
Expand All @@ -21,12 +24,13 @@ describe('utility', function () {
input.props.should.have.property('second', 2);
input.channel.should.be.equal('channel');
(typeof input.callback).should.be.equal('function');
done();
input.callback();
};
(function testCall(first, second, callback) {
var promise = utility.callService(api.service.auth.testCall, emitter, 'channel', callback, arguments);
promise.should.be.an.instanceOf(Promise);
})(1, 2, 'callback');
promise.then(done);
})(1, 2, done);
});
});
});

0 comments on commit deb46b3

Please sign in to comment.