refactor lock warning and add tests

This commit is contained in:
Matias Alejo Garcia 2014-08-12 15:26:15 -04:00
commit 35ab711846
13 changed files with 632 additions and 557 deletions

View file

@ -27,16 +27,16 @@ FakeStorage.prototype.getLastOpened = function() {
return this.storage['lastOpened'];
};
FakeStorage.prototype.setIsOpen = function(id) {
this.storage[id + '::isOpen'] = true;
FakeStorage.prototype.setLock = function(id) {
this.storage[id + '::lock'] = true;
}
FakeStorage.prototype.getIsOpen = function(id) {
return this.storage[id + '::isOpen'];
FakeStorage.prototype.getLock = function(id) {
return this.storage[id + '::lock'];
}
FakeStorage.prototype.removeIsOpen = function(id) {
delete this[id + '::isOpen'];
FakeStorage.prototype.removeLock = function(id) {
delete this.storage[id + '::lock'];
}
FakeStorage.prototype.removeGlobal = function(id) {

View file

@ -181,6 +181,7 @@ describe('Wallet model', function() {
cachedW2obj.opts.reconnectDelay = 100;
}
var w = Wallet.fromObj(cachedW2obj, cachedW2.storage, cachedW2.network, cachedW2.blockchain);
w.unlock();
return w;
};
@ -1024,11 +1025,34 @@ describe('Wallet model', function() {
});
it('should check if wallet is already opened', function() {
var w = createW();
w._checkLocked();
w.isLocked.should.equal(false);
w._checkLocked();
w.isLocked.should.equal(true);
var w = cachedCreateW2();
should.not.exist(w.getLock());
w.checkAndLock().should.equal(false);
w.getLock().should.equal(true);
});
it('should check if wallet is already opened', function() {
var w = cachedCreateW2();
should.not.exist(w.getLock());
w.checkAndLock().should.equal(false);
w.getLock().should.equal(true);
});
it('should not start if locked', function() {
var w = cachedCreateW2();
w.netStart();
w.emit = sinon.spy();
w.netStart();
w.emit.getCall(0).args[0].should.equal('locked');
});
it('should accept ignoreLocked', function() {
var w = cachedCreateW2();
w.netStart();
w.network.start = sinon.spy();
w.ignoreLock=1;
w.netStart();
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
});
});

View file

@ -160,16 +160,16 @@ describe('Storage/LocalEncrypted model', function() {
});
});
describe('#WalletIsOpened', function() {
describe('#WalletLock', function() {
it('should get/set/remove opened', function() {
var s = new LocalEncrypted({
localStorage: localMock,
password: 'password'
});
s.setIsOpen('walletId');
s.getIsOpen('walletId').should.equal(true);
s.removeIsOpen('walletId');
should.not.exist(s.getIsOpen('walletId'));
s.setLock('walletId');
s.getLock('walletId').should.equal(true);
s.removeLock('walletId');
should.not.exist(s.getLock('walletId'));
});
});

View file

@ -225,15 +225,15 @@ describe("Unit: Controllers", function() {
beforeEach(inject(function($controller, $injector) {
$httpBackend = $injector.get('$httpBackend');
$httpBackend.when('GET', GH)
.respond([{
name: "v100.1.6",
zipball_url: "https://api.github.com/repos/bitpay/copay/zipball/v0.0.6",
tarball_url: "https://api.github.com/repos/bitpay/copay/tarball/v0.0.6",
commit: {
sha: "ead7352bf2eca705de58d8b2f46650691f2bc2c7",
url: "https://api.github.com/repos/bitpay/copay/commits/ead7352bf2eca705de58d8b2f46650691f2bc2c7"
}
}]);
.respond([{
name: "v100.1.6",
zipball_url: "https://api.github.com/repos/bitpay/copay/zipball/v0.0.6",
tarball_url: "https://api.github.com/repos/bitpay/copay/tarball/v0.0.6",
commit: {
sha: "ead7352bf2eca705de58d8b2f46650691f2bc2c7",
url: "https://api.github.com/repos/bitpay/copay/commits/ead7352bf2eca705de58d8b2f46650691f2bc2c7"
}
}]);
}));
var rootScope;
@ -303,11 +303,6 @@ describe("Unit: Controllers", function() {
expect(array.length).equal(n);
});
it('should ignore if wallet is locked', function() {
scope.ignoreLocked();
expect(rootScope.wallet.isLocked).equal(false);
});
});
describe('Send Controller', function() {
@ -428,4 +423,18 @@ describe("Unit: Controllers", function() {
});
});
describe('Warning Controller', function() {
var what;
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
what = $controller('WarningController', {
$scope: scope,
});
}));
it('should exist', function() {
should.exist(what);
});
});
});