1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-16 06:05:07 -05:00
mail/test/unit/controller/login/login-set-credentials-ctrl-test.js

96 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-11-25 12:19:40 -05:00
var Auth = require('../../../../src/js/service/auth'),
ConnectionDoctor = require('../../../../src/js/util/connection-doctor'),
SetCredentialsCtrl = require('../../../../src/js/controller/login/login-set-credentials');
2014-10-07 14:32:23 -04:00
describe('Login (Set Credentials) Controller unit test', function() {
// Angular parameters
var scope, location, provider;
2014-10-07 14:32:23 -04:00
// Stubs
2014-11-25 12:19:40 -05:00
var auth, doctor;
2014-10-07 14:32:23 -04:00
// SUT
var setCredentialsCtrl;
2014-10-07 14:32:23 -04:00
beforeEach(function() {
// remeber pre-test state to restore later
2014-11-25 12:19:40 -05:00
auth = sinon.createStubInstance(Auth);
doctor = sinon.createStubInstance(ConnectionDoctor);
2014-10-07 14:32:23 -04:00
// setup the controller
angular.module('setcredentialstest', []);
2014-11-25 12:19:40 -05:00
angular.mock.module('setcredentialstest');
angular.mock.inject(function($rootScope, $controller, $location) {
2014-10-07 14:32:23 -04:00
scope = $rootScope.$new();
location = $location;
location.search({
provider: provider
});
scope.state = {
login: {
mailConfig: {
imap: {},
smtp: {}
}
}
};
2014-10-07 14:32:23 -04:00
setCredentialsCtrl = $controller(SetCredentialsCtrl, {
$scope: scope,
2014-11-25 12:19:40 -05:00
$routeParams: {},
2014-12-18 09:19:06 -05:00
$q: window.qMock,
2014-11-25 12:19:40 -05:00
auth: auth,
connectionDoctor: doctor
});
});
2014-10-07 14:32:23 -04:00
});
2014-11-25 12:19:40 -05:00
afterEach(function() {});
2014-10-07 14:32:23 -04:00
describe('set credentials', function() {
2014-12-18 09:19:06 -05:00
it('should work', function(done) {
2014-10-07 14:32:23 -04:00
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';
2014-10-07 14:32:23 -04:00
var expectedCredentials = {
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
2014-10-07 14:32:23 -04:00
},
smtp: {
host: scope.smtpHost.toLowerCase(),
port: scope.smtpPort,
secure: false,
ignoreTLS: false
2014-10-07 14:32:23 -04:00
}
};
2014-12-18 09:19:06 -05:00
doctor.check.returns(resolves()); // synchronous yields!
2014-12-18 09:19:06 -05:00
scope.test().then(function() {
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;
done();
});
});
});
});