mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 02:42:17 -05:00
Finish testing account service
This commit is contained in:
parent
7f6410e1f8
commit
2a2058c167
@ -137,13 +137,12 @@ Account.prototype.isOnline = function() {
|
|||||||
/**
|
/**
|
||||||
* Event that is called when the user agent goes online. This create new instances of the imap-client and pgp-mailer and connects to the mail server.
|
* Event that is called when the user agent goes online. This create new instances of the imap-client and pgp-mailer and connects to the mail server.
|
||||||
*/
|
*/
|
||||||
Account.prototype.onConnect = function(callback) {
|
Account.prototype.onConnect = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var config = self._appConfig.config;
|
var config = self._appConfig.config;
|
||||||
|
|
||||||
if (!self.isOnline() || !self._emailDao || !self._emailDao._account) {
|
if (!self.isOnline() || !self._emailDao || !self._emailDao._account) {
|
||||||
// prevent connection infinite loop
|
// prevent connection infinite loop
|
||||||
callback();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,10 +7,11 @@ var Account = require('../../../src/js/email/account'),
|
|||||||
Email = require('../../../src/js/email/email'),
|
Email = require('../../../src/js/email/email'),
|
||||||
Outbox = require('../../../src/js/email/outbox'),
|
Outbox = require('../../../src/js/email/outbox'),
|
||||||
Keychain = require('../../../src/js/service/keychain'),
|
Keychain = require('../../../src/js/service/keychain'),
|
||||||
UpdateHandler = require('../../../src/js/util/update/update-handler');
|
UpdateHandler = require('../../../src/js/util/update/update-handler'),
|
||||||
|
Dialog = require('../../../src/js/util/dialog');
|
||||||
|
|
||||||
describe('Account Service unit test', function() {
|
describe('Account Service unit test', function() {
|
||||||
var account, authStub, outboxStub, emailStub, devicestorageStub, keychainStub, updateHandlerStub, pgpbuilderStub,
|
var account, authStub, outboxStub, emailStub, devicestorageStub, keychainStub, updateHandlerStub, pgpbuilderStub, dialogStub,
|
||||||
realname = 'John Doe',
|
realname = 'John Doe',
|
||||||
dummyUser = 'spiderpig@springfield.com';
|
dummyUser = 'spiderpig@springfield.com';
|
||||||
|
|
||||||
@ -25,7 +26,8 @@ describe('Account Service unit test', function() {
|
|||||||
keychainStub = sinon.createStubInstance(Keychain);
|
keychainStub = sinon.createStubInstance(Keychain);
|
||||||
updateHandlerStub = sinon.createStubInstance(UpdateHandler);
|
updateHandlerStub = sinon.createStubInstance(UpdateHandler);
|
||||||
pgpbuilderStub = {};
|
pgpbuilderStub = {};
|
||||||
account = new Account(appConfig, authStub, devicestorageStub, emailStub, outboxStub, keychainStub, updateHandlerStub, pgpbuilderStub);
|
dialogStub = sinon.createStubInstance(Dialog);
|
||||||
|
account = new Account(appConfig, authStub, devicestorageStub, emailStub, outboxStub, keychainStub, updateHandlerStub, pgpbuilderStub, dialogStub);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {});
|
afterEach(function() {});
|
||||||
@ -212,4 +214,62 @@ describe('Account Service unit test', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('onConnect', function() {
|
||||||
|
var credentials = {
|
||||||
|
imap: {},
|
||||||
|
smtp: {}
|
||||||
|
};
|
||||||
|
beforeEach(function() {
|
||||||
|
emailStub._account = {};
|
||||||
|
sinon.stub(account, 'isOnline').returns(true);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
account.isOnline.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail due to _auth.getCredentials', function() {
|
||||||
|
authStub.getCredentials.yields(new Error('asdf'));
|
||||||
|
|
||||||
|
account.onConnect();
|
||||||
|
|
||||||
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work', function() {
|
||||||
|
authStub.getCredentials.yields(null, credentials);
|
||||||
|
emailStub.onConnect.yields();
|
||||||
|
|
||||||
|
account.onConnect();
|
||||||
|
|
||||||
|
expect(emailStub.onConnect.calledOnce).to.be.true;
|
||||||
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onDisconnect', function() {
|
||||||
|
it('should work', function() {
|
||||||
|
account.onDisconnect();
|
||||||
|
expect(emailStub.onDisconnect.calledOnce).to.be.true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('logout', function() {
|
||||||
|
it('should fail due to _auth.logout', function() {
|
||||||
|
authStub.logout.yields(new Error());
|
||||||
|
|
||||||
|
account.logout();
|
||||||
|
|
||||||
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail due to _emailDao.onDisconnect', function() {
|
||||||
|
authStub.logout.yields();
|
||||||
|
emailStub.onDisconnect.yields(new Error());
|
||||||
|
|
||||||
|
account.logout();
|
||||||
|
|
||||||
|
expect(dialogStub.error.calledOnce).to.be.true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user