1
0
mirror of https://github.com/moparisthebest/mail synced 2024-08-13 16:43:47 -04:00
mail/test/unit/login-set-credentials-ctrl-test.js
Felix Hammerl 77e0377fd1 [WO-563] Introduce connection doctor
* Uses predefined error messages from the config
* Show error and underlying error in login screen
2014-09-23 16:21:12 +02:00

101 lines
3.6 KiB
JavaScript

define(function(require) {
'use strict';
var expect = chai.expect,
angular = require('angular'),
mocks = require('angularMocks'),
Auth = require('js/bo/auth'),
ConnectionDoctor = require('js/util/connection-doctor'),
SetCredentialsCtrl = require('js/controller/login-set-credentials'),
appController = require('js/app-controller');
describe('Login (Set Credentials) Controller unit test', function() {
// Angular parameters
var scope, location, provider;
// Stubs
var auth, origAuth, doctor, origDoctor;
// SUT
var setCredentialsCtrl;
beforeEach(function() {
// remeber pre-test state to restore later
origAuth = appController._auth;
origDoctor = appController._doctor;
auth = appController._auth = sinon.createStubInstance(Auth);
doctor = appController._doctor = sinon.createStubInstance(ConnectionDoctor);
// setup the controller
angular.module('setcredentialstest', []);
mocks.module('setcredentialstest');
mocks.inject(function($rootScope, $controller, $location) {
scope = $rootScope.$new();
location = $location;
location.search({
provider: provider
});
scope.state = {};
setCredentialsCtrl = $controller(SetCredentialsCtrl, {
$scope: scope,
$routeParams: {}
});
});
});
afterEach(function() {
// restore pre-test state
appController._auth = origAuth;
appController._doctor = origDoctor;
});
describe('set credentials', function() {
it('should work', function() {
scope.emailAddress = 'emailemailemailemail';
scope.password = 'passwdpasswdpasswdpasswd';
scope.smtpHost = 'hosthosthost';
scope.smtpPort = 1337;
scope.smtpEncryption = '1'; // STARTTLS
scope.imapHost = 'hosthosthost';
scope.imapPort = 1337;
scope.imapEncryption = '2'; // TLS
scope.realname = 'peter pan';
var expectedCredentials = {
provider: provider,
emailAddress: scope.emailAddress,
username: scope.username || scope.emailAddress,
realname: scope.realname,
password: scope.password,
xoauth2: undefined,
imap: {
host: scope.imapHost.toLowerCase(),
port: scope.imapPort,
secure: true,
ignoreTLS: false,
ca: undefined,
pinned: false
},
smtp: {
host: scope.smtpHost.toLowerCase(),
port: scope.smtpPort,
secure: false,
ignoreTLS: false,
ca: undefined,
pinned: false
}
};
doctor.check.yields(); // synchronous yields!
scope.test();
expect(doctor.check.calledOnce).to.be.true;
expect(doctor.configure.calledOnce).to.be.true;
expect(doctor.configure.calledWith(expectedCredentials)).to.be.true;
expect(auth.setCredentials.calledOnce).to.be.true;
});
});
});
});