diff --git a/js/models/Identity.js b/js/models/Identity.js index 0f9fcdad7..5c2c9a2a1 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -317,13 +317,15 @@ Identity.prototype.remove = function(opts, cb) { var self = this; opts = opts || {}; - // HACK (isocolsky): remove notifications while deleting wallets - self.removeAllListeners('deletedWallet'); - async.each(_.values(self.wallets), function(w, cb) { - self.deleteWallet(w.getId(), cb); + w.close(); + self.storage.removeItem(Wallet.getStorageKey(w.getId()), function(err) { + if (err) return cb(err); + cb(); + }); }, function (err) { if (err) return cb(err); + self.storage.removeItem(self.getId(), function(err) { if (err) return cb(err); self.emitAndKeepAlive('closed'); diff --git a/test/Identity.js b/test/Identity.js index 0e939f916..f3fa2dfd3 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -158,6 +158,77 @@ describe('Identity model', function() { }); }); + describe('#remove', function(done) { + it('should remove empty profile', function (done) { + var storage = sinon.stub(); + storage.setCredentials = sinon.stub(); + storage.removeItem = sinon.stub().yields(null); + + var opts = { + email: 'test@test.com', + password: '123', + network: { + testnet: { + url: 'https://test-insight.bitpay.com:443' + }, + livenet: { + url: 'https://insight.bitpay.com:443' + }, + }, + storage: storage, + }; + + var iden = new Identity(opts); + iden.remove(null, function (err, res) { + should.not.exist(err); + storage.removeItem.calledOnce.should.be.true; + storage.removeItem.getCall(0).args[0].should.equal(iden.getId()); + done(); + }); + }); + + it('should remove profile and wallets', function(done) { + var storage = sinon.stub(); + storage.setCredentials = sinon.stub(); + storage.removeItem = sinon.stub().yields(null); + + var opts = { + email: 'test@test.com', + password: '123', + network: { + testnet: { + url: 'https://test-insight.bitpay.com:443' + }, + livenet: { + url: 'https://insight.bitpay.com:443' + }, + }, + storage: storage, + }; + + var iden = new Identity(opts); + + _.each(_.range(3), function(i) { + var w = { + on: sinon.stub().yields(null), + getId: sinon.stub().returns('wallet' + i), + getName: sinon.stub().returns('wallet' + i), + close: sinon.stub(), + }; + iden.bindWallet(w); + }); + + iden.remove(null, function(err, res) { + should.not.exist(err); + storage.removeItem.callCount.should.equal(4); + storage.removeItem.getCall(0).args[0].should.equal(Wallet.getStorageKey('wallet0')); + storage.removeItem.getCall(3).args[0].should.equal(iden.getId()); + done(); + }); + + }); + }); + describe.skip('#storeWallet', function() { // TODO test storeWallet });