1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 18:32:20 -05:00

fix bug in email dao init on first start

This commit is contained in:
Tankred Hase 2013-12-10 23:05:17 +01:00
parent d08321d345
commit 0e6dfe2c26
4 changed files with 34 additions and 20 deletions

View File

@ -369,8 +369,7 @@ define(function(require) {
self._emailDao.init({
account: account
}, function(err, keypair) {
// dont handle offline case this time
if (err && err.code !== 42) {
if (err) {
callback(err);
return;
}

View File

@ -57,7 +57,8 @@ define(function(require) {
function initFolders() {
// try init folders from memory, since imap client not initiated yet
self._imapListFolders(function(err, folders) {
if (err) {
// dont handle offline case this time
if (err && err.code !== 42) {
callback(err);
return;
}

View File

@ -266,8 +266,9 @@ define(function(require) {
it('should fail due to error in emailDao.init', function(done) {
emailDaoStub.init.yields({});
controller.init({}, function(err) {
controller.init({}, function(err, keypair) {
expect(err).to.exist;
expect(keypair).to.not.exist;
done();
});
});
@ -284,22 +285,6 @@ define(function(require) {
});
});
it('should pass email dao init when offline', function(done) {
emailDaoStub.init.yields({
code: 42
});
onConnectStub.yields();
outboxStub.init.returns();
controller.init({}, function(err) {
expect(err).to.not.exist;
expect(onConnectStub.calledOnce).to.be.true;
expect(outboxStub.init.calledOnce).to.be.true;
done();
});
});
it('should work and return a keypair', function(done) {
emailDaoStub.init.yields(null, {});

View File

@ -184,6 +184,35 @@ define(function(require) {
});
});
it('should not fail when offline', function(done) {
var listFolderStub;
// initKeychain
devicestorageStub.init.withArgs(emailAddress).yields();
keychainStub.getUserKeyPair.yields(null, mockKeyPair);
// initFolders
listFolderStub = sinon.stub(dao, '_imapListFolders');
listFolderStub.yields({code:42});
dao.init({
account: account
}, function(err, keyPair) {
expect(err).to.not.exist;
expect(dao._account.busy).to.be.false;
expect(dao._account.online).to.be.false;
expect(keyPair).to.equal(mockKeyPair);
expect(dao._account).to.equal(account);
expect(dao._account.folders).to.equal(undefined);
expect(devicestorageStub.init.calledOnce).to.be.true;
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
expect(listFolderStub.calledOnce).to.be.true;
done();
});
});
it('should fail due to error while listing folders', function(done) {
var listFolderStub;