From afb6574217a0fed028cf1d98f92840bfde326fb5 Mon Sep 17 00:00:00 2001 From: Matias Pando Date: Thu, 8 Jan 2015 16:48:12 -0300 Subject: [PATCH] Adding Identity close test --- js/models/Identity.js | 3 ++- test/Identity.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/js/models/Identity.js b/js/models/Identity.js index 289f205bf..eb35749c7 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -461,6 +461,7 @@ Identity.prototype._cleanUp = function() { * @desc Closes the wallet and disconnects all services */ Identity.prototype.close = function(cb) { + console.log('close!!!!!'); var self = this; function doClose() { @@ -507,7 +508,7 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) { log.debug('Updating Indexes for wallet:' + w.getName()); w.updateIndexes(function(err) { log.debug('Adding wallet to profile:' + w.getName()); - self.storeWallet(w, function (err) { + self.storeWallet(w, function(err) { if (err) return cb(err); self.addWallet(w); diff --git a/test/Identity.js b/test/Identity.js index 6744238ee..72a1c38f5 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -179,6 +179,36 @@ describe('Identity model', function() { }); }); + describe('#close', function(done) { + it('should store profile', function(done) { + var iden = new Identity(getDefaultParams()); + sinon.spy(iden, 'emitAndKeepAlive'); + sinon.spy(iden, '_cleanUp'); + iden.verifyChecksum = sinon.stub().yields(null, true); + iden.close(function() { + iden._cleanUp.calledOnce.should.be.true; + iden.emitAndKeepAlive.calledOnce.should.be.true; + iden.emitAndKeepAlive.getCall(0).args[0].should.equal('closed'); + iden.store.calledOnce.should.be.true; + iden.store.getCall(0).args[0].noWallets.should.equal(true); + done(); + }); + }); + it('should not store profile', function(done) { + var iden = new Identity(getDefaultParams()); + sinon.spy(iden, 'emitAndKeepAlive'); + sinon.spy(iden, '_cleanUp'); + iden.verifyChecksum = sinon.stub().yields(null, false); + iden.close(function() { + iden._cleanUp.calledOnce.should.be.true; + iden.emitAndKeepAlive.calledOnce.should.be.true; + iden.emitAndKeepAlive.getCall(0).args[0].should.equal('closed'); + iden.store.calledOnce.should.be.false; + done(); + }); + }); + }); + describe('#remove', function(done) { it('should remove empty profile', function(done) { var storage = sinon.stub();