|
|
|
@ -26,17 +26,13 @@ describe('Login Controller unit test', function() {
@@ -26,17 +26,13 @@ describe('Login Controller unit test', function() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
authMock.emailAddress = emailAddress; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function createController() { |
|
|
|
|
angular.module('login-test', ['woServices', 'woEmail', 'woUtil']); |
|
|
|
|
angular.mock.module('login-test'); |
|
|
|
|
angular.mock.inject(function($rootScope, $controller) { |
|
|
|
|
scope = $rootScope.$new(); |
|
|
|
|
scope.state = {}; |
|
|
|
|
scope.form = {}; |
|
|
|
|
scope.goTo = function() {}; |
|
|
|
|
goToStub = sinon.stub(scope, 'goTo'); |
|
|
|
|
|
|
|
|
|
ctrl = $controller(LoginCtrl, { |
|
|
|
|
$scope: scope, |
|
|
|
@ -46,151 +42,167 @@ describe('Login Controller unit test', function() {
@@ -46,151 +42,167 @@ describe('Login Controller unit test', function() {
|
|
|
|
|
auth: authMock, |
|
|
|
|
email: emailMock, |
|
|
|
|
keychain: keychainMock, |
|
|
|
|
dialog: dialogMock |
|
|
|
|
dialog: dialogMock, |
|
|
|
|
appConfig: { |
|
|
|
|
preventAutoStart: true |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
afterEach(function() {}); |
|
|
|
|
scope.goTo = function() {}; |
|
|
|
|
goToStub = sinon.stub(scope, 'goTo'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should fail for auth.getEmailAddress', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(new Error()); |
|
|
|
|
afterEach(function() {}); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
it('should fail for auth.getEmailAddress', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(rejects(new Error())); |
|
|
|
|
|
|
|
|
|
expect(updateHandlerMock.checkForUpdate.calledOnce).to.be.true; |
|
|
|
|
expect(authMock.init.calledOnce).to.be.true; |
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(updateHandlerMock.checkForUpdate.calledOnce).to.be.true; |
|
|
|
|
expect(authMock.init.calledOnce).to.be.true; |
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should fail for auth.init', function() { |
|
|
|
|
authMock.init.yields(new Error()); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should fail for auth.init', function(done) { |
|
|
|
|
authMock.init.returns(rejects(new Error())); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
expect(authMock.init.calledOnce).to.be.true; |
|
|
|
|
expect(accountMock.init.called).to.be.false; |
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(authMock.init.calledOnce).to.be.true; |
|
|
|
|
expect(accountMock.init.called).to.be.false; |
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should redirect to /add-account', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, {}); |
|
|
|
|
it('should redirect to /add-account', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({})); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
|
|
|
|
|
expect(goToStub.withArgs('/add-account').calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(goToStub.withArgs('/add-account').calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should redirect to /login-existing', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should redirect to /login-existing', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
accountMock.init.yields(null, { |
|
|
|
|
})); |
|
|
|
|
accountMock.init.returns(resolves({ |
|
|
|
|
publicKey: 'publicKey', |
|
|
|
|
privateKey: 'privateKey' |
|
|
|
|
}); |
|
|
|
|
emailMock.unlock.yields(new Error()); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
})); |
|
|
|
|
emailMock.unlock.returns(rejects(new Error())); |
|
|
|
|
|
|
|
|
|
expect(goToStub.withArgs('/login-existing').calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(goToStub.withArgs('/login-existing').calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should fail for auth.storeCredentials', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should fail for auth.storeCredentials', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
accountMock.init.yields(null, { |
|
|
|
|
})); |
|
|
|
|
accountMock.init.returns(resolves({ |
|
|
|
|
publicKey: 'publicKey', |
|
|
|
|
privateKey: 'privateKey' |
|
|
|
|
}); |
|
|
|
|
emailMock.unlock.yields(); |
|
|
|
|
authMock.storeCredentials.yields(new Error()); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
})); |
|
|
|
|
emailMock.unlock.returns(resolves()); |
|
|
|
|
authMock.storeCredentials.returns(rejects(new Error())); |
|
|
|
|
|
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should redirect to /account', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should redirect to /account', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
accountMock.init.yields(null, { |
|
|
|
|
})); |
|
|
|
|
accountMock.init.returns(resolves({ |
|
|
|
|
publicKey: 'publicKey', |
|
|
|
|
privateKey: 'privateKey' |
|
|
|
|
}); |
|
|
|
|
emailMock.unlock.yields(); |
|
|
|
|
authMock.storeCredentials.yields(); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
})); |
|
|
|
|
emailMock.unlock.returns(resolves()); |
|
|
|
|
authMock.storeCredentials.returns(resolves()); |
|
|
|
|
|
|
|
|
|
expect(goToStub.withArgs('/account').calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(goToStub.withArgs('/account').calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should fail for keychain.requestPrivateKeyDownload', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should fail for keychain.requestPrivateKeyDownload', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
accountMock.init.yields(null, { |
|
|
|
|
})); |
|
|
|
|
accountMock.init.returns(resolves({ |
|
|
|
|
publicKey: 'publicKey' |
|
|
|
|
}); |
|
|
|
|
keychainMock.requestPrivateKeyDownload.yields(new Error()); |
|
|
|
|
})); |
|
|
|
|
keychainMock.requestPrivateKeyDownload.returns(rejects(new Error())); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
|
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should redirect to /login-privatekey-download', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should redirect to /login-privatekey-download', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
accountMock.init.yields(null, { |
|
|
|
|
})); |
|
|
|
|
accountMock.init.returns(resolves({ |
|
|
|
|
publicKey: 'publicKey' |
|
|
|
|
}); |
|
|
|
|
keychainMock.requestPrivateKeyDownload.yields(null, true); |
|
|
|
|
})); |
|
|
|
|
keychainMock.requestPrivateKeyDownload.returns(resolves(true)); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
|
|
|
|
|
expect(goToStub.withArgs('/login-privatekey-download').calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(goToStub.withArgs('/login-privatekey-download').calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should redirect to /login-new-device', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should redirect to /login-new-device', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
accountMock.init.yields(null, { |
|
|
|
|
})); |
|
|
|
|
accountMock.init.returns(resolves({ |
|
|
|
|
publicKey: 'publicKey' |
|
|
|
|
}); |
|
|
|
|
keychainMock.requestPrivateKeyDownload.yields(); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
})); |
|
|
|
|
keychainMock.requestPrivateKeyDownload.returns(resolves()); |
|
|
|
|
|
|
|
|
|
expect(goToStub.withArgs('/login-new-device').calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(goToStub.withArgs('/login-new-device').calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should redirect to /login-initial', function() { |
|
|
|
|
authMock.init.yields(); |
|
|
|
|
authMock.getEmailAddress.yields(null, { |
|
|
|
|
it('should redirect to /login-initial', function(done) { |
|
|
|
|
authMock.init.returns(resolves()); |
|
|
|
|
authMock.getEmailAddress.returns(resolves({ |
|
|
|
|
emailAddress: emailAddress |
|
|
|
|
}); |
|
|
|
|
accountMock.init.yields(null, {}); |
|
|
|
|
})); |
|
|
|
|
accountMock.init.returns(resolves({})); |
|
|
|
|
|
|
|
|
|
createController(); |
|
|
|
|
|
|
|
|
|
expect(goToStub.withArgs('/login-initial').calledOnce).to.be.true; |
|
|
|
|
scope.init().then(function() { |
|
|
|
|
expect(goToStub.withArgs('/login-initial').calledOnce).to.be.true; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}); |