From 9ff7f4e10abb20b8963fba22333e272e17e612b8 Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Tue, 11 Mar 2014 18:27:02 +0100 Subject: [PATCH] cover corner case when emailAdress is undefined --- src/js/app-controller.js | 6 +++++- test/new-unit/app-controller-test.js | 24 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/js/app-controller.js b/src/js/app-controller.js index a40c1cd..aac37f3 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -362,7 +362,11 @@ define(function(require) { self.buildModules(); // init user's local database - self._userStorage.init(options.emailAddress, function() { + self._userStorage.init(options.emailAddress, function(err) { + if (err) { + callback(err); + return; + } // Migrate the databases if necessary self._updateHandler.update(onUpdate); diff --git a/test/new-unit/app-controller-test.js b/test/new-unit/app-controller-test.js index 4214299..c23754b 100644 --- a/test/new-unit/app-controller-test.js +++ b/test/new-unit/app-controller-test.js @@ -243,11 +243,25 @@ define(function(require) { onConnectStub.restore(); }); + it('should fail due to error in storage initialization', function(done) { + devicestorageStub.init.withArgs(undefined).yields({}); + + controller.init({}, function(err, keypair) { + expect(err).to.exist; + expect(keypair).to.not.exist; + expect(devicestorageStub.init.calledOnce).to.be.true; + expect(updateHandlerStub.update.calledOnce).to.be.false; + done(); + }); + }); + it('should fail due to error in update handler', function(done) { devicestorageStub.init.yields(); updateHandlerStub.update.yields({}); - controller.init({}, function(err, keypair) { + controller.init({ + emailAddress: emailAddress + }, function(err, keypair) { expect(err).to.exist; expect(keypair).to.not.exist; expect(updateHandlerStub.update.calledOnce).to.be.true; @@ -261,7 +275,9 @@ define(function(require) { updateHandlerStub.update.yields(); emailDaoStub.init.yields({}); - controller.init({}, function(err, keypair) { + controller.init({ + emailAddress: emailAddress + }, function(err, keypair) { expect(err).to.exist; expect(keypair).to.not.exist; expect(updateHandlerStub.update.calledOnce).to.be.true; @@ -278,7 +294,9 @@ define(function(require) { onConnectStub.yields({}); - controller.init({}, function(err) { + controller.init({ + emailAddress: emailAddress + }, function(err) { expect(err).to.exist; expect(updateHandlerStub.update.calledOnce).to.be.true; expect(emailDaoStub.init.calledOnce).to.be.true;