mirror of
https://github.com/moparisthebest/mail
synced 2025-02-19 20:31:48 -05:00
Fis all util service tests
This commit is contained in:
parent
3342b91d3f
commit
881afbff40
@ -3,17 +3,14 @@
|
|||||||
var StatusDisplayCtrl = function($scope, statusDisplay) {
|
var StatusDisplayCtrl = function($scope, statusDisplay) {
|
||||||
|
|
||||||
// set the show functions
|
// set the show functions
|
||||||
statusDisplay.showStatus = updateStatus;
|
statusDisplay.showStatus = function(lbl, time) {
|
||||||
statusDisplay.showSearching = setSearching;
|
|
||||||
|
|
||||||
function updateStatus(lbl, time) {
|
|
||||||
$scope.lastUpdateLbl = lbl;
|
$scope.lastUpdateLbl = lbl;
|
||||||
$scope.lastUpdate = (time) ? time : '';
|
$scope.lastUpdate = (time) ? time : '';
|
||||||
}
|
};
|
||||||
|
|
||||||
function setSearching(state) {
|
statusDisplay.showSearching = function(state) {
|
||||||
$scope.searching = state;
|
$scope.searching = state;
|
||||||
}
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -151,11 +151,12 @@ ConnectionDoctor.prototype._checkReachable = function(options, callback) {
|
|||||||
timeout, // remember the timeout object
|
timeout, // remember the timeout object
|
||||||
host = options.host + ':' + options.port,
|
host = options.host + ':' + options.port,
|
||||||
hasTimedOut = false, // prevents multiple callbacks
|
hasTimedOut = false, // prevents multiple callbacks
|
||||||
cfg = this._appConfig.config;
|
cfg = this._appConfig.config,
|
||||||
|
str = this._appConfig.string;
|
||||||
|
|
||||||
timeout = setTimeout(function() {
|
timeout = setTimeout(function() {
|
||||||
hasTimedOut = true;
|
hasTimedOut = true;
|
||||||
callback(createError(HOST_TIMEOUT, this._appConfig.string.connDocHostTimeout.replace('{0}', host).replace('{1}', cfg.connDocTimeout)));
|
callback(createError(HOST_TIMEOUT, str.connDocHostTimeout.replace('{0}', host).replace('{1}', cfg.connDocTimeout)));
|
||||||
}, cfg.connDocTimeout);
|
}, cfg.connDocTimeout);
|
||||||
|
|
||||||
socket = TCPSocket.open(options.host, options.port, {
|
socket = TCPSocket.open(options.host, options.port, {
|
||||||
@ -175,14 +176,14 @@ ConnectionDoctor.prototype._checkReachable = function(options, callback) {
|
|||||||
socket.oncert = function() {
|
socket.oncert = function() {
|
||||||
if (options.ca) {
|
if (options.ca) {
|
||||||
// the certificate we already have is outdated
|
// the certificate we already have is outdated
|
||||||
error = createError(TLS_WRONG_CERT, this._appConfig.string.connDocTlsWrongCert.replace('{0}', host));
|
error = createError(TLS_WRONG_CERT, str.connDocTlsWrongCert.replace('{0}', host));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
socket.onerror = function(e) {
|
socket.onerror = function(e) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
error = createError(HOST_UNREACHABLE, this._appConfig.string.connDocHostUnreachable.replace('{0}', host), e.data);
|
error = createError(HOST_UNREACHABLE, str.connDocHostUnreachable.replace('{0}', host), e.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -207,8 +208,8 @@ ConnectionDoctor.prototype._checkReachable = function(options, callback) {
|
|||||||
ConnectionDoctor.prototype._checkImap = function(callback) {
|
ConnectionDoctor.prototype._checkImap = function(callback) {
|
||||||
var self = this,
|
var self = this,
|
||||||
loggedIn = false,
|
loggedIn = false,
|
||||||
host = self.credentials.imap.host + ':' + self.credentials.imap.port;
|
host = self.credentials.imap.host + ':' + self.credentials.imap.port,
|
||||||
|
str = this._appConfig.string;
|
||||||
|
|
||||||
self._imap.onCert = function(pemEncodedCert) {
|
self._imap.onCert = function(pemEncodedCert) {
|
||||||
if (!self.credentials.imap.ca) {
|
if (!self.credentials.imap.ca) {
|
||||||
@ -220,9 +221,9 @@ ConnectionDoctor.prototype._checkImap = function(callback) {
|
|||||||
// the global onError handler, so we need to track if login was successful
|
// the global onError handler, so we need to track if login was successful
|
||||||
self._imap.onError = function(error) {
|
self._imap.onError = function(error) {
|
||||||
if (!loggedIn) {
|
if (!loggedIn) {
|
||||||
callback(createError(AUTH_REJECTED, this._appConfig.string.connDocAuthRejected.replace('{0}', host), error));
|
callback(createError(AUTH_REJECTED, str.connDocAuthRejected.replace('{0}', host), error));
|
||||||
} else {
|
} else {
|
||||||
callback(createError(GENERIC_ERROR, this._appConfig.string.connDocGenericError.replace('{0}', host).replace('{1}', error.message), error));
|
callback(createError(GENERIC_ERROR, str.connDocGenericError.replace('{0}', host).replace('{1}', error.message), error));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -231,12 +232,12 @@ ConnectionDoctor.prototype._checkImap = function(callback) {
|
|||||||
|
|
||||||
self._imap.listWellKnownFolders(function(error, wellKnownFolders) {
|
self._imap.listWellKnownFolders(function(error, wellKnownFolders) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return callback(createError(GENERIC_ERROR, this._appConfig.string.connDocGenericError.replace('{0}', host).replace('{1}', error.message), error));
|
return callback(createError(GENERIC_ERROR, str.connDocGenericError.replace('{0}', host).replace('{1}', error.message), error));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wellKnownFolders.Inbox.length === 0) {
|
if (wellKnownFolders.Inbox.length === 0) {
|
||||||
// the client needs at least an inbox folder to work properly
|
// the client needs at least an inbox folder to work properly
|
||||||
return callback(createError(NO_INBOX, this._appConfig.string.connDocNoInbox.replace('{0}', host)));
|
return callback(createError(NO_INBOX, str.connDocNoInbox.replace('{0}', host)));
|
||||||
}
|
}
|
||||||
|
|
||||||
self._imap.logout(function() {
|
self._imap.logout(function() {
|
||||||
@ -255,7 +256,8 @@ ConnectionDoctor.prototype._checkImap = function(callback) {
|
|||||||
ConnectionDoctor.prototype._checkSmtp = function(callback) {
|
ConnectionDoctor.prototype._checkSmtp = function(callback) {
|
||||||
var self = this,
|
var self = this,
|
||||||
host = self.credentials.smtp.host + ':' + self.credentials.smtp.port,
|
host = self.credentials.smtp.host + ':' + self.credentials.smtp.port,
|
||||||
errored = false; // tracks if we need to invoke the callback at onclose or not
|
errored = false, // tracks if we need to invoke the callback at onclose or not
|
||||||
|
str = this._appConfig.string;
|
||||||
|
|
||||||
self._smtp.oncert = function(pemEncodedCert) {
|
self._smtp.oncert = function(pemEncodedCert) {
|
||||||
if (!self.credentials.smtp.ca) {
|
if (!self.credentials.smtp.ca) {
|
||||||
@ -266,7 +268,7 @@ ConnectionDoctor.prototype._checkSmtp = function(callback) {
|
|||||||
self._smtp.onerror = function(error) {
|
self._smtp.onerror = function(error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
errored = true;
|
errored = true;
|
||||||
callback(createError(AUTH_REJECTED, this._appConfig.string.connDocAuthRejected.replace('{0}', host), error));
|
callback(createError(AUTH_REJECTED, str.connDocAuthRejected.replace('{0}', host), error));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,7 +4,13 @@ var ngModule = angular.module('woUtil');
|
|||||||
ngModule.service('statusDisplay', StatusDisplay);
|
ngModule.service('statusDisplay', StatusDisplay);
|
||||||
module.exports = StatusDisplay;
|
module.exports = StatusDisplay;
|
||||||
|
|
||||||
function StatusDisplay() {}
|
/**
|
||||||
|
* A central service to display status updates to the user
|
||||||
|
*/
|
||||||
|
function StatusDisplay($q, axe) {
|
||||||
|
this._q = $q;
|
||||||
|
this._axe = axe;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the status disply in the lower left of the screen
|
* Update the status disply in the lower left of the screen
|
||||||
@ -12,7 +18,16 @@ function StatusDisplay() {}
|
|||||||
* @param {Date} time The time of the last update
|
* @param {Date} time The time of the last update
|
||||||
*/
|
*/
|
||||||
StatusDisplay.prototype.update = function(msg, time) {
|
StatusDisplay.prototype.update = function(msg, time) {
|
||||||
this.showStatus(msg, time);
|
var self = this;
|
||||||
|
self._axe.info('status display', msg);
|
||||||
|
return self._q(function(resolve, reject) {
|
||||||
|
if (self.showStatus) {
|
||||||
|
self.showStatus(msg, time);
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
reject(new Error('Status display service showStatus not set!'));
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,5 +35,13 @@ StatusDisplay.prototype.update = function(msg, time) {
|
|||||||
* @param {Boolean} state If the spinner should be displayed or not
|
* @param {Boolean} state If the spinner should be displayed or not
|
||||||
*/
|
*/
|
||||||
StatusDisplay.prototype.setSearching = function(state) {
|
StatusDisplay.prototype.setSearching = function(state) {
|
||||||
this.showSearching(state);
|
var self = this;
|
||||||
|
return self._q(function(resolve, reject) {
|
||||||
|
if (self.showSearching) {
|
||||||
|
self.showSearching(state);
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
reject(new Error('Status display service showSearching not set!'));
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
@ -15,9 +15,9 @@ var axe = require('axe-logger'),
|
|||||||
/**
|
/**
|
||||||
* Handles database migration
|
* Handles database migration
|
||||||
*/
|
*/
|
||||||
function UpdateHandler(appConfigStore, deviceStorage, auth, dialog) {
|
function UpdateHandler(appConfigStore, accountStore, auth, dialog) {
|
||||||
this._appConfigStorage = appConfigStore;
|
this._appConfigStorage = appConfigStore;
|
||||||
this._userStorage = deviceStorage;
|
this._userStorage = accountStore;
|
||||||
this._updateScripts = [updateV1, updateV2, updateV3, updateV4, updateV5];
|
this._updateScripts = [updateV1, updateV2, updateV3, updateV4, updateV5];
|
||||||
this._auth = auth;
|
this._auth = auth;
|
||||||
this._dialog = dialog;
|
this._dialog = dialog;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var btnHandler = require('../../src/js/util/backbutton-handler');
|
var btnHandler = require('../../../src/js/util/backbutton-handler');
|
||||||
|
|
||||||
describe('Backbutton Handler', function() {
|
describe('Backbutton Handler', function() {
|
||||||
chai.config.includeStack = true;
|
chai.config.includeStack = true;
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
var TCPSocket = require('tcp-socket'),
|
var TCPSocket = require('tcp-socket'),
|
||||||
ImapClient = require('imap-client'),
|
ImapClient = require('imap-client'),
|
||||||
SmtpClient = require('wo-smtpclient'),
|
SmtpClient = require('wo-smtpclient'),
|
||||||
ConnectionDoctor = require('../../src/js/util/connection-doctor'),
|
ConnectionDoctor = require('../../../src/js/util/connection-doctor'),
|
||||||
cfg = require('../../src/js/app-config').config;
|
appConfig = require('../../../src/js/app-config'),
|
||||||
|
cfg = appConfig.config;
|
||||||
|
|
||||||
describe('Connection Doctor', function() {
|
describe('Connection Doctor', function() {
|
||||||
var doctor;
|
var doctor;
|
||||||
@ -22,7 +23,7 @@ describe('Connection Doctor', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
workerPath = 'js/tcp-socket-tls-worker.min.js';
|
workerPath = '../lib/tcp-socket-tls-worker.min.js';
|
||||||
imapStub = sinon.createStubInstance(ImapClient);
|
imapStub = sinon.createStubInstance(ImapClient);
|
||||||
smtpStub = sinon.createStubInstance(SmtpClient);
|
smtpStub = sinon.createStubInstance(SmtpClient);
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ describe('Connection Doctor', function() {
|
|||||||
//
|
//
|
||||||
// Setup SUT
|
// Setup SUT
|
||||||
//
|
//
|
||||||
doctor = new ConnectionDoctor();
|
doctor = new ConnectionDoctor(appConfig);
|
||||||
doctor.configure(credentials);
|
doctor.configure(credentials);
|
||||||
doctor._imap = imapStub;
|
doctor._imap = imapStub;
|
||||||
doctor._smtp = smtpStub;
|
doctor._smtp = smtpStub;
|
||||||
|
65
test/unit/util/status-display-test.js
Normal file
65
test/unit/util/status-display-test.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Status Display Service unit test', function() {
|
||||||
|
var statusDisplay, logInfoStub;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
angular.module('statusDisplay-test', ['woUtil']);
|
||||||
|
angular.mock.module('statusDisplay-test');
|
||||||
|
angular.mock.inject(function($injector, axe) {
|
||||||
|
logInfoStub = sinon.stub(axe, 'info');
|
||||||
|
statusDisplay = $injector.get('statusDisplay');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
logInfoStub.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('update', function() {
|
||||||
|
it('should work', inject(function($rootScope) {
|
||||||
|
var message = 'Tada!',
|
||||||
|
time = new Date();
|
||||||
|
statusDisplay.showStatus = function() {};
|
||||||
|
var showStatusStub = sinon.stub(statusDisplay, 'showStatus');
|
||||||
|
|
||||||
|
statusDisplay.update(message, time).then(function(result) {
|
||||||
|
expect(result).to.not.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(logInfoStub.calledOnce).to.be.true;
|
||||||
|
$rootScope.$apply();
|
||||||
|
expect(showStatusStub.withArgs(message, time).calledOnce).to.be.true;
|
||||||
|
}));
|
||||||
|
it('should fail for no display function', inject(function($rootScope) {
|
||||||
|
statusDisplay.update().catch(function(err) {
|
||||||
|
expect(err.message).to.match(/showStatus/);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(logInfoStub.calledOnce).to.be.true;
|
||||||
|
$rootScope.$apply();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setSearching', function() {
|
||||||
|
it('should work', inject(function($rootScope) {
|
||||||
|
statusDisplay.showSearching = function() {};
|
||||||
|
var showSearchingStub = sinon.stub(statusDisplay, 'showSearching');
|
||||||
|
|
||||||
|
statusDisplay.setSearching(true).then(function(result) {
|
||||||
|
expect(result).to.not.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
$rootScope.$apply();
|
||||||
|
expect(showSearchingStub.withArgs(true).calledOnce).to.be.true;
|
||||||
|
}));
|
||||||
|
it('should fail for no display function', inject(function($rootScope) {
|
||||||
|
statusDisplay.setSearching().catch(function(err) {
|
||||||
|
expect(err.message).to.match(/showSearching/);
|
||||||
|
});
|
||||||
|
|
||||||
|
$rootScope.$apply();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -1,12 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var DeviceStorageDAO = require('../../src/js/dao/devicestorage-dao'),
|
var DeviceStorageDAO = require('../../../src/js/service/devicestorage'),
|
||||||
Auth = require('../../src/js/bo/auth'),
|
Auth = require('../../../src/js/service/auth'),
|
||||||
cfg = require('../../src/js/app-config').config,
|
cfg = require('../../../src/js/app-config').config,
|
||||||
UpdateHandler = require('../../src/js/util/update/update-handler');
|
UpdateHandler = require('../../../src/js/util/update/update-handler'),
|
||||||
|
Dialog = require('../../../src/js/util/dialog');
|
||||||
|
|
||||||
describe('UpdateHandler', function() {
|
describe('UpdateHandler', function() {
|
||||||
var updateHandler, appConfigStorageStub, authStub, userStorageStub, origDbVersion;
|
var updateHandler, appConfigStorageStub, authStub, userStorageStub, dialogStub, origDbVersion;
|
||||||
|
|
||||||
chai.config.includeStack = true;
|
chai.config.includeStack = true;
|
||||||
|
|
||||||
@ -15,7 +16,8 @@ describe('UpdateHandler', function() {
|
|||||||
appConfigStorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
appConfigStorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
||||||
userStorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
userStorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
||||||
authStub = sinon.createStubInstance(Auth);
|
authStub = sinon.createStubInstance(Auth);
|
||||||
updateHandler = new UpdateHandler(appConfigStorageStub, userStorageStub, authStub);
|
dialogStub = sinon.createStubInstance(Dialog);
|
||||||
|
updateHandler = new UpdateHandler(appConfigStorageStub, userStorageStub, authStub, dialogStub);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user