diff --git a/src/js/email/email.js b/src/js/email/email.js index 4498c9c..870dcaa 100644 --- a/src/js/email/email.js +++ b/src/js/email/email.js @@ -192,11 +192,11 @@ Email.prototype.openFolder = function(options) { self._imapClient.selectMailbox({ path: options.folder.path - }, function(err) { + }, function(err, folder) { if (err) { reject(err); } else { - resolve(); + resolve(folder); } }); }); diff --git a/test/integration/email-dao-test.js b/test/integration/email-dao-test.js index 9e6b8a3..c4ca728 100644 --- a/test/integration/email-dao-test.js +++ b/test/integration/email-dao-test.js @@ -247,35 +247,28 @@ describe('Email DAO integration tests', function() { ca: 'random string' } }, accountService._pgpbuilder) - }, cb); + }).then(cb).catch(cb); }); // clear the local database before each test var cleanup = new DeviceStorageDAO(new LawnchairDAO()); - cleanup.init(testAccount.user, function() { - cleanup.clear(function(err) { - expect(err).to.not.exist; - - onCleaned(); - }); + cleanup.init(testAccount.user).then(function() { + cleanup.clear().then(onCleaned); }); function onCleaned() { userStorage = accountService._accountStore; auth = accountService._auth; - auth.init(function(err) { - expect(err).to.not.exist; + auth.init().then(function() { accountService.init({ emailAddress: testAccount.user - }, function(err) { - expect(err).to.not.exist; - + }).then(function() { emailDao = accountService._emailDao; // stub rest request to key server - sinon.stub(emailDao._keychain._publicKeyDao, 'get').yields(null, mockKeyPair.publicKey); - sinon.stub(emailDao._keychain._publicKeyDao, 'getByUserId').yields(null, mockKeyPair.publicKey); + sinon.stub(emailDao._keychain._publicKeyDao, 'get').returns(resolves(mockKeyPair.publicKey)); + sinon.stub(emailDao._keychain._publicKeyDao, 'getByUserId').returns(resolves(mockKeyPair.publicKey)); emailDao.onIncomingMessage = function(messages) { expect(messages.length).to.equal(imapMessages.length); @@ -303,9 +296,7 @@ describe('Email DAO integration tests', function() { emailDao.unlock({ passphrase: testAccount.pass, keypair: mockKeyPair - }, function(err) { - expect(err).to.not.exist; - + }).then(function() { accountService.onConnect(function(err) { expect(err).to.not.exist; }); @@ -323,7 +314,7 @@ describe('Email DAO integration tests', function() { imapClient.stopListeningForChanges(function() { imapClient.logout(function() { - userStorage.clear(done); + userStorage.clear().then(done); }); }); }); @@ -333,10 +324,7 @@ describe('Email DAO integration tests', function() { if (emailDao._imapClient._client.selectedMailbox !== inbox.path) { emailDao.openFolder({ folder: inbox - }, function(err) { - expect(err).to.not.exist; - done(); - }); + }).then(done); return; } @@ -360,14 +348,12 @@ describe('Email DAO integration tests', function() { emailDao.deleteMessage({ folder: inbox, message: inbox.messages[0] - }, function(err) { - expect(err).to.not.exist; + }).then(function() { emailDao.openFolder({ folder: { path: '[Gmail]/Trash' } - }, function(err, folder) { - expect(err).to.not.exist; + }).then(function(folder) { expect(folder.exists).to.equal(1); done(); }); @@ -379,14 +365,12 @@ describe('Email DAO integration tests', function() { folder: inbox, destination: spam, message: inbox.messages[0] - }, function(err) { - expect(err).to.not.exist; + }).then(function() { emailDao.openFolder({ folder: { path: '[Gmail]/Spam' } - }, function(err, folder) { - expect(err).to.not.exist; + }).then(function(folder) { expect(folder.exists).to.equal(1); done(); }); @@ -397,8 +381,7 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[2] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { expect(message.body).to.equal('World 5!'); done(); }); @@ -408,8 +391,7 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[3] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { expect(message.html).to.equal('
asd'); done(); }); @@ -424,8 +406,7 @@ describe('Email DAO integration tests', function() { emailDao.setFlags({ folder: inbox, message: message - }, function(err) { - expect(err).to.not.exist; + }).then(function() { done(); }); }); @@ -436,13 +417,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[4] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.false; expect(message.signaturesValid).to.be.undefined; @@ -457,13 +436,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[5] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -478,13 +455,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[6] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -499,13 +474,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[7] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.false; expect(message.signaturesValid).to.be.undefined; @@ -520,13 +493,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[8] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.false; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -541,13 +512,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[9] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.false; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -562,13 +531,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[10] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.false; expect(message.signaturesValid).to.be.undefined; @@ -583,13 +550,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[11] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -604,13 +569,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[12] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -625,13 +588,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[13] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.false; expect(message.signaturesValid).to.be.undefined; @@ -646,13 +607,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[14] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.false; expect(message.signed).to.be.false; expect(message.signaturesValid).to.be.undefined; @@ -667,13 +626,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[15] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.false; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -688,13 +645,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[16] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.false; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -709,13 +664,11 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: inbox.messages[17] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { emailDao.decryptBody({ message: message, folder: inbox - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(message.encrypted).to.be.true; expect(message.signed).to.be.false; expect(message.signaturesValid).to.be.undefined; @@ -748,8 +701,7 @@ describe('Email DAO integration tests', function() { subject: 'plaintext test', body: 'hello world!' } - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(smtpServer.onmail.callCount).to.equal(1); done(); }); @@ -774,8 +726,7 @@ describe('Email DAO integration tests', function() { body: 'hello world!', publicKeysArmored: [mockKeyPair.publicKey.publicKey] } - }, function(err) { - expect(err).to.not.exist; + }).then(function() { expect(smtpServer.onmail.callCount).to.equal(1); done(); }); @@ -802,8 +753,7 @@ describe('Email DAO integration tests', function() { emailDao.getBody({ folder: inbox, message: messages[0] - }, function(err, message) { - expect(err).to.not.exist; + }).then(function(message) { expect(message.encrypted).to.be.false; expect(message.signed).to.be.true; expect(message.signaturesValid).to.be.true; @@ -821,9 +771,7 @@ describe('Email DAO integration tests', function() { subject: 'plaintext test', body: expectedBody } - }, function(err) { - expect(err).to.not.exist; - }); + }).then(function() {}); }); }); }); \ No newline at end of file