Refactor controllers

This commit is contained in:
Yemel Jardi 2014-08-28 15:18:05 -03:00
commit 16091bd330
9 changed files with 50 additions and 47 deletions

View file

@ -6,6 +6,10 @@ function FakeBlockchain(opts) {
opts = opts || {};
}
FakeBlockchain.prototype.getTransaction = function(txid, cb) {
return cb(null, {txid: txid});
};
FakeBlockchain.prototype.getTransactions = function(addresses, cb) {
return cb(null, []);
};

View file

@ -752,7 +752,7 @@ describe('Wallet model', function() {
var utxo = createUTXO(w);
w.blockchain.fixUnspent(utxo);
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
sinon.stub(w.blockchain, 'sendRawTransaction').yields(undefined);
sinon.stub(w.blockchain, 'broadcast').yields({statusCode: 303});
var spyCheckSentTx = sinon.spy(w, '_checkSentTx');
w.sendTx(ntxid, function () {});
chai.expect(spyCheckSentTx.calledOnce).to.be.true;

View file

@ -98,6 +98,14 @@ describe('Insight model', function() {
emitSpy.calledWith('subscribe', 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
});
it('should subscribe to an address once', function() {
var blockchain = new Insight(FAKE_OPTS);
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
blockchain.subscribed.length.should.equal(1);
});
it('should subscribe to a list of addresses', function() {
var blockchain = new Insight(FAKE_OPTS);
var emitSpy = sinon.spy(blockchain.socket, 'emit');

View file

@ -62,26 +62,26 @@ describe("Unit: controllerUtils", function() {
expect($rootScope.unitName).to.be.equal('bits');
});
}));
describe("Unit: controllerUtils #setSocketHandlers", function() {
describe("Unit: controllerUtils #updateGlobalAddresses", function() {
it(' should call updateAddressList ', inject(function(controllerUtils, $rootScope) {
var spy = sinon.spy(controllerUtils, 'updateAddressList');
controllerUtils.setSocketHandlers();
controllerUtils.updateGlobalAddresses();
sinon.assert.callCount(spy, 1);
}));
it('should update addresses', inject(function(controllerUtils, $rootScope) {
$rootScope.wallet = new FakeWallet();
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
controllerUtils.setSocketHandlers();
controllerUtils.updateGlobalAddresses();
expect($rootScope.addrInfos[0].address).to.be.equal(Waddr);;
}));
it('should set System Event Handlers', inject(function(controllerUtils, $rootScope, Socket) {
var spy = sinon.spy(Socket, 'sysOn');
$rootScope.wallet = new FakeWallet();
controllerUtils.setSocketHandlers();
controllerUtils.updateGlobalAddresses();
sinon.assert.callCount(spy, 5);
['error', 'reconnect_error', 'reconnect_failed', 'connect', 'reconnect'].forEach(function(e) {
sinon.assert.calledWith(spy, e);
@ -92,7 +92,7 @@ describe("Unit: controllerUtils", function() {
var spy = sinon.spy(Socket, 'on');
$rootScope.wallet = new FakeWallet();
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
controllerUtils.setSocketHandlers();
controllerUtils.updateGlobalAddresses();
sinon.assert.calledWith(spy, Waddr);
}));
});