1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-22 15:28:49 -05:00

fix tests

This commit is contained in:
Tankred Hase 2014-03-31 21:35:40 +02:00
parent f3b3a4b496
commit f8e0c90b5b
6 changed files with 61 additions and 127 deletions

View File

@ -2,8 +2,7 @@ define(function(require) {
'use strict';
var appController = require('js/app-controller'),
errorUtil = require('js/util/error'),
dl = require('js/util/download');
errorUtil = require('js/util/error');
var LoginInitialCtrl = function($scope, $location) {
var emailDao = appController._emailDao,

View File

@ -291,32 +291,11 @@ define(function(require) {
});
});
it('should fail due to error in onConnect', function(done) {
devicestorageStub.init.yields();
updateHandlerStub.update.yields();
emailDaoStub.init.yields();
onConnectStub.yields({});
controller.init({
emailAddress: emailAddress
}, function(err) {
expect(err).to.exist;
expect(updateHandlerStub.update.calledOnce).to.be.true;
expect(emailDaoStub.init.calledOnce).to.be.true;
expect(devicestorageStub.init.calledOnce).to.be.true;
expect(onConnectStub.calledOnce).to.be.true;
done();
});
});
it('should work and return a keypair', function(done) {
devicestorageStub.init.withArgs(emailAddress).yields();
emailDaoStub.init.yields(null, {});
updateHandlerStub.update.yields();
onConnectStub.yields();
controller.init({
emailAddress: emailAddress
}, function(err, keypair) {
@ -325,7 +304,6 @@ define(function(require) {
expect(updateHandlerStub.update.calledOnce).to.be.true;
expect(emailDaoStub.init.calledOnce).to.be.true;
expect(devicestorageStub.init.calledOnce).to.be.true;
expect(onConnectStub.calledOnce).to.be.true;
done();
});
});

View File

@ -133,14 +133,18 @@ define(function(require) {
dao._account.folders = [];
imapClientStub.login.yields();
var listFolderStub = sinon.stub(dao, '_imapListFolders').yields(null, []);
dao.onConnect({
imapClient: imapClientStub,
pgpMailer: pgpMailerStub
}, function(err) {
expect(err).to.not.exist;
expect(dao._account.online).to.be.true;
expect(dao._account.folders).to.deep.equal([]);
expect(dao._imapClient).to.equal(dao._imapClient);
expect(dao._smtpClient).to.equal(dao._smtpClient);
listFolderStub.restore();
done();
});
});
@ -306,23 +310,7 @@ define(function(require) {
});
});
it('should work when folder already initiated', function(done) {
dao._account.folders = [];
imapLoginStub.yields();
dao.onConnect({
imapClient: imapClientStub,
pgpMailer: pgpMailerStub
}, function(err) {
expect(err).to.not.exist;
expect(dao._account.online).to.be.true;
expect(dao._imapClient).to.equal(dao._imapClient);
expect(dao._smtpClient).to.equal(dao._smtpClient);
done();
});
});
it('should work when folder not yet initiated', function(done) {
it('should work', function(done) {
var folders = [];
imapLoginStub.yields();
imapListFoldersStub.yields(null, folders);

View File

@ -60,13 +60,55 @@ define(function(require) {
initStub.restore();
});
it('should forward to existing user login', function(done) {
startAppStub.yields();
getEmailAddressStub.yields(null, emailAddress);
initStub.yields(null, {
it('should forward directly to desktop for empty passphrase', function(done) {
var testKeys = {
privateKey: 'a',
publicKey: 'b'
};
startAppStub.yields();
getEmailAddressStub.yields(null, emailAddress);
initStub.yields(null, testKeys);
emailDaoMock.unlock.withArgs({
keypair: testKeys,
passphrase: undefined
}).yields();
angular.module('logintest', []);
mocks.module('logintest');
mocks.inject(function($controller, $rootScope, $location) {
location = $location;
sinon.stub(location, 'path', function(path) {
expect(path).to.equal('/desktop');
expect(startAppStub.calledOnce).to.be.true;
expect(checkForUpdateStub.calledOnce).to.be.true;
expect(getEmailAddressStub.calledOnce).to.be.true;
done();
});
scope = $rootScope.$new();
scope.state = {};
ctrl = $controller(LoginCtrl, {
$location: location,
$scope: scope
});
});
});
it('should forward to existing user login', function(done) {
var testKeys = {
privateKey: 'a',
publicKey: 'b'
};
startAppStub.yields();
getEmailAddressStub.yields(null, emailAddress);
initStub.yields(null, testKeys);
emailDaoMock.unlock.withArgs({
keypair: testKeys,
passphrase: undefined
}).yields({});
angular.module('logintest', []);
mocks.module('logintest');

View File

@ -5,7 +5,6 @@ define(function(require) {
angular = require('angular'),
mocks = require('angularMocks'),
LoginInitialCtrl = require('js/controller/login-initial'),
dl = require('js/util/download'),
PGP = require('js/crypto/pgp'),
EmailDAO = require('js/dao/email-dao'),
appController = require('js/app-controller');
@ -54,8 +53,6 @@ define(function(require) {
describe('initial state', function() {
it('should be well defined', function() {
expect(scope.proceed).to.exist;
expect(scope.exportKeypair).to.exist;
expect(scope.confirmPassphrase).to.exist;
expect(scope.state.ui).to.equal(1);
});
@ -63,10 +60,10 @@ define(function(require) {
describe('check passphrase quality', function() {
it('should be too short', function() {
scope.state.passphrase = '&§DG36abc';
scope.state.passphrase = '&§DG36';
scope.checkPassphraseQuality();
expect(scope.passphraseMsg).to.equal('Too short');
expect(scope.passphraseMsg).to.equal('Very weak');
expect(scope.passphraseRating).to.equal(0);
});
@ -112,16 +109,12 @@ define(function(require) {
emailDaoMock.unlock.withArgs({
passphrase: passphrase
}).yields();
setStateStub = sinon.stub(scope, 'setState', function(state) {
if (setStateStub.calledOnce) {
expect(state).to.equal(2);
} else if (setStateStub.calledTwice) {
expect(state).to.equal(4);
expect(emailDaoMock.unlock.calledOnce).to.be.true;
scope.setState.restore();
done();
}
});
scope.$apply = function() {
expect(location.$$path).to.equal('/desktop');
expect(emailDaoMock.unlock.calledOnce).to.be.true;
done();
};
scope.confirmPassphrase();
});
@ -139,6 +132,7 @@ define(function(require) {
emailDaoMock.unlock.withArgs({
passphrase: passphrase
}).yields(new Error('asd'));
setStateStub = sinon.stub(scope, 'setState', function(state) {
if (setStateStub.calledOnce) {
expect(state).to.equal(2);
@ -154,64 +148,5 @@ define(function(require) {
});
});
describe('proceed', function() {
it('should forward', function() {
var locationSpy = sinon.spy(location, 'path');
scope.proceed();
expect(locationSpy.calledWith('/desktop')).to.be.true;
});
});
describe('export keypair', function() {
it('should work', function() {
var locationSpy, createDownloadMock;
createDownloadMock = sinon.stub(dl, 'createDownload');
cryptoMock.exportKeys.yields(null, {
publicKeyArmored: 'a',
privateKeyArmored: 'b',
keyId: keyId
});
createDownloadMock.withArgs(sinon.match(function(arg) {
return arg.content === 'ab' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
})).yields();
locationSpy = sinon.spy(location, 'path');
scope.exportKeypair();
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
expect(createDownloadMock.calledOnce).to.be.true;
expect(locationSpy.calledWith('/desktop')).to.be.true;
dl.createDownload.restore();
});
it('should not work when download fails', function() {
var createDownloadMock = sinon.stub(dl, 'createDownload');
cryptoMock.exportKeys.yields(null, {
publicKeyArmored: 'a',
privateKeyArmored: 'b',
keyId: keyId
});
createDownloadMock.yields({
errMsg: 'snafu.'
});
scope.exportKeypair();
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
expect(createDownloadMock.calledOnce).to.be.true;
dl.createDownload.restore();
});
it('should not work when export fails', function() {
cryptoMock.exportKeys.yields(new Error('snafu.'));
scope.exportKeypair();
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
});
});
});
});

View File

@ -98,14 +98,6 @@ define(function(require) {
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
});
it('should not do anything without passphrase', function() {
scope.state.passphrase = '';
scope.confirmPassphrase();
expect(scope.incorrect).to.be.true;
});
it('should not work when keypair upload fails', function() {
scope.passphrase = passphrase;
scope.key = {