mirror of https://github.com/moparisthebest/mail
Start writing account test
This commit is contained in:
parent
f2fee61d3b
commit
c8980f6f51
|
@ -177,6 +177,7 @@ module.exports = function(grunt) {
|
||||||
'test/unit/service/invitation-dao-test.js',
|
'test/unit/service/invitation-dao-test.js',
|
||||||
'test/unit/email/outbox-bo-test.js',
|
'test/unit/email/outbox-bo-test.js',
|
||||||
'test/unit/email/email-dao-test.js',
|
'test/unit/email/email-dao-test.js',
|
||||||
|
'test/unit/email/account-test.js',
|
||||||
/*'test/unit/dialog-ctrl-test.js',
|
/*'test/unit/dialog-ctrl-test.js',
|
||||||
'test/unit/add-account-ctrl-test.js',
|
'test/unit/add-account-ctrl-test.js',
|
||||||
'test/unit/create-account-ctrl-test.js',
|
'test/unit/create-account-ctrl-test.js',
|
||||||
|
|
|
@ -9,17 +9,16 @@ var axe = require('axe-logger'),
|
||||||
PgpMailer = require('pgpmailer'),
|
PgpMailer = require('pgpmailer'),
|
||||||
ImapClient = require('imap-client');
|
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._appConfig = appConfig;
|
||||||
this._auth = auth;
|
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._accountStore = accountStore;
|
||||||
|
this._emailDao = email;
|
||||||
|
this._outbox = outbox;
|
||||||
|
this._keychain = keychain;
|
||||||
this._updateHandler = updateHandler;
|
this._updateHandler = updateHandler;
|
||||||
|
this._pgpbuilder = pgpbuilder;
|
||||||
|
this._dialog = dialog;
|
||||||
this._accounts = []; // init accounts list
|
this._accounts = []; // init accounts list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,9 +235,3 @@ 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() {};
|
|
|
@ -56,8 +56,7 @@ function Email(keychain, pgp, accountStore, pgpbuilder, mailreader, dialog) {
|
||||||
this._devicestorage = accountStore;
|
this._devicestorage = accountStore;
|
||||||
this._pgpbuilder = pgpbuilder;
|
this._pgpbuilder = pgpbuilder;
|
||||||
this._mailreader = mailreader;
|
this._mailreader = mailreader;
|
||||||
|
this._dialog = dialog;
|
||||||
this.onError = dialog.error.bind(dialog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1263,7 +1262,7 @@ Email.prototype._onSyncUpdate = function(options) {
|
||||||
folder: folder,
|
folder: folder,
|
||||||
firstUid: Math.min.apply(null, options.list),
|
firstUid: Math.min.apply(null, options.list),
|
||||||
lastUid: Math.max.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) {
|
} else if (options.type === SYNC_TYPE_DELETED) {
|
||||||
// messages have been deleted, remove from local storage and memory
|
// messages have been deleted, remove from local storage and memory
|
||||||
options.list.forEach(function(uid) {
|
options.list.forEach(function(uid) {
|
||||||
|
@ -1279,7 +1278,7 @@ Email.prototype._onSyncUpdate = function(options) {
|
||||||
folder: folder,
|
folder: folder,
|
||||||
message: message,
|
message: message,
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}, self.onError.bind(self));
|
}, self._dialog.error);
|
||||||
});
|
});
|
||||||
} else if (options.type === SYNC_TYPE_MSGS) {
|
} else if (options.type === SYNC_TYPE_MSGS) {
|
||||||
// NB! several possible reasons why this could be called.
|
// NB! several possible reasons why this could be called.
|
||||||
|
@ -1306,7 +1305,7 @@ Email.prototype._onSyncUpdate = function(options) {
|
||||||
folder: folder,
|
folder: folder,
|
||||||
message: message,
|
message: message,
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}, self.onError.bind(self));
|
}, self._dialog.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -1899,64 +1899,55 @@ describe('Email DAO unit tests', function() {
|
||||||
setFlagsStub = sinon.stub(dao, 'setFlags');
|
setFlagsStub = sinon.stub(dao, 'setFlags');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get new message', function(done) {
|
it('should get new message', function() {
|
||||||
fetchMessagesStub.withArgs({
|
fetchMessagesStub.withArgs({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
firstUid: 1,
|
firstUid: 1,
|
||||||
lastUid: 3
|
lastUid: 3
|
||||||
}).yieldsAsync();
|
}).yields();
|
||||||
|
|
||||||
dao.onError = function(err) {
|
|
||||||
expect(err).to.not.exist;
|
|
||||||
expect(fetchMessagesStub.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
dao._onSyncUpdate({
|
dao._onSyncUpdate({
|
||||||
type: 'new',
|
type: 'new',
|
||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
list: [1, 3]
|
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({
|
deleteMessagesStub.withArgs({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
message: msgs[0],
|
message: msgs[0],
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}).yieldsAsync();
|
}).yields();
|
||||||
|
|
||||||
dao.onError = function(err) {
|
|
||||||
expect(err).to.not.exist;
|
|
||||||
expect(deleteMessagesStub.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
dao._onSyncUpdate({
|
dao._onSyncUpdate({
|
||||||
type: 'deleted',
|
type: 'deleted',
|
||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
list: [5]
|
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({
|
setFlagsStub.withArgs({
|
||||||
folder: inboxFolder,
|
folder: inboxFolder,
|
||||||
message: msgs[0],
|
message: msgs[0],
|
||||||
localOnly: true
|
localOnly: true
|
||||||
}).yieldsAsync();
|
}).yields();
|
||||||
|
|
||||||
dao.onError = function(err) {
|
|
||||||
expect(err).to.not.exist;
|
|
||||||
expect(setFlagsStub.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
dao._onSyncUpdate({
|
dao._onSyncUpdate({
|
||||||
type: 'messages',
|
type: 'messages',
|
||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
list: msgs
|
list: msgs
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
expect(setFlagsStub.calledOnce).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue