From 710c9c965765ed2e747264727567c668a61ad16b Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 17 Jun 2014 14:02:39 -0300 Subject: [PATCH] fix tests --- js/models/core/WalletFactory.js | 6 ++-- package.json | 3 +- test/mocks/FakeStorage.js | 5 +++ test/test.WalletFactory.js | 59 ++++++++++++++++++++------------- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index c55ab059a..490b1b6a6 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -19,9 +19,9 @@ function WalletFactory(config, version) { var self = this; config = config || {}; - this.storage = new Storage(config.storage); - this.network = new Network(config.network); - this.blockchain = new Blockchain(config.blockchain); + this.storage = config.storageObj || new Storage(config.storage); + this.network = config.networkObj || new Network(config.network); + this.blockchain = config.blockchainObj || new Blockchain(config.blockchain); this.networkName = config.networkName; this.verbose = config.verbose; diff --git a/package.json b/package.json index d8871d000..626a0d965 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "cli-color": "0.3.2" }, "dependencies": { - "mocha": "^1.18.2" + "mocha": "^1.18.2", + "mocha-lcov-reporter": "0.0.1" } } diff --git a/test/mocks/FakeStorage.js b/test/mocks/FakeStorage.js index 73b6f92c2..9ea94c1b0 100644 --- a/test/mocks/FakeStorage.js +++ b/test/mocks/FakeStorage.js @@ -1,4 +1,9 @@ var FakeStorage = function() { + this.reset(); +}; + + +FakeStorage.prototype.reset = function(password) { this.storage = {}; }; diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js index 2944c25de..23beca06c 100644 --- a/test/test.WalletFactory.js +++ b/test/test.WalletFactory.js @@ -3,28 +3,14 @@ var chai = chai || require('chai'); var should = chai.should(); +var copay = copay || require('../copay'); +var sinon = require('sinon'); var FakeNetwork = require('./mocks/FakeNetwork'); -var Insight = require('../js/models/blockchain/Insight'); +var FakeBlockchain = require('./mocks/FakeBlockchain'); var FakeStorage = require('./mocks/FakeStorage'); +var WalletFactory = require('../js/models/core/WalletFactory'); -var WalletFactory = typeof copay === 'undefined' ? require('soop').load('../js/models/core/WalletFactory', { - Network: FakeNetwork, - Blockchain: Insight, - Storage: FakeStorage, -}) : copay.WalletFactory; - -var blanket = require("blanket")({ - "pattern": "/js/" -}); - - -var addCopayers = function(w) { - for (var i = 0; i < 4; i++) { - w.publicKeyRing.addCopayer(); - } -}; - -describe('WalletFactory model', function() { +describe.only('WalletFactory model', function() { var config = { wallet: { requiredCopayers: 3, @@ -38,12 +24,34 @@ describe('WalletFactory model', function() { }, networkName: 'testnet', passphrase: 'test', + storageObj: new FakeStorage(), + networkObj: new FakeNetwork(), + blockchainObj: new FakeBlockchain(), }; - it('should create the factory', function() { - var wf = new WalletFactory(config); - should.exist(wf); + beforeEach(function() { + config.storageObj.reset(); }); + + it('should create the factory', function() { + var wf = new WalletFactory(config, '0.0.1'); + should.exist(wf); + wf.networkName.should.equal(config.networkName); + wf.walletDefaults.should.deep.equal(config.wallet); + wf.version.should.equal('0.0.1'); + }); + + it('should log', function() { + var c2 = JSON.parse(JSON.stringify(config)); + c2.verbose = 1; + var wf = new WalletFactory(c2, '0.0.1'); + var spy = sinon.spy(console, 'log'); + wf.log('ok'); + sinon.assert.callCount(spy, 1); + spy.getCall(0).args[0].should.equal('ok'); + }); + + it('#_checkRead should return false', function() { var wf = new WalletFactory(config); wf._checkRead('dummy').should.equal(false); @@ -111,7 +119,10 @@ describe('WalletFactory model', function() { "port": 3001 }, "verbose": 0, - "themes": ["default"] + "themes": ["default"], + storageObj: new FakeStorage(), + networkObj: new FakeNetwork(), + blockchainObj: new FakeBlockchain(), }; var wf = new WalletFactory(sconfig, '0.0.1'); var opts = { @@ -124,6 +135,8 @@ describe('WalletFactory model', function() { it('should be able to get current wallets', function() { var wf = new WalletFactory(config, '0.0.1'); + var ws = wf.getWallets(); + var w = wf.create({ name: 'test wallet' });