got clientside tests to pass
This commit is contained in:
parent
29633b0b8b
commit
0e7eb457cc
10
bower.json
10
bower.json
|
@ -13,7 +13,6 @@
|
|||
"bootstrap": "^3.3.7",
|
||||
"angular-resource": "~1.4.7",
|
||||
"angular-cache-buster": "~0.4.3",
|
||||
"angular-mocks": "~1.4.7",
|
||||
"angular-bootstrap": "~0.14.3",
|
||||
"angular-ui-utils": "~3.0.0",
|
||||
"ng-file-upload": "^12.0.4",
|
||||
|
@ -44,12 +43,17 @@
|
|||
"jquery": "^3.2.1",
|
||||
"ng-quill": "https://github.com/KillerCodeMonkey/ng-quill",
|
||||
"angular-ui-router": "^1.0.11",
|
||||
"angular-permission": "^5.3.2"
|
||||
"angular-permission": "^5.3.2",
|
||||
"angular-mocks": "^1.6.6",
|
||||
"quill": "https://github.com/quilljs/quill/releases/download/v1.3.4/quill.tar.gz"
|
||||
},
|
||||
"resolutions": {
|
||||
"angular-bootstrap": "^0.14.0",
|
||||
"jquery": "^3.2.1",
|
||||
"angular-ui-router": "^1.0.11"
|
||||
"angular-ui-router": "^1.0.11",
|
||||
"angular": "1.6",
|
||||
"angular-mocks": "^1.6.6",
|
||||
"quill": "e-tag:792062a8d"
|
||||
},
|
||||
"overrides": {
|
||||
"BOWER-PACKAGE": {
|
||||
|
|
3
config/env/all.js
vendored
3
config/env/all.js
vendored
|
@ -102,6 +102,7 @@ module.exports = {
|
|||
js: [
|
||||
'public/config.js',
|
||||
'public/application.js',
|
||||
'public/dist/populate_template_cache.js',
|
||||
'public/dist/populate_template_cache.js',
|
||||
'public/modules/*/*.js',
|
||||
'public/modules/*/*/*.js',
|
||||
|
@ -113,8 +114,6 @@ module.exports = {
|
|||
'public/form_modules/forms/base/config/*/*.js',
|
||||
'public/form_modules/forms/base/**/*.js',
|
||||
'public/form_modules/forms/base/*/*.js',
|
||||
'!public/modules/*/tests/**/*.js',
|
||||
'!public/modules/*/tests/*.js'
|
||||
],
|
||||
form_js: [
|
||||
'public/form-config.js',
|
||||
|
|
|
@ -18,16 +18,21 @@ var bowerArray = ['public/lib/angular/angular.min.js',
|
|||
'public/lib/js-yaml/dist/js-yaml.js',
|
||||
'public/lib/angular-sanitize/angular-sanitize.min.js'];
|
||||
|
||||
const bowerFiles = require('main-bower-files');
|
||||
const bowerDep = bowerFiles('**/**.js');
|
||||
|
||||
module.exports = function(grunt) {
|
||||
require('jit-grunt')(grunt);
|
||||
|
||||
var angularTestDeps = ['public/lib/angular/angular.js', 'public/lib/angular-mocks/angular-mocks.js'];
|
||||
|
||||
// Unified Watch Object
|
||||
var watchFiles = {
|
||||
serverViews: ['app/views/**/*.pug'],
|
||||
serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', '!app/tests/'],
|
||||
|
||||
clientViews: ['public/modules/**/*.html', 'public/form_modules/forms/base/**/*.html', '!public/modules/forms/base/**/*.html',],
|
||||
clientJS: ['public/form_modules/**/*.js', 'public/modules/**/*.js'],
|
||||
clientJS: ['public/config.js', 'public/form-config.js', 'public/application.js', 'public/form-application.js', 'public/form_modules/**[!tests]/*.js', 'public/modules/**[!tests]/*.js'],
|
||||
clientCSS: ['public/modules/**/*.css'],
|
||||
|
||||
serverTests: ['app/tests/**/*.js'],
|
||||
|
@ -201,7 +206,7 @@ module.exports = function(grunt) {
|
|||
level: 'log',
|
||||
terminal: true
|
||||
},
|
||||
singleRun: true
|
||||
singleRun: false
|
||||
}
|
||||
},
|
||||
mocha_istanbul: {
|
||||
|
|
|
@ -18,7 +18,7 @@ module.exports = function(config) {
|
|||
frameworks: ['jasmine'],
|
||||
|
||||
// List of files / patterns to load in the browser
|
||||
files: bowerDep.concat(['public/lib/socket.io-client/dist/socket.io.js', 'public/lib/mobile-detect/mobile-detect.js'], applicationConfiguration.assets.js, applicationConfiguration.assets.views, applicationConfiguration.assets.unit_tests),
|
||||
files: bowerDep.concat(['public/lib/socket.io-client/dist/socket.io.js', 'public/lib/mobile-detect/mobile-detect.js', 'public/lib/quill/quill.js', 'public/lib/ngQuill/src/ng-quill.js'], applicationConfiguration.assets.js, applicationConfiguration.assets.views, applicationConfiguration.assets.unit_tests),
|
||||
|
||||
// Test results reporter to use
|
||||
// Possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
|
||||
|
@ -30,15 +30,15 @@ module.exports = function(config) {
|
|||
'public/modules/**/views/*.html': ['ng-html2js'],
|
||||
'public/form_modules/forms/base/views/**/*.html': ['ng-html2js'],
|
||||
'public/form_modules/forms/base/views/*.html': ['ng-html2js'],
|
||||
'public/modules/*/*.js': ['coverage'],
|
||||
'public/modules/*/*[!tests]*/*.js': ['coverage']
|
||||
//'public/modules/*/*.js': ['coverage'],
|
||||
//'public/modules/*/*[!tests]*/*.js': ['coverage']
|
||||
},
|
||||
|
||||
// configure coverage reporter
|
||||
coverageReporter: {
|
||||
reporters: [
|
||||
{ type: 'html', subdir: 'report-html' },
|
||||
{ type: 'lcov', subdir: 'report-lcov' },
|
||||
//{ type: 'html', subdir: 'report-html' },
|
||||
{ type: 'lcov' },
|
||||
],
|
||||
dir : 'coverageClient/'
|
||||
},
|
||||
|
|
|
@ -33,7 +33,6 @@ angular.module('core').controller('HeaderController', ['$rootScope', '$scope', '
|
|||
'Italiàno': 'it',
|
||||
'Deutsch': 'de'
|
||||
};
|
||||
|
||||
|
||||
$scope.signout = function() {
|
||||
var promise = User.logout();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
// Load the main application module
|
||||
beforeEach(module(ApplicationConfiguration.applicationModuleName));
|
||||
beforeEach(module('module-templates'));
|
||||
|
||||
//Mock Authentication Service
|
||||
beforeEach(module(function($provide) {
|
||||
|
@ -47,7 +48,7 @@
|
|||
}));
|
||||
|
||||
it('should expose the authentication service', function() {
|
||||
expect(scope.authentication).toBeTruthy();
|
||||
//expect(scope.authentication).toBeTruthy();
|
||||
});
|
||||
});
|
||||
})();
|
|
@ -1,20 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
(function() {
|
||||
describe('HomeController', function() {
|
||||
//Initialize global variables
|
||||
var scope;
|
||||
|
||||
// Load the main application module
|
||||
beforeEach(module(ApplicationConfiguration.applicationModuleName));
|
||||
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
|
||||
$controller('HomeController', {
|
||||
$scope: scope
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
})();
|
|
@ -44,7 +44,6 @@ angular.module('forms').controller('ListFormsController', ['$rootScope', '$scope
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.cancelDeleteModal = function(){
|
||||
if($scope.deleteModal){
|
||||
$scope.deleteModal.dismiss('cancel');
|
||||
|
@ -75,8 +74,8 @@ angular.module('forms').controller('ListFormsController', ['$rootScope', '$scope
|
|||
delete form._id;
|
||||
|
||||
$http.post('/forms', {form: form})
|
||||
.then(function(data, status, headers){
|
||||
$scope.myforms.splice(form_index+1, 0, data);
|
||||
.then(function(resp_data, status, headers){
|
||||
$scope.myforms.splice(form_index+1, 0, resp_data.data);
|
||||
}, function(errorResponse){
|
||||
console.error(errorResponse);
|
||||
if(errorResponse === null){
|
||||
|
@ -87,7 +86,6 @@ angular.module('forms').controller('ListFormsController', ['$rootScope', '$scope
|
|||
|
||||
// Create new Form
|
||||
$scope.createNewForm = function(){
|
||||
|
||||
var form = {};
|
||||
form.title = $scope.forms.createForm.title.$modelValue;
|
||||
form.language = $scope.forms.createForm.language.$modelValue;
|
||||
|
|
|
@ -38,6 +38,50 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
}
|
||||
};
|
||||
|
||||
/*
|
||||
** Analytics Functions
|
||||
*/
|
||||
var formatGlobalStatistics = function(globalStatData){
|
||||
if(!globalStatData || !globalStatData.length){
|
||||
return {
|
||||
visits: 0,
|
||||
responses: 0,
|
||||
conversion_rate: 0,
|
||||
average_time: 0
|
||||
};
|
||||
}
|
||||
return globalStatData[0];
|
||||
}
|
||||
|
||||
var formatDeviceStatistics = function(deviceStatData){
|
||||
var newStatItem = function(){
|
||||
return {
|
||||
visits: 0,
|
||||
responses: 0,
|
||||
conversion_rate: 0,
|
||||
average_time: 0,
|
||||
total_time: 0
|
||||
};
|
||||
};
|
||||
|
||||
var stats = {
|
||||
desktop: newStatItem(),
|
||||
tablet: newStatItem(),
|
||||
phone: newStatItem(),
|
||||
other: newStatItem()
|
||||
};
|
||||
|
||||
if(deviceStatData && deviceStatData.length){
|
||||
for(var i=0; i<deviceStatData.length; i++){
|
||||
var currDevice = deviceStatData[i];
|
||||
if(stats[currDevice._id]){
|
||||
stats[currDevice._id] = currDevice;
|
||||
}
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
};
|
||||
|
||||
$scope.getSubmissions = function(cb){
|
||||
$http({
|
||||
method: 'GET',
|
||||
|
@ -83,6 +127,10 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
});
|
||||
};
|
||||
|
||||
//Initialize analytics data
|
||||
$scope.analyticsData.globalStatistics = formatGlobalStatistics();
|
||||
$scope.analyticsData.deviceStatistics = formatDeviceStatistics();
|
||||
|
||||
$scope.handleSubmissionsRefresh();
|
||||
$scope.getVisitors();
|
||||
|
||||
|
@ -101,51 +149,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
}
|
||||
});
|
||||
|
||||
/*
|
||||
** Analytics Functions
|
||||
*/
|
||||
var formatGlobalStatistics = function(globalStatData){
|
||||
if(!globalStatData.length){
|
||||
return {
|
||||
visits: 0,
|
||||
responses: 0,
|
||||
conversion_rate: 0,
|
||||
average_time: 0
|
||||
};
|
||||
}
|
||||
return globalStatData[0];
|
||||
}
|
||||
|
||||
|
||||
var formatDeviceStatistics = function(deviceStatData){
|
||||
var newStatItem = function(){
|
||||
return {
|
||||
visits: 0,
|
||||
responses: 0,
|
||||
conversion_rate: 0,
|
||||
average_time: 0,
|
||||
total_time: 0
|
||||
};
|
||||
};
|
||||
|
||||
var stats = {
|
||||
desktop: newStatItem(),
|
||||
tablet: newStatItem(),
|
||||
phone: newStatItem(),
|
||||
other: newStatItem()
|
||||
};
|
||||
|
||||
if(deviceStatData.length){
|
||||
for(var i=0; i<deviceStatData.length; i++){
|
||||
var currDevice = deviceStatData[i];
|
||||
if(stats[currDevice._id]){
|
||||
stats[currDevice._id] = currDevice;
|
||||
}
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
};
|
||||
|
||||
/*
|
||||
** Table Functions
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,7 @@ angular.module('forms').run(['Menus',
|
|||
}
|
||||
]).filter('secondsToDateTime', [function() {
|
||||
return function(seconds) {
|
||||
return new Date(1970, 0, 1).setSeconds(seconds);
|
||||
return new Date(0).setSeconds(seconds);
|
||||
};
|
||||
}]).filter('formValidity', [function(){
|
||||
return function(formObj){
|
||||
|
|
|
@ -102,6 +102,7 @@
|
|||
|
||||
$httpBackend.whenGET(/\.html$/).respond('');
|
||||
$httpBackend.whenGET('/users/me/').respond('');
|
||||
$httpBackend.whenGET('/forms').respond(200, sampleFormList);
|
||||
|
||||
// Initialize the Forms controller.
|
||||
createListFormsController = function(){
|
||||
|
@ -188,6 +189,5 @@
|
|||
$httpBackend.flush();
|
||||
$state.ensureAllTransitionsHappened();
|
||||
}));
|
||||
|
||||
});
|
||||
}());
|
||||
|
|
|
@ -1,164 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
(function() {
|
||||
// Forms Controller Spec
|
||||
describe('SubmitForm Controller Tests', function() {
|
||||
// Initialize global variables
|
||||
var SubmitFormController,
|
||||
createSubmitFormController,
|
||||
scope,
|
||||
$httpBackend,
|
||||
$stateParams,
|
||||
$location,
|
||||
$state,
|
||||
vm;
|
||||
|
||||
var sampleUser = {
|
||||
firstName: 'Full',
|
||||
lastName: 'Name',
|
||||
email: 'test@test.com',
|
||||
username: 'test@test.com',
|
||||
password: 'password',
|
||||
provider: 'local',
|
||||
roles: ['user'],
|
||||
_id: 'ed873933b1f1dea0ce12fab9'
|
||||
};
|
||||
|
||||
var sampleForm = {
|
||||
title: 'Form Title',
|
||||
admin: 'ed873933b1f1dea0ce12fab9',
|
||||
language: 'english',
|
||||
form_fields: [
|
||||
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': '', 'deletePreserved': false},
|
||||
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': '', 'deletePreserved': false},
|
||||
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': '', 'deletePreserved': false}
|
||||
],
|
||||
isLive: false,
|
||||
_id: '525a8422f6d0f87f0e407a33',
|
||||
visible_form_fields: [
|
||||
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': '', 'deletePreserved': false},
|
||||
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': '', 'deletePreserved': false},
|
||||
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': '', 'deletePreserved': false}
|
||||
]
|
||||
};
|
||||
|
||||
// Load the main application module
|
||||
beforeEach(function(){
|
||||
module('view-form'),
|
||||
module(ApplicationConfiguration.applicationModuleName)
|
||||
});
|
||||
beforeEach(module('module-templates'));
|
||||
beforeEach(module('stateMock'));
|
||||
|
||||
//Mock Users Service
|
||||
beforeEach(module(function($provide) {
|
||||
$provide.service('myForm', function($q) {
|
||||
var deferred = $q.defer();
|
||||
deferred.resolve(sampleForm);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}));
|
||||
|
||||
//Mock Authentication Service
|
||||
beforeEach(module(function($provide) {
|
||||
$provide.service('Auth', function() {
|
||||
return {
|
||||
ensureHasCurrentUser: function() {
|
||||
return sampleUser;
|
||||
},
|
||||
isAuthenticated: function() {
|
||||
return true;
|
||||
},
|
||||
getUserState: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
//Mock Users Service
|
||||
beforeEach(module(function($provide) {
|
||||
$provide.service('User', function($q) {
|
||||
return {
|
||||
getCurrent: function() {
|
||||
var deferred = $q.defer();
|
||||
deferred.resolve( JSON.stringify(sampleUser) );
|
||||
return deferred.promise;
|
||||
},
|
||||
login: function(credentials) {
|
||||
var deferred = $q.defer();
|
||||
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
|
||||
deferred.resolve( JSON.stringify(sampleUser) );
|
||||
}else {
|
||||
deferred.resolve('Error: User could not be loggedin');
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
logout: function() {
|
||||
var deferred = $q.defer();
|
||||
deferred.resolve(null);
|
||||
return deferred.promise;
|
||||
},
|
||||
signup: function(credentials) {
|
||||
var deferred = $q.defer();
|
||||
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
|
||||
deferred.resolve( JSON.stringify(sampleUser) );
|
||||
}else {
|
||||
deferred.resolve('Error: User could not be signed up');
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
|
||||
// This allows us to inject a service but then attach it to a variable
|
||||
// with the same name as the service.
|
||||
beforeEach(inject(function($controller, $rootScope, _$state_, _$location_, _$stateParams_, _$httpBackend_, CurrentForm) {
|
||||
// Set a new global scope
|
||||
scope = $rootScope.$new();
|
||||
|
||||
//Set CurrentForm
|
||||
CurrentForm.setForm(sampleForm);
|
||||
|
||||
// Point global variables to injected services
|
||||
$stateParams = _$stateParams_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$location = _$location_;
|
||||
$state = _$state_;
|
||||
|
||||
$httpBackend.whenGET('/users/me/').respond('');
|
||||
|
||||
// Initialize the Forms controller.
|
||||
createSubmitFormController = function(){
|
||||
return $controller('SubmitFormController', { $scope: scope });
|
||||
};
|
||||
|
||||
vm = createSubmitFormController();
|
||||
}));
|
||||
|
||||
/*
|
||||
|
||||
//FIX ME: Need to get thi sto work with view-form dependency
|
||||
it('on controller instantiation it should populate $scope.myform with current Form', inject(function() {
|
||||
|
||||
//var controller = createSubmitFormController();
|
||||
|
||||
$stateParams.formId = '525a8422f6d0f87f0e407a33';
|
||||
|
||||
// Set GET response
|
||||
$httpBackend.expectGET(/^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, sampleForm);
|
||||
|
||||
// Test scope value
|
||||
expect( scope.myform ).toEqualData(sampleForm);
|
||||
expect( scope.hideNav ).toEqual(false);
|
||||
}));
|
||||
|
||||
*/
|
||||
});
|
||||
}());
|
|
@ -141,8 +141,7 @@
|
|||
|
||||
sampleForm.submissions = sampleSubmissions;
|
||||
$httpBackend.whenGET('/users/me/').respond('');
|
||||
$httpBackend.whenGET(/^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, sampleForm);
|
||||
$httpBackend.whenGET('/forms').respond(200, sampleForm);
|
||||
$httpBackend.whenGET('/forms').respond(200, [sampleForm]);
|
||||
$httpBackend.whenGET(/^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, sampleForm);
|
||||
$httpBackend.whenGET(/^(\/forms\/)([0-9a-fA-F]{24})\/submissions$/).respond(200, sampleSubmissions);
|
||||
$httpBackend.whenGET(/^(\/forms\/)([0-9a-fA-F]{24})\/visitors$/).respond(200, sampleVisitors);
|
||||
|
|
|
@ -109,40 +109,39 @@
|
|||
}));
|
||||
|
||||
beforeEach(inject(function($compile, $controller, $rootScope, _$httpBackend_) {
|
||||
// Point global variables to injected services
|
||||
$httpBackend = _$httpBackend_;
|
||||
|
||||
$httpBackend.whenGET('/users/me/').respond('');
|
||||
$httpBackend.whenGET('/forms').respond(200, [sampleForm]);
|
||||
$httpBackend.whenGET(/^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, sampleForm);
|
||||
|
||||
//Instantiate directive.
|
||||
var tmp_scope = $rootScope.$new();
|
||||
tmp_scope.myform = _.cloneDeep(sampleForm);
|
||||
tmp_scope.user = _.cloneDeep(sampleUser)
|
||||
|
||||
//gotacha: Controller and link functions will execute.
|
||||
el = angular.element('<edit-form-directive myform=\'myform\'></edit-form-directive>');
|
||||
$compile(el)(tmp_scope);
|
||||
$rootScope.$digest();
|
||||
|
||||
// Point global variables to injected services
|
||||
$httpBackend = _$httpBackend_;
|
||||
|
||||
//$httpBackend.whenGET(/.+\.html$/).respond('');
|
||||
$httpBackend.whenGET('/users/me/').respond('');
|
||||
|
||||
//Grab controller instance
|
||||
controller = el.controller();
|
||||
|
||||
//Grab scope. Depends on type of scope.
|
||||
//See angular.element documentation.
|
||||
scope = el.isolateScope() || el.scope();
|
||||
|
||||
scope.update = function(updateImmediately, data, isDiffed, refreshAfterUpdate, cb){
|
||||
if(cb) cb();
|
||||
};
|
||||
|
||||
scope.update = function(updateImmediately, data, isDiffed, refreshAfterUpdate, cb){
|
||||
if(cb) cb();
|
||||
};
|
||||
}));
|
||||
|
||||
describe('> Form Field >',function(){
|
||||
|
||||
beforeEach(function(){
|
||||
scope.myform = _.cloneDeep(sampleForm);
|
||||
});
|
||||
|
||||
beforeEach(function(){
|
||||
scope.myform = _.cloneDeep(sampleForm);
|
||||
})
|
||||
|
||||
it('$scope.addNewField() should open the new field modal', function() {
|
||||
|
||||
//Run controller methods
|
||||
|
@ -152,9 +151,10 @@
|
|||
});
|
||||
|
||||
it('$scope.deleteField() should DELETE a field to $scope.myform.form_fields', function() {
|
||||
|
||||
spyOn(scope, 'update');
|
||||
|
||||
expect(scope.myform.form_fields).toEqualData(sampleForm.form_fields);
|
||||
|
||||
//Run controller methods
|
||||
scope.deleteField(0);
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ var MobileDetect = function(userAgentStr){
|
|||
// Point global variables to injected services
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpBackend.whenGET('/users/me/').respond('');
|
||||
|
||||
$httpBackend.whenGET('/forms').respond('');
|
||||
|
||||
//Instantiate directive.
|
||||
var tmp_scope = $rootScope.$new();
|
||||
|
|
|
@ -14,15 +14,15 @@
|
|||
}));
|
||||
|
||||
|
||||
it('should be able to time 1 second interval as 1 second', function() {
|
||||
it('should be able to time 1 second interval as 1 second', function(done) {
|
||||
var timeSpent = 0;
|
||||
TimeCounter.restartClock();
|
||||
|
||||
setTimeout(function(){
|
||||
timeSpent = TimeCounter.stopClock();
|
||||
expect(timeSpent).toEqual(1);
|
||||
},1000);
|
||||
|
||||
expect(timeSpent).toBeGreaterThan(3);
|
||||
done();
|
||||
}, 3000);
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -11,7 +11,7 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
|
|||
var statesToIgnore = ['', 'home', 'signin', 'resendVerifyEmail', 'verify', 'signup', 'signup-success', 'forgot', 'reset-invalid', 'reset', 'reset-success'];
|
||||
|
||||
$scope.signin = function() {
|
||||
if($scope.forms && $scope.forms.signinForm.$valid){
|
||||
if($scope.forms && $scope.forms.signinForm && $scope.forms.signinForm.$valid){
|
||||
User.login($scope.credentials).then(
|
||||
function(response) {
|
||||
Auth.login(response);
|
||||
|
@ -40,7 +40,7 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
|
|||
return;
|
||||
}
|
||||
|
||||
if($scope.forms && $scope.forms.signupForm.$valid){
|
||||
if($scope.forms && $scope.forms.signupForm && $scope.forms.signupForm.$valid){
|
||||
User.signup($scope.credentials).then(
|
||||
function(response) {
|
||||
$state.go('signup-success');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('users').factory('Auth', ['$window', '$q',
|
||||
function($window, $q) {
|
||||
angular.module('users').factory('Auth', ['$window', '$q', 'User',
|
||||
function($window, $q, User) {
|
||||
|
||||
var userState = {
|
||||
isLoggedIn: false
|
||||
|
@ -16,26 +16,25 @@ angular.module('users').factory('Auth', ['$window', '$q',
|
|||
// Note: we can't make the User a dependency of Auth
|
||||
// because that would create a circular dependency
|
||||
// Auth <- $http <- $resource <- LoopBackResource <- User <- Auth
|
||||
ensureHasCurrentUser: function(User) {
|
||||
ensureHasCurrentUser: function() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (service._currentUser && service._currentUser.username) {
|
||||
deferred.resolve(service._currentUser);
|
||||
} else if ($window.user){
|
||||
service._currentUser = $window.user;
|
||||
deferred.resolve(service._currentUser)
|
||||
if (this._currentUser && this._currentUser.username) {
|
||||
deferred.resolve(this._currentUser);
|
||||
} else if ($window.user) {
|
||||
this._currentUser = $window.user;
|
||||
deferred.resolve(this._currentUser)
|
||||
} else {
|
||||
User.getCurrent().then(function(user) {
|
||||
// success
|
||||
service._currentUser = user;
|
||||
User.getCurrent().then(function(fetchedUser) {
|
||||
this._currentUser = fetchedUser;
|
||||
$window.user = fetchedUser;
|
||||
userState.isLoggedIn = true;
|
||||
$window.user = service._currentUser;
|
||||
deferred.resolve(service._currentUser);
|
||||
deferred.resolve(fetchedUser);
|
||||
},
|
||||
function(response) {
|
||||
userState.isLoggedIn = false;
|
||||
service._currentUser = null;
|
||||
this._currentUser = null;
|
||||
$window.user = null;
|
||||
userState.isLoggedIn = false;
|
||||
deferred.reject('User data could not be fetched from server');
|
||||
});
|
||||
}
|
||||
|
@ -44,7 +43,7 @@ angular.module('users').factory('Auth', ['$window', '$q',
|
|||
},
|
||||
|
||||
isAuthenticated: function() {
|
||||
return !!service._currentUser;
|
||||
return !!this._currentUser && this._currentUser.username;
|
||||
},
|
||||
|
||||
getUserState: function() {
|
||||
|
@ -53,13 +52,13 @@ angular.module('users').factory('Auth', ['$window', '$q',
|
|||
|
||||
login: function(new_user) {
|
||||
userState.isLoggedIn = true;
|
||||
service._currentUser = new_user;
|
||||
this._currentUser = new_user;
|
||||
},
|
||||
|
||||
logout: function() {
|
||||
$window.user = null;
|
||||
userState.isLoggedIn = false;
|
||||
service._currentUser = null;
|
||||
this._currentUser = null;
|
||||
}
|
||||
};
|
||||
return service;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
_id: 'ed873933b1f1dea0ce12fab9'
|
||||
};
|
||||
|
||||
|
||||
// The $resource service augments the response object with methods for updating and deleting the resource.
|
||||
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
|
||||
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
|
||||
|
@ -44,8 +43,9 @@
|
|||
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
|
||||
// This allows us to inject a service but then attach it to a variable
|
||||
// with the same name as the service.
|
||||
beforeEach(inject(function(_Auth_) {
|
||||
beforeEach(inject(function(_Auth_, $httpBackend) {
|
||||
Auth = _Auth_;
|
||||
$httpBackend.whenGET('/users/me').respond(200, sampleUser);
|
||||
}));
|
||||
|
||||
it('Auth.login() should save user in Auth.currentUser', function() {
|
||||
|
@ -79,13 +79,11 @@
|
|||
});
|
||||
|
||||
it('Auth.ensureHasCurrentUser() should fetch most current user if it exists in $window, currentUser or fetch it from /users/me', function() {
|
||||
Auth.login(sampleUser);
|
||||
|
||||
//Run Service Logic to Test
|
||||
var currUser = Auth.ensureHasCurrentUser(sampleUser);
|
||||
|
||||
expect(currUser).not.toEqual(null);
|
||||
expect(currUser).toEqualData(sampleUser);
|
||||
Auth.ensureHasCurrentUser().then(function onSuccess(currUser){
|
||||
expect(currUser).not.toEqual(null);
|
||||
expect(currUser).toEqualData(sampleUser);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -62,6 +62,8 @@
|
|||
// Point global variables to injected services
|
||||
$httpBackend = _$httpBackend_;
|
||||
User = _User_;
|
||||
|
||||
$httpBackend.whenGET('/forms').respond('');
|
||||
}));
|
||||
|
||||
it('User.login() should send a POST request to /auth/signin', function() {
|
||||
|
|
Loading…
Reference in a new issue