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-03-10 11:06:10 -07:00
|
|
|
var PeerSync = require('../../lib/PeerSync.js');
|
2014-01-16 11:12:32 -08:00
|
|
|
describe('PeerSync', function() {
|
2014-01-16 11:43:37 -08:00
|
|
|
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-17 22:40:55 -08:00
|
|
|
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-16 11:43:37 -08:00
|
|
|
|
|
|
|
|
2014-02-11 11:03:46 -08:00
|
|
|
describe('#handleInv()', function() {
|
2014-01-16 11:43:37 -08:00
|
|
|
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 11:43:37 -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
|
|
|
});
|