mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 10:22:18 -05:00
Begin conrtoller unit tests
This commit is contained in:
parent
eab07041f0
commit
6beddf4760
@ -51,7 +51,7 @@ var AddAccountCtrl = function($scope, $location, $routeParams, $timeout, $q, mai
|
|||||||
callback: function(granted) {
|
callback: function(granted) {
|
||||||
if (granted) {
|
if (granted) {
|
||||||
// query oauth token
|
// query oauth token
|
||||||
getOAuthToken();
|
return getOAuthToken();
|
||||||
} else {
|
} else {
|
||||||
// use normal user/password login
|
// use normal user/password login
|
||||||
$scope.setCredentials();
|
$scope.setCredentials();
|
||||||
@ -61,7 +61,7 @@ var AddAccountCtrl = function($scope, $location, $routeParams, $timeout, $q, mai
|
|||||||
|
|
||||||
function getOAuthToken() {
|
function getOAuthToken() {
|
||||||
// fetches the email address from the chrome identity api
|
// fetches the email address from the chrome identity api
|
||||||
auth.getOAuthToken().then(function() {
|
return auth.getOAuthToken().then(function() {
|
||||||
// continue to setting credentials
|
// continue to setting credentials
|
||||||
return $scope.setCredentials();
|
return $scope.setCredentials();
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, auth, email, keychain, dialog) {
|
var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, auth, email, keychain, dialog, appConfig) {
|
||||||
|
|
||||||
// check for app update
|
//
|
||||||
updateHandler.checkForUpdate();
|
// Scope functions
|
||||||
|
//
|
||||||
|
|
||||||
|
$scope.init = function() {
|
||||||
// initialize the user account
|
// initialize the user account
|
||||||
auth.init().then(function() {
|
return auth.init().then(function() {
|
||||||
// get email address
|
// get email address
|
||||||
return auth.getEmailAddress();
|
return auth.getEmailAddress();
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
|
|||||||
});
|
});
|
||||||
|
|
||||||
}).catch(dialog.error);
|
}).catch(dialog.error);
|
||||||
|
};
|
||||||
|
|
||||||
function redirect(availableKeys) {
|
function redirect(availableKeys) {
|
||||||
if (availableKeys && availableKeys.publicKey && availableKeys.privateKey) {
|
if (availableKeys && availableKeys.publicKey && availableKeys.privateKey) {
|
||||||
@ -32,15 +35,16 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
|
|||||||
return email.unlock({
|
return email.unlock({
|
||||||
keypair: availableKeys,
|
keypair: availableKeys,
|
||||||
passphrase: undefined
|
passphrase: undefined
|
||||||
}).then(function() {
|
|
||||||
// no passphrase set... go to main screen
|
|
||||||
return auth.storeCredentials().then(function() {
|
|
||||||
return $scope.goTo('/account');
|
|
||||||
});
|
|
||||||
|
|
||||||
}).catch(function() {
|
}).catch(function() {
|
||||||
// passphrase set... ask for passphrase
|
// passphrase set... ask for passphrase
|
||||||
return $scope.goTo('/login-existing');
|
return $scope.goTo('/login-existing');
|
||||||
|
|
||||||
|
}).then(function() {
|
||||||
|
// no passphrase set... go to main screen
|
||||||
|
return auth.storeCredentials();
|
||||||
|
|
||||||
|
}).then(function() {
|
||||||
|
return $scope.goTo('/account');
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (availableKeys && availableKeys.publicKey && !availableKeys.privateKey) {
|
} else if (availableKeys && availableKeys.publicKey && !availableKeys.privateKey) {
|
||||||
@ -69,6 +73,19 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
|
|||||||
$location.path(location);
|
$location.path(location);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start the app
|
||||||
|
//
|
||||||
|
|
||||||
|
// check for app update
|
||||||
|
updateHandler.checkForUpdate();
|
||||||
|
|
||||||
|
// init the app
|
||||||
|
if (!appConfig.preventAutoStart) {
|
||||||
|
$scope.init();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = LoginCtrl;
|
module.exports = LoginCtrl;
|
@ -49,6 +49,10 @@ require('../src/js/email');
|
|||||||
// Global mocks
|
// Global mocks
|
||||||
//
|
//
|
||||||
|
|
||||||
|
window.qMock = function(res, rej) {
|
||||||
|
return new Promise(res, rej);
|
||||||
|
};
|
||||||
|
|
||||||
window.resolves = function(val) {
|
window.resolves = function(val) {
|
||||||
return new Promise(function(res) {
|
return new Promise(function(res) {
|
||||||
res(val);
|
res(val);
|
||||||
|
@ -116,16 +116,17 @@ describe('Add Account Controller unit test', function() {
|
|||||||
setCredentialsStub.restore();
|
setCredentialsStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use oauth', function() {
|
it('should use oauth', function(done) {
|
||||||
dialogStub.confirm = function(options) {
|
dialogStub.confirm = function(options) {
|
||||||
options.callback(true);
|
options.callback(true).then(function() {
|
||||||
};
|
|
||||||
authStub.getOAuthToken.yields();
|
|
||||||
|
|
||||||
scope.oauthPossible();
|
|
||||||
|
|
||||||
expect(setCredentialsStub.calledOnce).to.be.true;
|
expect(setCredentialsStub.calledOnce).to.be.true;
|
||||||
expect(authStub.getOAuthToken.calledOnce).to.be.true;
|
expect(authStub.getOAuthToken.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
authStub.getOAuthToken.returns(resolves());
|
||||||
|
|
||||||
|
scope.oauthPossible();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not use oauth', function() {
|
it('should not use oauth', function() {
|
||||||
@ -139,25 +140,29 @@ describe('Add Account Controller unit test', function() {
|
|||||||
expect(authStub.getOAuthToken.called).to.be.false;
|
expect(authStub.getOAuthToken.called).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not forward to login when oauth fails', function() {
|
it('should not forward to login when oauth fails', function(done) {
|
||||||
|
dialogStub.error = function(err) {
|
||||||
|
expect(err).to.exist;
|
||||||
|
expect(setCredentialsStub.called).to.be.false;
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
dialogStub.confirm = function(options) {
|
dialogStub.confirm = function(options) {
|
||||||
options.callback(true);
|
options.callback(true);
|
||||||
};
|
};
|
||||||
authStub.getOAuthToken.yields(new Error());
|
authStub.getOAuthToken.returns(rejects(new Error()));
|
||||||
|
|
||||||
scope.oauthPossible();
|
scope.oauthPossible();
|
||||||
|
|
||||||
expect(dialogStub.error.calledOnce).to.be.true;
|
|
||||||
expect(setCredentialsStub.called).to.be.false;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setCredentials', function() {
|
describe('setCredentials', function() {
|
||||||
it('should work', function() {
|
it('should work', inject(function($timeout) {
|
||||||
scope.setCredentials();
|
scope.setCredentials().then();
|
||||||
|
$timeout.flush();
|
||||||
|
|
||||||
expect(location.path.calledWith('/login-set-credentials')).to.be.true;
|
expect(location.path.calledWith('/login-set-credentials')).to.be.true;
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -29,6 +29,7 @@ describe('Create Account Controller unit test', function() {
|
|||||||
$location: location,
|
$location: location,
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
$routeParams: {},
|
$routeParams: {},
|
||||||
|
$q: window.qMock,
|
||||||
auth: authStub,
|
auth: authStub,
|
||||||
admin: adminStub
|
admin: adminStub
|
||||||
});
|
});
|
||||||
@ -54,16 +55,15 @@ describe('Create Account Controller unit test', function() {
|
|||||||
scope.form.$invalid = false;
|
scope.form.$invalid = false;
|
||||||
scope.betaCode = 'asfd';
|
scope.betaCode = 'asfd';
|
||||||
scope.phone = '12345';
|
scope.phone = '12345';
|
||||||
adminStub.createUser.yieldsAsync(new Error('asdf'));
|
adminStub.createUser.returns(rejects(new Error('asdf')));
|
||||||
|
|
||||||
scope.$apply = function() {
|
scope.createWhiteoutAccount().then(function() {
|
||||||
expect(scope.busy).to.be.false;
|
expect(scope.busy).to.be.false;
|
||||||
expect(scope.errMsg).to.equal('asdf');
|
expect(scope.errMsg).to.equal('asdf');
|
||||||
expect(adminStub.createUser.calledOnce).to.be.true;
|
expect(adminStub.createUser.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
};
|
});
|
||||||
|
|
||||||
scope.createWhiteoutAccount();
|
|
||||||
expect(scope.busy).to.be.true;
|
expect(scope.busy).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -71,16 +71,15 @@ describe('Create Account Controller unit test', function() {
|
|||||||
scope.form.$invalid = false;
|
scope.form.$invalid = false;
|
||||||
scope.betaCode = 'asfd';
|
scope.betaCode = 'asfd';
|
||||||
scope.phone = '12345';
|
scope.phone = '12345';
|
||||||
adminStub.createUser.yieldsAsync();
|
adminStub.createUser.returns(resolves());
|
||||||
|
|
||||||
scope.$apply = function() {
|
scope.createWhiteoutAccount().then(function() {
|
||||||
expect(scope.busy).to.be.false;
|
expect(scope.busy).to.be.false;
|
||||||
expect(scope.errMsg).to.be.undefined;
|
expect(scope.errMsg).to.be.undefined;
|
||||||
expect(adminStub.createUser.calledOnce).to.be.true;
|
expect(adminStub.createUser.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
};
|
});
|
||||||
|
|
||||||
scope.createWhiteoutAccount();
|
|
||||||
expect(scope.busy).to.be.true;
|
expect(scope.busy).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -26,17 +26,13 @@ describe('Login Controller unit test', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
authMock.emailAddress = emailAddress;
|
authMock.emailAddress = emailAddress;
|
||||||
});
|
|
||||||
|
|
||||||
function createController() {
|
|
||||||
angular.module('login-test', ['woServices', 'woEmail', 'woUtil']);
|
angular.module('login-test', ['woServices', 'woEmail', 'woUtil']);
|
||||||
angular.mock.module('login-test');
|
angular.mock.module('login-test');
|
||||||
angular.mock.inject(function($rootScope, $controller) {
|
angular.mock.inject(function($rootScope, $controller) {
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
scope.state = {};
|
scope.state = {};
|
||||||
scope.form = {};
|
scope.form = {};
|
||||||
scope.goTo = function() {};
|
|
||||||
goToStub = sinon.stub(scope, 'goTo');
|
|
||||||
|
|
||||||
ctrl = $controller(LoginCtrl, {
|
ctrl = $controller(LoginCtrl, {
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
@ -46,151 +42,167 @@ describe('Login Controller unit test', function() {
|
|||||||
auth: authMock,
|
auth: authMock,
|
||||||
email: emailMock,
|
email: emailMock,
|
||||||
keychain: keychainMock,
|
keychain: keychainMock,
|
||||||
dialog: dialogMock
|
dialog: dialogMock,
|
||||||
});
|
appConfig: {
|
||||||
});
|
preventAutoStart: true
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
scope.goTo = function() {};
|
||||||
|
goToStub = sinon.stub(scope, 'goTo');
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(function() {});
|
afterEach(function() {});
|
||||||
|
|
||||||
it('should fail for auth.getEmailAddress', function() {
|
it('should fail for auth.getEmailAddress', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(new Error());
|
authMock.getEmailAddress.returns(rejects(new Error()));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(updateHandlerMock.checkForUpdate.calledOnce).to.be.true;
|
expect(updateHandlerMock.checkForUpdate.calledOnce).to.be.true;
|
||||||
expect(authMock.init.calledOnce).to.be.true;
|
expect(authMock.init.calledOnce).to.be.true;
|
||||||
expect(dialogMock.error.calledOnce).to.be.true;
|
expect(dialogMock.error.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail for auth.init', function() {
|
it('should fail for auth.init', function(done) {
|
||||||
authMock.init.yields(new Error());
|
authMock.init.returns(rejects(new Error()));
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(authMock.init.calledOnce).to.be.true;
|
expect(authMock.init.calledOnce).to.be.true;
|
||||||
expect(accountMock.init.called).to.be.false;
|
expect(accountMock.init.called).to.be.false;
|
||||||
expect(dialogMock.error.calledOnce).to.be.true;
|
expect(dialogMock.error.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to /add-account', function() {
|
it('should redirect to /add-account', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {});
|
authMock.getEmailAddress.returns(resolves({}));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(goToStub.withArgs('/add-account').calledOnce).to.be.true;
|
expect(goToStub.withArgs('/add-account').calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to /login-existing', function() {
|
it('should redirect to /login-existing', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
accountMock.init.yields(null, {
|
accountMock.init.returns(resolves({
|
||||||
publicKey: 'publicKey',
|
publicKey: 'publicKey',
|
||||||
privateKey: 'privateKey'
|
privateKey: 'privateKey'
|
||||||
});
|
}));
|
||||||
emailMock.unlock.yields(new Error());
|
emailMock.unlock.returns(rejects(new Error()));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(goToStub.withArgs('/login-existing').calledOnce).to.be.true;
|
expect(goToStub.withArgs('/login-existing').calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail for auth.storeCredentials', function() {
|
it('should fail for auth.storeCredentials', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
accountMock.init.yields(null, {
|
accountMock.init.returns(resolves({
|
||||||
publicKey: 'publicKey',
|
publicKey: 'publicKey',
|
||||||
privateKey: 'privateKey'
|
privateKey: 'privateKey'
|
||||||
});
|
}));
|
||||||
emailMock.unlock.yields();
|
emailMock.unlock.returns(resolves());
|
||||||
authMock.storeCredentials.yields(new Error());
|
authMock.storeCredentials.returns(rejects(new Error()));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(dialogMock.error.calledOnce).to.be.true;
|
expect(dialogMock.error.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to /account', function() {
|
it('should redirect to /account', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
accountMock.init.yields(null, {
|
accountMock.init.returns(resolves({
|
||||||
publicKey: 'publicKey',
|
publicKey: 'publicKey',
|
||||||
privateKey: 'privateKey'
|
privateKey: 'privateKey'
|
||||||
});
|
}));
|
||||||
emailMock.unlock.yields();
|
emailMock.unlock.returns(resolves());
|
||||||
authMock.storeCredentials.yields();
|
authMock.storeCredentials.returns(resolves());
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(goToStub.withArgs('/account').calledOnce).to.be.true;
|
expect(goToStub.withArgs('/account').calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail for keychain.requestPrivateKeyDownload', function() {
|
it('should fail for keychain.requestPrivateKeyDownload', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
accountMock.init.yields(null, {
|
accountMock.init.returns(resolves({
|
||||||
publicKey: 'publicKey'
|
publicKey: 'publicKey'
|
||||||
});
|
}));
|
||||||
keychainMock.requestPrivateKeyDownload.yields(new Error());
|
keychainMock.requestPrivateKeyDownload.returns(rejects(new Error()));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(dialogMock.error.calledOnce).to.be.true;
|
expect(dialogMock.error.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to /login-privatekey-download', function() {
|
it('should redirect to /login-privatekey-download', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
accountMock.init.yields(null, {
|
accountMock.init.returns(resolves({
|
||||||
publicKey: 'publicKey'
|
publicKey: 'publicKey'
|
||||||
});
|
}));
|
||||||
keychainMock.requestPrivateKeyDownload.yields(null, true);
|
keychainMock.requestPrivateKeyDownload.returns(resolves(true));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(goToStub.withArgs('/login-privatekey-download').calledOnce).to.be.true;
|
expect(goToStub.withArgs('/login-privatekey-download').calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to /login-new-device', function() {
|
it('should redirect to /login-new-device', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
accountMock.init.yields(null, {
|
accountMock.init.returns(resolves({
|
||||||
publicKey: 'publicKey'
|
publicKey: 'publicKey'
|
||||||
});
|
}));
|
||||||
keychainMock.requestPrivateKeyDownload.yields();
|
keychainMock.requestPrivateKeyDownload.returns(resolves());
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(goToStub.withArgs('/login-new-device').calledOnce).to.be.true;
|
expect(goToStub.withArgs('/login-new-device').calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to /login-initial', function() {
|
it('should redirect to /login-initial', function(done) {
|
||||||
authMock.init.yields();
|
authMock.init.returns(resolves());
|
||||||
authMock.getEmailAddress.yields(null, {
|
authMock.getEmailAddress.returns(resolves({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
});
|
}));
|
||||||
accountMock.init.yields(null, {});
|
accountMock.init.returns(resolves({}));
|
||||||
|
|
||||||
createController();
|
|
||||||
|
|
||||||
|
scope.init().then(function() {
|
||||||
expect(goToStub.withArgs('/login-initial').calledOnce).to.be.true;
|
expect(goToStub.withArgs('/login-initial').calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -28,6 +28,7 @@ describe('Login (existing user) Controller unit test', function() {
|
|||||||
ctrl = $controller(LoginExistingCtrl, {
|
ctrl = $controller(LoginExistingCtrl, {
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
$routeParams: {},
|
$routeParams: {},
|
||||||
|
$q: window.qMock,
|
||||||
email: emailDaoMock,
|
email: emailDaoMock,
|
||||||
auth: authMock,
|
auth: authMock,
|
||||||
keychain: keychainMock
|
keychain: keychainMock
|
||||||
@ -44,32 +45,35 @@ describe('Login (existing user) Controller unit test', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('confirm passphrase', function() {
|
describe('confirm passphrase', function() {
|
||||||
it('should unlock crypto and start', function() {
|
it('should unlock crypto and start', function(done) {
|
||||||
var keypair = {},
|
var keypair = {},
|
||||||
pathSpy = sinon.spy(location, 'path');
|
pathSpy = sinon.spy(location, 'path');
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, keypair);
|
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(resolves(keypair));
|
||||||
emailDaoMock.unlock.withArgs({
|
emailDaoMock.unlock.withArgs({
|
||||||
keypair: keypair,
|
keypair: keypair,
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
authMock.storeCredentials.yields();
|
authMock.storeCredentials.returns(resolves());
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
|
scope.confirmPassphrase().then(function() {
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
||||||
expect(pathSpy.calledOnce).to.be.true;
|
expect(pathSpy.calledOnce).to.be.true;
|
||||||
expect(pathSpy.calledWith('/account')).to.be.true;
|
expect(pathSpy.calledWith('/account')).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not work when keypair unavailable', function() {
|
it('should not work when keypair unavailable', function(done) {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(new Error('asd'));
|
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(rejects(new Error('asd')));
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
scope.confirmPassphrase().then(function() {
|
||||||
expect(scope.errMsg).to.exist;
|
expect(scope.errMsg).to.exist;
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -30,6 +30,7 @@ describe('Login (initial user) Controller unit test', function() {
|
|||||||
ctrl = $controller(LoginInitialCtrl, {
|
ctrl = $controller(LoginInitialCtrl, {
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
$routeParams: {},
|
$routeParams: {},
|
||||||
|
$q: window.qMock,
|
||||||
newsletter: newsletter,
|
newsletter: newsletter,
|
||||||
email: emailMock,
|
email: emailMock,
|
||||||
auth: authMock
|
auth: authMock
|
||||||
@ -74,36 +75,38 @@ describe('Login (initial user) Controller unit test', function() {
|
|||||||
expect(newsletterStub.called).to.be.false;
|
expect(newsletterStub.called).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail due to error in emailDao.unlock', function() {
|
it('should fail due to error in emailDao.unlock', function(done) {
|
||||||
scope.agree = true;
|
scope.agree = true;
|
||||||
|
|
||||||
emailMock.unlock.withArgs({
|
emailMock.unlock.withArgs({
|
||||||
passphrase: undefined
|
passphrase: undefined
|
||||||
}).yields(new Error('asdf'));
|
}).returns(rejects(new Error('asdf')));
|
||||||
authMock.storeCredentials.yields();
|
authMock.storeCredentials.returns(resolves());
|
||||||
|
|
||||||
scope.generateKey();
|
|
||||||
|
|
||||||
|
scope.generateKey().then(function() {
|
||||||
expect(scope.errMsg).to.exist;
|
expect(scope.errMsg).to.exist;
|
||||||
expect(scope.state.ui).to.equal(1);
|
expect(scope.state.ui).to.equal(1);
|
||||||
expect(newsletterStub.called).to.be.true;
|
expect(newsletterStub.called).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unlock crypto', function() {
|
it('should unlock crypto', function(done) {
|
||||||
scope.agree = true;
|
scope.agree = true;
|
||||||
|
|
||||||
emailMock.unlock.withArgs({
|
emailMock.unlock.withArgs({
|
||||||
passphrase: undefined
|
passphrase: undefined
|
||||||
}).yields();
|
}).returns(resolves());
|
||||||
authMock.storeCredentials.yields();
|
authMock.storeCredentials.returns(resolves());
|
||||||
|
|
||||||
scope.generateKey();
|
|
||||||
|
|
||||||
|
scope.generateKey().then(function() {
|
||||||
expect(scope.errMsg).to.not.exist;
|
expect(scope.errMsg).to.not.exist;
|
||||||
expect(scope.state.ui).to.equal(2);
|
expect(scope.state.ui).to.equal(2);
|
||||||
expect(newsletterStub.called).to.be.true;
|
expect(newsletterStub.called).to.be.true;
|
||||||
expect(location.$$path).to.equal('/account');
|
expect(location.$$path).to.equal('/account');
|
||||||
expect(emailMock.unlock.calledOnce).to.be.true;
|
expect(emailMock.unlock.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -35,6 +35,7 @@ describe('Login (new device) Controller unit test', function() {
|
|||||||
ctrl = $controller(LoginNewDeviceCtrl, {
|
ctrl = $controller(LoginNewDeviceCtrl, {
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
$routeParams: {},
|
$routeParams: {},
|
||||||
|
$q: window.qMock,
|
||||||
email: emailMock,
|
email: emailMock,
|
||||||
auth: authMock,
|
auth: authMock,
|
||||||
pgp: pgpMock,
|
pgp: pgpMock,
|
||||||
@ -53,7 +54,7 @@ describe('Login (new device) Controller unit test', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('confirm passphrase', function() {
|
describe('confirm passphrase', function() {
|
||||||
it('should unlock crypto with a public key on the server', function() {
|
it('should unlock crypto with a public key on the server', function(done) {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
scope.key = {
|
scope.key = {
|
||||||
privateKeyArmored: 'b'
|
privateKeyArmored: 'b'
|
||||||
@ -64,20 +65,21 @@ describe('Login (new device) Controller unit test', function() {
|
|||||||
userIds: []
|
userIds: []
|
||||||
});
|
});
|
||||||
|
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(resolves({
|
||||||
_id: keyId,
|
_id: keyId,
|
||||||
publicKey: 'a'
|
publicKey: 'a'
|
||||||
});
|
}));
|
||||||
emailMock.unlock.withArgs(sinon.match.any, passphrase).yields();
|
emailMock.unlock.withArgs(sinon.match.any, passphrase).returns(resolves());
|
||||||
keychainMock.putUserKeyPair.yields();
|
keychainMock.putUserKeyPair.returns(resolves());
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
|
scope.confirmPassphrase().then(function() {
|
||||||
expect(emailMock.unlock.calledOnce).to.be.true;
|
expect(emailMock.unlock.calledOnce).to.be.true;
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unlock crypto with no key on the server', function() {
|
it('should unlock crypto with no key on the server', function(done) {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
scope.key = {
|
scope.key = {
|
||||||
privateKeyArmored: 'b',
|
privateKeyArmored: 'b',
|
||||||
@ -89,17 +91,18 @@ describe('Login (new device) Controller unit test', function() {
|
|||||||
userIds: []
|
userIds: []
|
||||||
});
|
});
|
||||||
|
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields();
|
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(resolves());
|
||||||
emailMock.unlock.withArgs(sinon.match.any, passphrase).yields();
|
emailMock.unlock.withArgs(sinon.match.any, passphrase).returns(resolves());
|
||||||
keychainMock.putUserKeyPair.yields();
|
keychainMock.putUserKeyPair.returns(resolves());
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
|
scope.confirmPassphrase().then(function() {
|
||||||
expect(emailMock.unlock.calledOnce).to.be.true;
|
expect(emailMock.unlock.calledOnce).to.be.true;
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not work when keypair upload fails', function() {
|
it('should not work when keypair upload fails', function(done) {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
scope.key = {
|
scope.key = {
|
||||||
privateKeyArmored: 'b'
|
privateKeyArmored: 'b'
|
||||||
@ -110,24 +113,25 @@ describe('Login (new device) Controller unit test', function() {
|
|||||||
userIds: []
|
userIds: []
|
||||||
});
|
});
|
||||||
|
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(resolves({
|
||||||
_id: keyId,
|
_id: keyId,
|
||||||
publicKey: 'a'
|
publicKey: 'a'
|
||||||
});
|
}));
|
||||||
emailMock.unlock.yields();
|
emailMock.unlock.returns(resolves());
|
||||||
keychainMock.putUserKeyPair.yields({
|
keychainMock.putUserKeyPair.returns(rejects({
|
||||||
errMsg: 'yo mamma.'
|
errMsg: 'yo mamma.'
|
||||||
});
|
}));
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
|
scope.confirmPassphrase().then(function() {
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
expect(emailMock.unlock.calledOnce).to.be.true;
|
expect(emailMock.unlock.calledOnce).to.be.true;
|
||||||
expect(keychainMock.putUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.putUserKeyPair.calledOnce).to.be.true;
|
||||||
expect(scope.errMsg).to.equal('yo mamma.');
|
expect(scope.errMsg).to.equal('yo mamma.');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not work when unlock fails', function() {
|
it('should not work when unlock fails', function(done) {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
scope.key = {
|
scope.key = {
|
||||||
privateKeyArmored: 'b'
|
privateKeyArmored: 'b'
|
||||||
@ -138,36 +142,38 @@ describe('Login (new device) Controller unit test', function() {
|
|||||||
userIds: []
|
userIds: []
|
||||||
});
|
});
|
||||||
|
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(resolves({
|
||||||
_id: keyId,
|
_id: keyId,
|
||||||
publicKey: 'a'
|
publicKey: 'a'
|
||||||
});
|
}));
|
||||||
emailMock.unlock.yields({
|
emailMock.unlock.returns(rejects({
|
||||||
errMsg: 'yo mamma.'
|
errMsg: 'yo mamma.'
|
||||||
});
|
}));
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
|
scope.confirmPassphrase().then(function() {
|
||||||
expect(scope.incorrect).to.be.true;
|
expect(scope.incorrect).to.be.true;
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
expect(emailMock.unlock.calledOnce).to.be.true;
|
expect(emailMock.unlock.calledOnce).to.be.true;
|
||||||
expect(scope.errMsg).to.equal('yo mamma.');
|
expect(scope.errMsg).to.equal('yo mamma.');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not work when keypair retrieval', function() {
|
it('should not work when keypair retrieval', function(done) {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
scope.key = {
|
scope.key = {
|
||||||
privateKeyArmored: 'b'
|
privateKeyArmored: 'b'
|
||||||
};
|
};
|
||||||
|
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields({
|
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(rejects({
|
||||||
errMsg: 'yo mamma.'
|
errMsg: 'yo mamma.'
|
||||||
});
|
}));
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
|
scope.confirmPassphrase().then(function() {
|
||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
expect(scope.errMsg).to.equal('yo mamma.');
|
expect(scope.errMsg).to.equal('yo mamma.');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user