From f7c1e3d4abdedf3623e9ac791372d1a00ab4da04 Mon Sep 17 00:00:00 2001 From: Matias Pando Date: Wed, 7 Jan 2015 18:25:36 -0300 Subject: [PATCH] Adding test for Identity --- test/Identity.js | 42 +++++++++++++++++++++++++++++++++++++++++- test/PublicKeyRing.js | 4 ++++ test/Wallet.js | 6 ++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/test/Identity.js b/test/Identity.js index 43b266b9a..6744238ee 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -672,7 +672,7 @@ describe('Identity model', function() { describe('add / delete / list Wallets', function() { - var iden, w; + var iden, w, w2; beforeEach(function() { var storage = sinon.stub(); storage.setCredentials = sinon.stub(); @@ -699,6 +699,12 @@ describe('Identity model', function() { getName: sinon.stub().returns('treintaydos'), close: sinon.stub(), }; + + w2 = { + getId: sinon.stub().returns('33'), + getName: sinon.stub().returns('treintaytres'), + close: sinon.stub(), + }; }); it('should add wallet', function() { @@ -710,6 +716,40 @@ describe('Identity model', function() { return w.getName() == 'treintaydos'; }).should.deep.equal(w); + iden.addWallet(w2); + iden.getWalletById('33').getName().should.equal('treintaytres'); + iden.walletIds.should.deep.equal(['32', '33']); + + }); + + it('should read and bind wallet', function(done) { + iden.addWallet(w); + iden.storage.getItem = sinon.stub().yields(w, JSON.stringify(iden)); + iden.readAndBindWallet('32', function(err) { + iden.getWalletById('32').getName().should.equal('treintaydos'); + done(); + }); + }); + + + it('should open wallet', function() { + iden.addWallet(w); + iden.storage.getItem = sinon.stub().yields(w, JSON.stringify(iden)); + iden.readAndBindWallet = sinon.spy(); + iden.openWallets(); + iden.readAndBindWallet.should.calledOnce; + + }); + + it('should open wallets', function() { + iden.addWallet(w); + iden.addWallet(w2); + iden.storage.getItem = sinon.stub().yields(w, JSON.stringify(iden)); + iden.readAndBindWallet = sinon.spy(); + iden.openWallets(); + iden.walletIds.should.deep.equal(['32', '33']); + iden.readAndBindWallet.callCount.should.be.equal(1); + }); it('should not add same wallet twice', function() { diff --git a/test/PublicKeyRing.js b/test/PublicKeyRing.js index 40eef5daf..d6ee15443 100644 --- a/test/PublicKeyRing.js +++ b/test/PublicKeyRing.js @@ -548,6 +548,10 @@ describe('PublicKeyRing model', function() { ret.pubKeys[1].length.should.equal(5); }); + it('#myCopayerId should return first copayerId ', function() { + var w = getCachedW().w; + w.myCopayerId().should.be.equal(w.getCopayerId(0)); + }); }); diff --git a/test/Wallet.js b/test/Wallet.js index bd500ad2f..c29d2f44d 100644 --- a/test/Wallet.js +++ b/test/Wallet.js @@ -382,9 +382,11 @@ describe('Wallet model', function() { wallet.addressIsOwn('mmHqhvTVbxgJTnePa7cfweSRjBCy9bQQXJ').should.equal(false); wallet.addressIsOwn('mgtUfP9sTJ6vPLoBxZLPEccGpcjNVryaCX').should.equal(false); + }); - - allAddresses = wallet.getAddressesOrdered(); + it('#getAddressesOrdered', function() { + var wallet = cachedCreateW2(); + var allAddresses = wallet.getAddressesOrdered(); for (var i = 0; i < allAddresses.length; i++) { wallet.addressIsOwn(allAddresses[i]).should.equal(true); }