1
0
mirror of https://github.com/moparisthebest/mail synced 2024-10-31 23:35:03 -04:00
mail/test/unit/controller/login/create-account-ctrl-test.js

88 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-11-10 12:36:26 -05:00
'use strict';
2014-11-25 12:19:40 -05:00
var CreateAccountCtrl = require('../../../../src/js/controller/login/create-account'),
AdminDao = require('../../../../src/js/service/admin'),
Auth = require('../../../../src/js/service/auth');
2014-11-10 12:36:26 -05:00
describe('Create Account Controller unit test', function() {
2014-11-25 12:19:40 -05:00
var scope, location, ctrl, authStub, adminStub;
2014-11-10 12:36:26 -05:00
beforeEach(function() {
// remember original module to restore later, then replace it
2014-11-25 12:19:40 -05:00
adminStub = sinon.createStubInstance(AdminDao);
authStub = sinon.createStubInstance(Auth);
2014-11-10 12:36:26 -05:00
2014-11-25 12:19:40 -05:00
angular.module('createaccounttest', ['woServices', 'woAppConfig']);
angular.mock.module('createaccounttest');
angular.mock.inject(function($controller, $rootScope, $location) {
2014-11-10 12:36:26 -05:00
location = $location;
scope = $rootScope.$new();
scope.state = {};
scope.form = {};
scope.formValidate = {};
sinon.stub(location, 'path').returns(location);
sinon.stub(location, 'search').returns(location);
sinon.stub(scope, '$apply', function() {});
ctrl = $controller(CreateAccountCtrl, {
$location: location,
$scope: scope,
2014-11-25 12:19:40 -05:00
$routeParams: {},
auth: authStub,
admin: adminStub
2014-11-10 12:36:26 -05:00
});
});
});
afterEach(function() {
location.path.restore();
location.search.restore();
if (scope.$apply.restore) {
scope.$apply.restore();
}
});
describe('createWhiteoutAccount', function() {
it('should return early for invalid form', function() {
scope.form.$invalid = true;
scope.createWhiteoutAccount();
expect(adminStub.createUser.called).to.be.false;
});
it('should fail to error creating user', function(done) {
scope.form.$invalid = false;
scope.betaCode = 'asfd';
scope.phone = '12345';
adminStub.createUser.yieldsAsync(new Error('asdf'));
scope.$apply = function() {
expect(scope.busy).to.be.false;
expect(scope.errMsg).to.equal('asdf');
expect(adminStub.createUser.calledOnce).to.be.true;
done();
};
scope.createWhiteoutAccount();
expect(scope.busy).to.be.true;
});
it('should work', function(done) {
scope.form.$invalid = false;
scope.betaCode = 'asfd';
scope.phone = '12345';
adminStub.createUser.yieldsAsync();
scope.$apply = function() {
expect(scope.busy).to.be.false;
expect(scope.errMsg).to.be.undefined;
expect(adminStub.createUser.calledOnce).to.be.true;
done();
};
scope.createWhiteoutAccount();
expect(scope.busy).to.be.true;
});
});
});