From e02c250ea8f17598d666dff488273a9b74f71e2c Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Mon, 20 Jan 2014 11:03:01 +0100 Subject: [PATCH] do not try to send when offline --- src/js/bo/outbox.js | 7 +++++++ test/new-unit/outbox-bo-test.js | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/js/bo/outbox.js b/src/js/bo/outbox.js index 18e7a25..5c249ed 100644 --- a/src/js/bo/outbox.js +++ b/src/js/bo/outbox.js @@ -112,6 +112,13 @@ define(function(require) { self.pendingEmails.push(i); }); + // we're not online, don't even bother sending mails + if (!self._emailDao._account.online) { + self._outboxBusy = false; + callback(null, self.pendingEmails.length); + return; + } + // sending pending mails processMails(); }); diff --git a/test/new-unit/outbox-bo-test.js b/test/new-unit/outbox-bo-test.js index 3c3aec8..21eb46a 100644 --- a/test/new-unit/outbox-bo-test.js +++ b/test/new-unit/outbox-bo-test.js @@ -19,7 +19,8 @@ define(function(require) { emailAddress: dummyUser, folders: [{ type: 'Outbox' - }] + }], + online: true }; devicestorageStub = sinon.createStubInstance(DeviceStorageDAO); keychainStub = sinon.createStubInstance(KeychainDAO); @@ -107,6 +108,8 @@ define(function(require) { })).yieldsAsync(); var check = _.after(dummyMails.length + 1, function() { + expect(outbox._outboxBusy).to.be.false; + expect(unsentCount).to.equal(2); expect(emailDaoStub.list.callCount).to.equal(1); expect(emailDaoStub.sendEncrypted.callCount).to.equal(1); @@ -131,6 +134,25 @@ define(function(require) { outbox._processOutbox(onOutboxUpdate); }); + it('should not process outbox in offline mode', function(done) { + emailDaoStub._account.online = false; + emailDaoStub.list.yieldsAsync(null, [{ + id: '123', + to: [{ + name: 'member', + address: 'member@whiteout.io' + }] + }]); + + outbox._processOutbox(function(err, count) { + expect(err).to.not.exist; + expect(count).to.equal(1); + expect(emailDaoStub.list.callCount).to.equal(1); + expect(outbox._outboxBusy).to.be.false; + done(); + }); + }); + it('should fire notification', function(done) { outbox.onSent = function(email) { expect(email).to.exist;