mirror of
https://github.com/moparisthebest/mail
synced 2025-02-16 15:10:10 -05:00
merged new error handlers with controller unti tests
This commit is contained in:
parent
61b02c8175
commit
5be2d89fab
@ -46,12 +46,7 @@ define(function(require) {
|
|||||||
content: keys.publicKeyArmored + keys.privateKeyArmored,
|
content: keys.publicKeyArmored + keys.privateKeyArmored,
|
||||||
filename: id + '.asc',
|
filename: id + '.asc',
|
||||||
contentType: 'text/plain'
|
contentType: 'text/plain'
|
||||||
}, function onSave(err) {
|
}, $scope.onError);
|
||||||
if (err) {
|
|
||||||
$scope.onError(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -162,7 +162,7 @@ define(function(require) {
|
|||||||
|
|
||||||
function moved(err) {
|
function moved(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
$scope.onError(err);
|
||||||
$scope.emails.splice(index, 0, email);
|
$scope.emails.splice(index, 0, email);
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
return;
|
return;
|
||||||
|
@ -69,7 +69,7 @@ define(function(require) {
|
|||||||
// get last item from outbox
|
// get last item from outbox
|
||||||
emailDao._devicestorage.listItems(dbType, 0, null, function(err, pending) {
|
emailDao._devicestorage.listItems(dbType, 0, null, function(err, pending) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
$scope.onError(err);
|
||||||
outboxBusy = false;
|
outboxBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ define(function(require) {
|
|||||||
var email = emails.shift();
|
var email = emails.shift();
|
||||||
emailDao.smtpSend(email, function(err) {
|
emailDao.smtpSend(email, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
$scope.onError(err);
|
||||||
outboxBusy = false;
|
outboxBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -104,7 +104,9 @@ define(function(require) {
|
|||||||
|
|
||||||
function removeFromStorage(id) {
|
function removeFromStorage(id) {
|
||||||
if (!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;
|
outboxBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -113,7 +115,7 @@ define(function(require) {
|
|||||||
var key = dbType + '_' + id;
|
var key = dbType + '_' + id;
|
||||||
emailDao._devicestorage.removeList(key, function(err) {
|
emailDao._devicestorage.removeList(key, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
$scope.onError(err);
|
||||||
outboxBusy = false;
|
outboxBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -144,7 +146,7 @@ define(function(require) {
|
|||||||
if (window.chrome && chrome.identity) {
|
if (window.chrome && chrome.identity) {
|
||||||
emailDao.imapListFolders(function(err, folders) {
|
emailDao.imapListFolders(function(err, folders) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
$scope.onError(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('export to key file', function() {
|
describe('export to key file', function() {
|
||||||
it('should work', function() {
|
it('should work', function(done) {
|
||||||
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
||||||
cryptoMock.exportKeys.yields(null, {
|
cryptoMock.exportKeys.yields(null, {
|
||||||
publicKeyArmored: 'a',
|
publicKeyArmored: 'a',
|
||||||
@ -73,12 +73,14 @@ define(function(require) {
|
|||||||
createDownloadMock.withArgs(sinon.match(function(arg) {
|
createDownloadMock.withArgs(sinon.match(function(arg) {
|
||||||
return arg.content === 'ab' && arg.filename === expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
return arg.content === 'ab' && arg.filename === expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
||||||
})).yields();
|
})).yields();
|
||||||
|
scope.onError = function() {
|
||||||
|
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
|
||||||
|
expect(dl.createDownload.calledOnce).to.be.true;
|
||||||
|
dl.createDownload.restore();
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
scope.exportKeyFile();
|
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) {
|
it('should not work when key export failed', function(done) {
|
||||||
|
@ -146,16 +146,18 @@ define(function(require) {
|
|||||||
expect(scope.sendBtnText).to.equal('Send securely');
|
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';
|
var id = scope.to = 'pity@da.fool';
|
||||||
keychainMock.getReceiverPublicKey.withArgs(id).yields({
|
keychainMock.getReceiverPublicKey.withArgs(id).yields({
|
||||||
errMsg: '404 not found yadda yadda'
|
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();
|
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() {
|
it('should reset display if there is no recipient', function() {
|
||||||
@ -170,6 +172,7 @@ define(function(require) {
|
|||||||
scope.to = 'a, b, c';
|
scope.to = 'a, b, c';
|
||||||
scope.body = 'asd';
|
scope.body = 'asd';
|
||||||
scope.subject = 'yaddablabla';
|
scope.subject = 'yaddablabla';
|
||||||
|
scope.toKey = 'Public Key';
|
||||||
|
|
||||||
deviceStorageMock.storeList.withArgs(sinon.match(function(mail) {
|
deviceStorageMock.storeList.withArgs(sinon.match(function(mail) {
|
||||||
return mail[0].from[0].address === emailAddress && mail[0].to.length === 3;
|
return mail[0].from[0].address === emailAddress && mail[0].to.length === 3;
|
||||||
@ -183,22 +186,43 @@ define(function(require) {
|
|||||||
scope.sendToOutbox();
|
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.state.writer.open = true;
|
||||||
scope.to = 'a, b, c';
|
scope.to = 'a, b, c';
|
||||||
scope.body = 'asd';
|
scope.body = 'asd';
|
||||||
scope.subject = 'yaddablabla';
|
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) {
|
deviceStorageMock.storeList.withArgs(sinon.match(function(mail) {
|
||||||
return mail[0].from[0].address === emailAddress && mail[0].to.length === 3;
|
return mail[0].from[0].address === emailAddress && mail[0].to.length === 3;
|
||||||
})).yields({
|
})).yields({
|
||||||
errMsg: 'snafu'
|
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;
|
scope.sendToOutbox();
|
||||||
expect(deviceStorageMock.storeList.calledOnce).to.be.true;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user