mail/test/unit/controller/login/login-existing-ctrl-test.js

79 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-11-25 12:19:40 -05:00
var Auth = require('../../../../src/js/service/auth'),
LoginExistingCtrl = require('../../../../src/js/controller/login/login-existing'),
EmailDAO = require('../../../../src/js/email/email'),
KeychainDAO = require('../../../../src/js/service/keychain');
2014-10-07 14:32:23 -04:00
describe('Login (existing user) Controller unit test', function() {
2014-11-25 12:19:40 -05:00
var scope, location, ctrl, emailDaoMock, authMock,
2014-10-07 14:32:23 -04:00
emailAddress = 'fred@foo.com',
passphrase = 'asd',
keychainMock;
beforeEach(function() {
2014-11-25 12:19:40 -05:00
emailDaoMock = sinon.createStubInstance(EmailDAO);
authMock = sinon.createStubInstance(Auth);
2014-10-07 14:32:23 -04:00
keychainMock = sinon.createStubInstance(KeychainDAO);
2014-11-25 12:19:40 -05:00
authMock.emailAddress = emailAddress;
2014-10-07 14:32:23 -04:00
2014-11-25 12:19:40 -05:00
angular.module('loginexistingtest', ['woServices']);
angular.mock.module('loginexistingtest');
angular.mock.inject(function($rootScope, $controller, $location) {
2014-10-07 14:32:23 -04:00
location = $location;
scope = $rootScope.$new();
scope.state = {};
scope.form = {};
2014-10-07 14:32:23 -04:00
ctrl = $controller(LoginExistingCtrl, {
$scope: scope,
2014-11-25 12:19:40 -05:00
$routeParams: {},
2014-12-17 16:41:57 -05:00
$q: window.qMock,
2014-11-25 12:19:40 -05:00
email: emailDaoMock,
auth: authMock,
keychain: keychainMock
});
});
2014-10-07 14:32:23 -04:00
});
2014-11-25 12:19:40 -05:00
afterEach(function() {});
2014-10-07 14:32:23 -04:00
describe('initial state', function() {
it('should be well defined', function() {
expect(scope.incorrect).to.be.undefined;
});
2014-10-07 14:32:23 -04:00
});
describe('confirm passphrase', function() {
2014-12-17 16:41:57 -05:00
it('should unlock crypto and start', function(done) {
var keypair = {},
pathSpy = sinon.spy(location, 'path');
scope.passphrase = passphrase;
2014-12-17 16:41:57 -05:00
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(resolves(keypair));
emailDaoMock.unlock.withArgs({
keypair: keypair,
passphrase: passphrase
2014-12-17 16:41:57 -05:00
}).returns(resolves());
authMock.storeCredentials.returns(resolves());
2014-12-17 16:41:57 -05:00
scope.confirmPassphrase().then(function() {
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
expect(emailDaoMock.unlock.calledOnce).to.be.true;
expect(pathSpy.calledOnce).to.be.true;
expect(pathSpy.calledWith('/account')).to.be.true;
done();
});
});
2014-12-17 16:41:57 -05:00
it('should not work when keypair unavailable', function(done) {
scope.passphrase = passphrase;
2014-12-17 16:41:57 -05:00
keychainMock.getUserKeyPair.withArgs(emailAddress).returns(rejects(new Error('asd')));
2014-10-07 14:32:23 -04:00
2014-12-17 16:41:57 -05:00
scope.confirmPassphrase().then(function() {
expect(scope.errMsg).to.exist;
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
done();
});
});
});
});