Save last opened wallet

This commit is contained in:
Yemel Jardi 2014-08-04 15:10:01 -03:00
commit 9b1708b88e
6 changed files with 62 additions and 1 deletions

View file

@ -19,6 +19,13 @@ FakeStorage.prototype.getGlobal = function(id) {
return this.storage[id];
};
FakeStorage.prototype.setLastOpened = function(val) {
this.storage['lastOpened'] = val;
};
FakeStorage.prototype.getLastOpened = function() {
return this.storage['lastOpened'];
};
FakeStorage.prototype.removeGlobal = function(id) {
delete this.storage[id];

View file

@ -317,6 +317,20 @@ describe('WalletFactory model', function() {
});
});
it('should clean lastOpened on delete wallet', function(done) {
var wf = new WalletFactory(config, '0.0.1');
var w = wf.create({
name: 'test wallet'
});
wf.storage.setLastOpened(w.id);
wf.delete(w.id, function() {
var last = wf.storage.getLastOpened();
should.equal(last, undefined);
done();
});
});
it('should return false if wallet does not exist', function() {
var opts = {
'requiredCopayers': 2,
@ -343,6 +357,23 @@ describe('WalletFactory model', function() {
wf.read.calledWith(walletId).should.be.true;
});
it('should save lastOpened on create/open a wallet', function() {
var opts = {
'requiredCopayers': 2,
'totalCopayers': 3
};
var wf = new WalletFactory(config, '0.0.1');
var w = wf.create(opts);
var last = wf.storage.getLastOpened();
should.equal(last, w.id);
wf.storage.setLastOpened('other_id');
var wo = wf.open(w.id, opts);
last = wf.storage.getLastOpened();
should.equal(last, w.id);
});
it('should return error if network are differents', function() {
var opts = {
'requiredCopayers': 2,

View file

@ -148,6 +148,18 @@ describe('Storage/LocalEncrypted model', function() {
s.getName(1).should.equal('hola');
});
});
describe('#getLastOpened #setLastOpened', function() {
it('should get/set names', function() {
var s = new LocalEncrypted({
localStorage: localMock,
password: 'password'
});
s.setLastOpened('hey');
s.getLastOpened().should.equal('hey');
});
});
describe('#getWallets', function() {
it('should retreive wallets from storage', function() {
var s = new LocalEncrypted({