insight-ui-zcash/test/lib/PeerSync.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-01-15 07:53:44 -08:00
'use strict';
2014-01-16 11:12:32 -08:00
var chai = require('chai'),
expect = chai.expect,
sinon = require('sinon');
2014-01-15 07:53:44 -08:00
var PeerSync = require('../../lib/PeerSync.js').class();
2014-01-16 11:12:32 -08:00
describe('PeerSync', function() {
var ps;
2014-02-11 11:03:46 -08:00
beforeEach(function(done) {
2014-01-16 08:01:10 -08:00
ps = new PeerSync();
2014-02-11 11:03:46 -08:00
ps.init({
verbose: false
}, done);
2014-01-16 11:12:32 -08:00
});
2014-02-11 11:03:46 -08:00
afterEach(function() {
2014-01-16 11:12:32 -08:00
ps.close();
2014-01-16 08:01:10 -08:00
});
2014-01-15 07:53:44 -08:00
describe('#init()', function() {
2014-02-11 11:03:46 -08:00
it('should return with no errors', function() {
2014-01-16 11:12:32 -08:00
var other_ps = new PeerSync();
2014-02-11 11:03:46 -08:00
expect(other_ps.init.bind(other_ps)).not.to.
throw (Error);
2014-01-16 11:12:32 -08:00
other_ps.close();
2014-01-15 07:53:44 -08:00
});
});
2014-02-11 11:03:46 -08:00
describe('#handleInv()', function() {
var inv_info = {
2014-02-11 11:03:46 -08:00
message: {
invs: []
},
conn: {
sendGetData: sinon.spy()
}
2014-01-16 11:12:32 -08:00
};
2014-02-11 11:03:46 -08:00
it('should return with no errors', function() {
2014-01-16 11:12:32 -08:00
expect(function() {
2014-02-11 11:03:46 -08:00
ps.handleInv(inv_info);
}).not.to.
throw (Error);
2014-01-16 11:12:32 -08:00
});
2014-02-11 11:03:46 -08:00
it('should call sendGetData', function() {
ps.handleInv(inv_info);
2014-01-16 11:47:06 -08:00
expect(inv_info.conn.sendGetData.calledTwice).to.be.ok;
2014-01-16 11:12:32 -08:00
});
2014-01-16 08:01:10 -08:00
});
2014-01-16 08:01:10 -08:00
describe('#run()', function() {
2014-02-11 11:03:46 -08:00
it('should setup peerman', function() {
2014-01-16 16:08:50 -08:00
var startSpy = sinon.spy(ps.peerman, 'start');
var onSpy = sinon.spy(ps.peerman, 'on');
ps.run();
2014-02-11 11:03:46 -08:00
2014-01-16 16:08:50 -08:00
expect(startSpy.called).to.be.ok;
expect(onSpy.called).to.be.ok;
});
2014-01-16 08:01:10 -08:00
});
2014-01-15 07:53:44 -08:00
});