Commit 46d0277c authored by Evren Kutar's avatar Evren Kutar

FIX http500 error show on ui and prepare test for interceptors ADD cross browser units tests

rfix #5102
parent a51aa6c0
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* (GPLv3). See LICENSE.txt for details. * (GPLv3). See LICENSE.txt for details.
*/ */
'use strict'; 'use strict';
describe('dashboard controller module', function () { describe('dashboard controller module', function () {
...@@ -30,12 +30,13 @@ describe('dashboard controller module', function () { ...@@ -30,12 +30,13 @@ describe('dashboard controller module', function () {
expect('ulakbus.dashboard.DashCtrl').toBeDefined(); expect('ulakbus.dashboard.DashCtrl').toBeDefined();
})); }));
// todo: complete dashboard tests
it('should execute DashCtrl functions', inject(function ($rootScope, RESTURL) { it('should execute DashCtrl functions', inject(function ($rootScope, RESTURL) {
$httpBackend.expectGET(RESTURL.url + 'ara/personel/123') $httpBackend.expectGET(RESTURL.url + 'ara/personel/123')
.respond(200, {}); .respond(200, {});
var $scope = $rootScope.$new(); var $scope = $rootScope.$new();
var controller = $controller('DashCtrl', { $scope: $scope }); var controller = $controller('DashCtrl', {$scope: $scope});
$scope.student_kw = "123"; $scope.student_kw = "123";
$scope.staff_kw = "123"; $scope.staff_kw = "123";
......
...@@ -805,41 +805,42 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -805,41 +805,42 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
} }
}); });
}; };
/** ///**
* @memberof ulakbus.formService // * @memberof ulakbus.formService
* @ngdoc function // * @ngdoc function
* @name isValidEmail // * @name isValidEmail
* @description checks if given value is a valid email address. // * @description checks if given value is a valid email address.
* @param email // * @param email
* @returns {boolean} // * @returns {boolean}
*/ // */
generator.isValidEmail = function (email) { //generator.isValidEmail = function (email) {
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; // var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email); // return re.test(email);
}; //};
/** ///**
* @memberof ulakbus.formService // * @memberof ulakbus.formService
* @ngdoc function // * @ngdoc function
* @name isValidTCNo // * @name isValidTCNo
* @description checks if given value is a valid identity number for Turkey. // * @description checks if given value is a valid identity number for Turkey.
* @param tcno // * @param tcno
* @returns {boolean} // * @returns {boolean}
*/ // */
generator.isValidTCNo = function (tcno) { //generator.isValidTCNo = function (tcno) {
var re = /^([1-9]{1}[0-9]{9}[0,2,4,6,8]{1})$/i; // var re = /^([1-9]{1}[0-9]{9}[0,2,4,6,8]{1})$/i;
return re.test(tcno); // return re.test(tcno);
}; //};
/** ///**
* @memberof ulakbus.formService // * @memberof ulakbus.formService
* @ngdoc function // * @ngdoc function
* @name isValidDate // * @name isValidDate
* @description checks if given value can be parsed as Date object // * @description checks if given value can be parsed as Date object
* @param dateValue // * @param dateValue
* @returns {boolean} // * @returns {boolean}
*/ // */
generator.isValidDate = function (dateValue) { //generator.isValidDate = function (dateValue) {
return !isNaN(Date.parse(dateValue)); // //return !isNaN(Date.parse(dateValue));
}; // return moment(dateValue)._d.toString() !== 'Invalid Date'
//};
/** /**
* @memberof ulakbus.formService * @memberof ulakbus.formService
......
...@@ -301,82 +301,83 @@ describe('form service module', function () { ...@@ -301,82 +301,83 @@ describe('form service module', function () {
}) })
); );
it('should validate email', //it('should validate email',
inject(function (Generator) { // inject(function (Generator) {
var validEmails = [ // var validEmails = [
'test@test.com', // 'test@test.com',
'test@test.co.uk', // 'test@test.co.uk',
'test734ltylytkliytkryety9ef@jb-fe.com' // 'test734ltylytkliytkryety9ef@jb-fe.com'
]; // ];
//
var invalidEmails = [ // var invalidEmails = [
'test@testcom', // 'test@testcom',
'test@ test.co.uk', // 'test@ test.co.uk',
'ghgf@fe.com.co.', // 'ghgf@fe.com.co.',
'tes@t@test.com', // 'tes@t@test.com',
'' // ''
]; // ];
//
for (var i in validEmails) { // for (var i in validEmails) {
var valid = Generator.isValidEmail(validEmails[i]); // var valid = Generator.isValidEmail(validEmails[i]);
expect(valid).toBeTruthy(); // expect(valid).toBeTruthy();
} // }
for (var i in invalidEmails) { // for (var i in invalidEmails) {
var valid = Generator.isValidEmail(invalidEmails[i]); // var valid = Generator.isValidEmail(invalidEmails[i]);
expect(valid).toBeFalsy(); // expect(valid).toBeFalsy();
} // }
}) // })
); //);
//
it('should validate tcNo', //it('should validate tcNo',
inject(function (Generator) { // inject(function (Generator) {
var validTCNos = [ // var validTCNos = [
'12345678902', // '12345678902',
'18307990654' // '18307990654'
]; // ];
//
var invalidTCNos = [ // var invalidTCNos = [
'00000000000', // '00000000000',
'00000000002', // '00000000002',
'12345678901', // '12345678901',
'1234567892', // '1234567892',
'' // ''
]; // ];
//
for (var i in validTCNos) { // for (var i in validTCNos) {
var valid = Generator.isValidTCNo(validTCNos[i]); // var valid = Generator.isValidTCNo(validTCNos[i]);
expect(valid).toBeTruthy(); // expect(valid).toBeTruthy();
} // }
for (var i in invalidTCNos) { // for (var i in invalidTCNos) {
var valid = Generator.isValidTCNo(invalidTCNos[i]); // var valid = Generator.isValidTCNo(invalidTCNos[i]);
expect(valid).toBeFalsy(); // expect(valid).toBeFalsy();
} // }
}) // })
); //);
//
it('should validate date', //it('should validate date',
inject(function (Generator) { // inject(function (Generator) {
var validDates = [ // var validDates = [
'12/12/2012' // '12.12.2012'
]; // ];
//
var invalidDates = [ // var invalidDates = [
'dsad', // 'dsad',
'0.0.0', // '0.0.0',
'12.15.2012', // '15/12/2012',
'' // ''
]; // ];
//
for (var i in validDates) { // for (var i in validDates) {
var valid = Generator.isValidDate(validDates[i]); // var valid = Generator.isValidDate(validDates[i]);
expect(valid).toBeTruthy(); //
} // expect(valid).toBeTruthy();
for (var i in invalidDates) { // }
var valid = Generator.isValidDate(invalidDates[i]); // for (var j in invalidDates) {
expect(valid).toBeFalsy(); // var notValid = Generator.isValidDate(invalidDates[j]);
} // expect(notValid).toBeFalsy();
}) // }
); // })
//);
it('should get wf and redirect according to client_cmd', it('should get wf and redirect according to client_cmd',
inject(function (Generator, $httpBackend, RESTURL) { inject(function (Generator, $httpBackend, RESTURL) {
......
...@@ -55,13 +55,10 @@ angular.module('ulakbus') ...@@ -55,13 +55,10 @@ angular.module('ulakbus')
} }
} }
// if (response.data.client_cmd) {
//$location.path(response.data.screen);
// }
return response; return response;
}, },
'responseError': function (rejection) { 'responseError': function (rejection) {
var errorInModal = ('error' in rejection.data);
var errorModal = function () { var errorModal = function () {
if ($rootScope.loginAttempt === 0) { if ($rootScope.loginAttempt === 0) {
$log.debug('not logged in, no alert message triggered'); $log.debug('not logged in, no alert message triggered');
...@@ -81,7 +78,7 @@ angular.module('ulakbus') ...@@ -81,7 +78,7 @@ angular.module('ulakbus')
'<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span' + '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span' +
' aria-hidden="true">&times;</span></button>' + ' aria-hidden="true">&times;</span></button>' +
'<h4 class="modal-title" id="exampleModalLabel">' + '<h4 class="modal-title" id="exampleModalLabel">' +
rejection.status + rejection.data.title + "Error Status: " + rejection.status + "<br>Error Title: " + rejection.data.title +
'</h4>' + '</h4>' +
'</div>' + '</div>' +
'<div class="modal-body">' + '<div class="modal-body">' +
...@@ -108,45 +105,54 @@ angular.module('ulakbus') ...@@ -108,45 +105,54 @@ angular.module('ulakbus')
} }
}; };
if (rejection.status === -1) { var errorInAlertBox = function (alertContent) {
rejection.status = 'Sunucu hatası' if (errorInModal) {
rejection.data = { errorModal();
title: "", description: 'Sunucu bağlantısında bir hata oluştu.' + } else {
'Lütfen yetkili personelle iletişime geçiniz.' $rootScope.$broadcast('alertBox', alertContent);
};
$rootScope.$broadcast('alertBox', {
title: rejection.status,
msg: rejection.data.description,
type: 'error'
});
}
if (rejection.status === 400) {
$location.reload();
}
if (rejection.status === 401) {
$location.path('/login');
if ($location.path() === "/login") {
$log.debug("show errors on login form");
} }
} };
if (rejection.status === 403) {
if (rejection.data.is_login === true) { var errorForAlertBox = {
$rootScope.loggedInUser = true; title: rejection.status,
msg: rejection.data.description,
type: 'error'
};
var errorDispatch = {
"-1" : function () {
rejection.status = 'Sunucu hatası';
rejection.data.title = rejection.data.title || "Sunucu Hatası";
rejection.data.description = rejection.data.description || 'Sunucu bağlantısında bir hata oluştu. Lütfen yetkili personelle iletişime geçiniz.';
errorInAlertBox(errorForAlertBox);
},
"400": function () {
$location.reload();
},
"401": function () {
$location.path('/login');
if ($location.path() === "/login") { if ($location.path() === "/login") {
$location.path("/dashboard"); $log.debug("show errors on login form");
} }
},
"403": function () {
if (rejection.data.is_login === true) {
$rootScope.loggedInUser = true;
if ($location.path() === "/login") {
$location.path("/dashboard");
}
}
},
"404": function () {
errorInAlertBox(errorForAlertBox);
},
"500": function () {
errorInAlertBox(errorForAlertBox);
} }
//errorModal(); };
}
$rootScope.$broadcast('show_notifications', rejection.data); errorDispatch[rejection.status]();
if (rejection.status === 404) {
errorModal();
}
if (rejection.status === 500) {
errorModal();
}
return $q.reject(rejection); return $q.reject(rejection);
} }
}; };
......
/**
* @license Ulakbus-UI
* Copyright (C) 2015 ZetaOps Inc.
*
* This file is licensed under the GNU General Public License v3
* (GPLv3). See LICENSE.txt for details.
*/
//'use strict';
describe('interceptor module', function () {
beforeEach(module('ulakbus'));
var $httpBackend, $rootScope;
beforeEach(inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
$rootScope = $injector.get('$rootScope');
}));
describe('http interceptor', function () {
it('should handle errors properly', inject(function ($http, $rootScope, RESTURL) {
this.statuses = [-1, 404, 500];
angular.forEach(this.statuses, function (value, key) {
var resp = {data: {title: 'test', description: 'test', is_login: true}};
//if (modal) { resp.data.error = 'some error'; }
$httpBackend.expectGET(RESTURL.url + 'testforerror').respond(value, resp);
var listener = jasmine.createSpy('listener');
$rootScope.$on('alertBox', listener);
$http.get(RESTURL.url + 'testforerror').error(function (data) {
expect(listener).toHaveBeenCalled();
});
$httpBackend.flush();
});
var resp2 = {data: {title: 'test', description: 'test', is_login: true, error: 'test error'}};
$httpBackend.expectGET(RESTURL.url + 'testforerror2').respond(500, resp2);
var listener2 = jasmine.createSpy('listener2');
$rootScope.$on('alertBox', listener2);
$http.get(RESTURL.url + 'testforerror2').error(function (data) {
expect(listener2).toHaveBeenCalled();
});
$httpBackend.flush();
var resp3 = {is_login: true, _debug_queries: [{query: ''}]};
$httpBackend.expectGET(RESTURL.url + 'testforerror3').respond(200, resp3);
$http.get(RESTURL.url + 'testforerror3').success(function (data) {
expect($rootScope.debug_queries[0].queries).toEqual([{query: ''}]);
});
$httpBackend.flush();
}));
});
});
\ No newline at end of file
...@@ -37,7 +37,7 @@ module.exports = function (config) { ...@@ -37,7 +37,7 @@ module.exports = function (config) {
frameworks: ['jasmine'], frameworks: ['jasmine'],
browsers: ['PhantomJS'], browsers: ['PhantomJS', 'Chrome', 'Firefox', 'Safari'],
customLaunchers: { customLaunchers: {
'PhantomJS_custom': { 'PhantomJS_custom': {
...@@ -46,7 +46,7 @@ module.exports = function (config) { ...@@ -46,7 +46,7 @@ module.exports = function (config) {
windowName: 'my-window', windowName: 'my-window',
settings: { settings: {
webSecurityEnabled: false webSecurityEnabled: false
}, }
}, },
flags: ['--load-images=true'], flags: ['--load-images=true'],
debug: true debug: true
...@@ -60,6 +60,9 @@ module.exports = function (config) { ...@@ -60,6 +60,9 @@ module.exports = function (config) {
plugins: [ plugins: [
'karma-phantomjs-launcher', 'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-safari-launcher',
'karma-jasmine', 'karma-jasmine',
'karma-junit-reporter', 'karma-junit-reporter',
'karma-coverage' 'karma-coverage'
...@@ -90,8 +93,7 @@ module.exports = function (config) { ...@@ -90,8 +93,7 @@ module.exports = function (config) {
functions: 60, functions: 60,
lines: 60, lines: 60,
excludes: [ excludes: [
'app/components/uitemplates/*.js', 'app/components/uitemplates/*.js'
//'app/zetalib/interceptors.js'
] ]
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment