diff --git a/Gruntfile.js b/Gruntfile.js index 643c117..538acb7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -177,6 +177,7 @@ module.exports = function(grunt) { 'test/unit/service/invitation-dao-test.js', 'test/unit/email/outbox-bo-test.js', 'test/unit/email/email-dao-test.js', + 'test/unit/email/account-test.js', /*'test/unit/dialog-ctrl-test.js', 'test/unit/add-account-ctrl-test.js', 'test/unit/create-account-ctrl-test.js', diff --git a/src/js/email/account.js b/src/js/email/account.js index c568ed9..2eb0010 100644 --- a/src/js/email/account.js +++ b/src/js/email/account.js @@ -9,17 +9,16 @@ var axe = require('axe-logger'), PgpMailer = require('pgpmailer'), ImapClient = require('imap-client'); -function Account(appConfig, auth, admin, mailConfig, keychain, pgpbuilder, email, outbox, accountStore, updateHandler) { +function Account(appConfig, auth, accountStore, email, outbox, keychain, updateHandler, pgpbuilder, dialog) { this._appConfig = appConfig; this._auth = auth; - this._admin = admin; - this._mailConfig = mailConfig; - this._keychain = keychain; - this._emailDao = email; - this._pgpbuilder = pgpbuilder; - this._outbox = outbox; this._accountStore = accountStore; + this._emailDao = email; + this._outbox = outbox; + this._keychain = keychain; this._updateHandler = updateHandler; + this._pgpbuilder = pgpbuilder; + this._dialog = dialog; this._accounts = []; // init accounts list } @@ -235,10 +234,4 @@ Account.prototype.logout = function() { } }); }); -}; - -/** - * Create a new whiteout account. This creates a new email data access object instance for that account and logs in via IMAP. - * @param {String} options.emailAddress The account's email address - */ -Account.prototype.create = function() {}; \ No newline at end of file +}; \ No newline at end of file diff --git a/src/js/email/email.js b/src/js/email/email.js index 3e4b2da..8ac597f 100644 --- a/src/js/email/email.js +++ b/src/js/email/email.js @@ -56,8 +56,7 @@ function Email(keychain, pgp, accountStore, pgpbuilder, mailreader, dialog) { this._devicestorage = accountStore; this._pgpbuilder = pgpbuilder; this._mailreader = mailreader; - - this.onError = dialog.error.bind(dialog); + this._dialog = dialog; } @@ -1263,7 +1262,7 @@ Email.prototype._onSyncUpdate = function(options) { folder: folder, firstUid: Math.min.apply(null, options.list), lastUid: Math.max.apply(null, options.list) - }, self.onError.bind(self)); + }, self._dialog.error); } else if (options.type === SYNC_TYPE_DELETED) { // messages have been deleted, remove from local storage and memory options.list.forEach(function(uid) { @@ -1279,7 +1278,7 @@ Email.prototype._onSyncUpdate = function(options) { folder: folder, message: message, localOnly: true - }, self.onError.bind(self)); + }, self._dialog.error); }); } else if (options.type === SYNC_TYPE_MSGS) { // NB! several possible reasons why this could be called. @@ -1306,7 +1305,7 @@ Email.prototype._onSyncUpdate = function(options) { folder: folder, message: message, localOnly: true - }, self.onError.bind(self)); + }, self._dialog.error); }); } }; diff --git a/test/unit/email/account-test.js b/test/unit/email/account-test.js new file mode 100644 index 0000000..815498b --- /dev/null +++ b/test/unit/email/account-test.js @@ -0,0 +1,53 @@ +'use strict'; + +var Account = require('../../../src/js/email/account'), + appConfig = require('../../../src/js/app-config'), + Auth = require('../../../src/js/service/auth'), + DeviceStorageDAO = require('../../../src/js/service/devicestorage'), + Email = require('../../../src/js/email/email'), + Outbox = require('../../../src/js/email/outbox'), + Keychain = require('../../../src/js/service/keychain'), + UpdateHandler = require('../../../src/js/util/update/update-handler'); + +describe('Account Service unit test', function() { + var account, authStub, outboxStub, emailStub, devicestorageStub, keychainStub, updateHandlerStub, pgpbuilderStub, + dummyUser = 'spiderpig@springfield.com'; + + chai.config.includeStack = true; + + beforeEach(function() { + authStub = sinon.createStubInstance(Auth); + outboxStub = sinon.createStubInstance(Outbox); + devicestorageStub = sinon.createStubInstance(DeviceStorageDAO); + emailStub = sinon.createStubInstance(Email); + outboxStub = sinon.createStubInstance(Outbox); + keychainStub = sinon.createStubInstance(Keychain); + updateHandlerStub = sinon.createStubInstance(UpdateHandler); + pgpbuilderStub = {}; + account = new Account(appConfig, authStub, devicestorageStub, emailStub, outboxStub, keychainStub, updateHandlerStub, pgpbuilderStub); + }); + + afterEach(function() {}); + + describe('isLoggedIn', function() { + it('should be logged in', function() { + account._accounts = [{}]; + expect(account.isLoggedIn()).to.be.true; + }); + it('should not be logged in', function() { + account._accounts = []; + expect(account.isLoggedIn()).to.be.false; + }); + }); + + describe('list', function() { + it('should work', function() { + var testAccounts = [{ + foo: 'bar' + }]; + account._accounts = testAccounts; + expect(account.list()).to.deep.equal(testAccounts); + }); + }); + +}); \ No newline at end of file diff --git a/test/unit/email/email-dao-test.js b/test/unit/email/email-dao-test.js index 95123e5..66d3397 100644 --- a/test/unit/email/email-dao-test.js +++ b/test/unit/email/email-dao-test.js @@ -1899,64 +1899,55 @@ describe('Email DAO unit tests', function() { setFlagsStub = sinon.stub(dao, 'setFlags'); }); - it('should get new message', function(done) { + it('should get new message', function() { fetchMessagesStub.withArgs({ folder: inboxFolder, firstUid: 1, lastUid: 3 - }).yieldsAsync(); - - dao.onError = function(err) { - expect(err).to.not.exist; - expect(fetchMessagesStub.calledOnce).to.be.true; - done(); - }; + }).yields(); dao._onSyncUpdate({ type: 'new', path: inboxFolder.path, list: [1, 3] }); + + expect(dialogStub.error.calledOnce).to.be.true; + expect(fetchMessagesStub.calledOnce).to.be.true; }); - it('should delete message', function(done) { + it('should delete message', function() { deleteMessagesStub.withArgs({ folder: inboxFolder, message: msgs[0], localOnly: true - }).yieldsAsync(); - - dao.onError = function(err) { - expect(err).to.not.exist; - expect(deleteMessagesStub.calledOnce).to.be.true; - done(); - }; + }).yields(); dao._onSyncUpdate({ type: 'deleted', path: inboxFolder.path, list: [5] }); + + expect(dialogStub.error.calledOnce).to.be.true; + expect(deleteMessagesStub.calledOnce).to.be.true; }); - it('should fetch flags', function(done) { + it('should fetch flags', function() { setFlagsStub.withArgs({ folder: inboxFolder, message: msgs[0], localOnly: true - }).yieldsAsync(); - - dao.onError = function(err) { - expect(err).to.not.exist; - expect(setFlagsStub.calledOnce).to.be.true; - done(); - }; + }).yields(); dao._onSyncUpdate({ type: 'messages', path: inboxFolder.path, list: msgs }); + + expect(dialogStub.error.calledOnce).to.be.true; + expect(setFlagsStub.calledOnce).to.be.true; }); }); });