tests
This commit is contained in:
parent
14cb044990
commit
e308fd6f92
2 changed files with 77 additions and 4 deletions
|
|
@ -317,13 +317,15 @@ Identity.prototype.remove = function(opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
// HACK (isocolsky): remove notifications while deleting wallets
|
|
||||||
self.removeAllListeners('deletedWallet');
|
|
||||||
|
|
||||||
async.each(_.values(self.wallets), function(w, cb) {
|
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) {
|
}, function (err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
self.storage.removeItem(self.getId(), function(err) {
|
self.storage.removeItem(self.getId(), function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
self.emitAndKeepAlive('closed');
|
self.emitAndKeepAlive('closed');
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
describe.skip('#storeWallet', function() {
|
||||||
// TODO test storeWallet
|
// TODO test storeWallet
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue