This commit is contained in:
Ivan Socolsky 2014-12-01 15:37:28 -03:00
parent 14cb044990
commit e308fd6f92
2 changed files with 77 additions and 4 deletions

View File

@ -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');

View File

@ -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
});