2014-01-27 12:50:13 -05:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var expect = chai.expect,
|
|
|
|
angular = require('angular'),
|
|
|
|
mocks = require('angularMocks'),
|
|
|
|
AddAccountCtrl = require('js/controller/add-account'),
|
2014-04-01 07:16:39 -04:00
|
|
|
Auth = require('js/bo/auth'),
|
2014-01-27 12:50:13 -05:00
|
|
|
appController = require('js/app-controller');
|
|
|
|
|
|
|
|
describe('Add Account Controller unit test', function() {
|
2014-04-01 07:16:39 -04:00
|
|
|
var scope, location, ctrl, authStub;
|
2014-01-27 12:50:13 -05:00
|
|
|
|
|
|
|
describe('connectToGoogle', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
// remember original module to restore later, then replace it
|
2014-04-01 07:16:39 -04:00
|
|
|
appController._auth = authStub = sinon.createStubInstance(Auth);
|
2014-01-27 12:50:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
// restore the app controller module
|
|
|
|
location && location.path && location.path.restore && location.path.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail on fetchOAuthToken error', function(done) {
|
|
|
|
angular.module('addaccounttest', []);
|
|
|
|
mocks.module('addaccounttest');
|
|
|
|
mocks.inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
scope.state = {};
|
|
|
|
ctrl = $controller(AddAccountCtrl, {
|
|
|
|
$location: location,
|
|
|
|
$scope: scope
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
scope.onError = function(err) {
|
|
|
|
expect(err).to.equal(42);
|
2014-04-01 07:16:39 -04:00
|
|
|
expect(authStub.getCredentials.calledOnce).to.be.true;
|
2014-01-27 12:50:13 -05:00
|
|
|
done();
|
|
|
|
};
|
2014-04-01 07:16:39 -04:00
|
|
|
authStub.getCredentials.yields(42);
|
2014-01-27 12:50:13 -05:00
|
|
|
|
|
|
|
scope.connectToGoogle();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should forward to login', function(done) {
|
|
|
|
angular.module('addaccounttest', []);
|
|
|
|
mocks.module('addaccounttest');
|
|
|
|
mocks.inject(function($controller, $rootScope, $location) {
|
|
|
|
location = $location;
|
2014-02-06 05:55:24 -05:00
|
|
|
scope = $rootScope.$new();
|
|
|
|
scope.state = {};
|
|
|
|
|
2014-01-27 12:50:13 -05:00
|
|
|
sinon.stub(location, 'path', function(path) {
|
|
|
|
expect(path).to.equal('/login');
|
2014-04-01 07:16:39 -04:00
|
|
|
expect(authStub.getCredentials.calledOnce).to.be.true;
|
2014-02-06 05:55:24 -05:00
|
|
|
|
|
|
|
location.path.restore();
|
|
|
|
scope.$apply.restore();
|
2014-01-27 12:50:13 -05:00
|
|
|
done();
|
|
|
|
});
|
2014-02-06 05:55:24 -05:00
|
|
|
|
|
|
|
sinon.stub(scope, '$apply', function() {});
|
|
|
|
|
2014-01-27 12:50:13 -05:00
|
|
|
ctrl = $controller(AddAccountCtrl, {
|
|
|
|
$location: location,
|
|
|
|
$scope: scope
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-01 07:16:39 -04:00
|
|
|
authStub.getCredentials.yields();
|
2014-01-27 12:50:13 -05:00
|
|
|
|
|
|
|
scope.connectToGoogle();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|