1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 08:52:15 -05:00

Finish testing account service

This commit is contained in:
Tankred Hase 2014-11-25 12:07:26 +01:00
parent 7f6410e1f8
commit 2a2058c167
2 changed files with 64 additions and 5 deletions

View File

@ -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.
*/
Account.prototype.onConnect = function(callback) {
Account.prototype.onConnect = function() {
var self = this;
var config = self._appConfig.config;
if (!self.isOnline() || !self._emailDao || !self._emailDao._account) {
// prevent connection infinite loop
callback();
return;
}

View File

@ -7,10 +7,11 @@ var Account = require('../../../src/js/email/account'),
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');
UpdateHandler = require('../../../src/js/util/update/update-handler'),
Dialog = require('../../../src/js/util/dialog');
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',
dummyUser = 'spiderpig@springfield.com';
@ -25,7 +26,8 @@ describe('Account Service unit test', function() {
keychainStub = sinon.createStubInstance(Keychain);
updateHandlerStub = sinon.createStubInstance(UpdateHandler);
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() {});
@ -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;
});
});
});