merged new error handlers with controller unti tests

This commit is contained in:
Tankred Hase 2013-11-14 20:13:27 +01:00
parent 61b02c8175
commit 5be2d89fab
5 changed files with 48 additions and 25 deletions

View File

@ -46,12 +46,7 @@ define(function(require) {
content: keys.publicKeyArmored + keys.privateKeyArmored,
filename: id + '.asc',
contentType: 'text/plain'
}, function onSave(err) {
if (err) {
$scope.onError(err);
return;
}
});
}, $scope.onError);
});
};
};

View File

@ -162,7 +162,7 @@ define(function(require) {
function moved(err) {
if (err) {
console.error(err);
$scope.onError(err);
$scope.emails.splice(index, 0, email);
$scope.$apply();
return;

View File

@ -69,7 +69,7 @@ define(function(require) {
// get last item from outbox
emailDao._devicestorage.listItems(dbType, 0, null, function(err, pending) {
if (err) {
console.error(err);
$scope.onError(err);
outboxBusy = false;
return;
}
@ -92,7 +92,7 @@ define(function(require) {
var email = emails.shift();
emailDao.smtpSend(email, function(err) {
if (err) {
console.error(err);
$scope.onError(err);
outboxBusy = false;
return;
}
@ -104,7 +104,9 @@ define(function(require) {
function removeFromStorage(id) {
if (!id) {
console.error('Cannot remove email from storage without a valid id!');
$scope.onError({
errMsg: 'Cannot remove email from storage without a valid id!'
});
outboxBusy = false;
return;
}
@ -113,7 +115,7 @@ define(function(require) {
var key = dbType + '_' + id;
emailDao._devicestorage.removeList(key, function(err) {
if (err) {
console.error(err);
$scope.onError(err);
outboxBusy = false;
return;
}
@ -144,7 +146,7 @@ define(function(require) {
if (window.chrome && chrome.identity) {
emailDao.imapListFolders(function(err, folders) {
if (err) {
console.log(err);
$scope.onError(err);
return;
}

View File

@ -63,7 +63,7 @@ define(function(require) {
});
});
describe('export to key file', function() {
it('should work', function() {
it('should work', function(done) {
var createDownloadMock = sinon.stub(dl, 'createDownload');
cryptoMock.exportKeys.yields(null, {
publicKeyArmored: 'a',
@ -73,12 +73,14 @@ define(function(require) {
createDownloadMock.withArgs(sinon.match(function(arg) {
return arg.content === 'ab' && arg.filename === expectedKeyId + '.asc' && arg.contentType === 'text/plain';
})).yields();
scope.onError = function() {
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
expect(dl.createDownload.calledOnce).to.be.true;
dl.createDownload.restore();
done();
};
scope.exportKeyFile();
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
expect(dl.createDownload.calledOnce).to.be.true;
dl.createDownload.restore();
});
it('should not work when key export failed', function(done) {

View File

@ -146,16 +146,18 @@ define(function(require) {
expect(scope.sendBtnText).to.equal('Send securely');
});
it('should verify the recipient as not secure', function() {
it('should verify the recipient as not secure', function(done) {
var id = scope.to = 'pity@da.fool';
keychainMock.getReceiverPublicKey.withArgs(id).yields({
errMsg: '404 not found yadda yadda'
});
scope.onError = function() {
expect(scope.toSecure).to.be.false;
expect(scope.sendBtnText).to.equal('Invite & send securely');
done();
};
scope.verifyTo();
expect(scope.toSecure).to.be.false;
expect(scope.sendBtnText).to.equal('Invite & send securely');
});
it('should reset display if there is no recipient', function() {
@ -170,6 +172,7 @@ define(function(require) {
scope.to = 'a, b, c';
scope.body = 'asd';
scope.subject = 'yaddablabla';
scope.toKey = 'Public Key';
deviceStorageMock.storeList.withArgs(sinon.match(function(mail) {
return mail[0].from[0].address === emailAddress && mail[0].to.length === 3;
@ -183,22 +186,43 @@ define(function(require) {
scope.sendToOutbox();
});
it('should not work and not close the write view', function() {
it('should not work if recipient does not have a public key', function(done) {
scope.state.writer.open = true;
scope.to = 'a, b, c';
scope.body = 'asd';
scope.subject = 'yaddablabla';
scope.onError = function(err) {
expect(err).to.exist;
expect(scope.state.writer.open).to.be.true;
expect(deviceStorageMock.storeList.called).to.be.false;
done();
};
scope.sendToOutbox();
});
it('should not work and not close the write view', function(done) {
scope.state.writer.open = true;
scope.to = 'a, b, c';
scope.body = 'asd';
scope.subject = 'yaddablabla';
scope.toKey = 'Public Key';
deviceStorageMock.storeList.withArgs(sinon.match(function(mail) {
return mail[0].from[0].address === emailAddress && mail[0].to.length === 3;
})).yields({
errMsg: 'snafu'
});
scope.sendToOutbox();
scope.onError = function(err) {
expect(err).to.exist;
expect(scope.state.writer.open).to.be.true;
expect(deviceStorageMock.storeList.calledOnce).to.be.true;
done();
};
expect(scope.state.writer.open).to.be.true;
expect(deviceStorageMock.storeList.calledOnce).to.be.true;
scope.sendToOutbox();
});
});
});