Commit d8edcd8b authored by Evren Kutar's avatar Evren Kutar

tests ok for now, will add more test cases

parent 2e8c4583
...@@ -58,16 +58,13 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU ...@@ -58,16 +58,13 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU
} }
]; ];
$scope.onSubmit = function(form){ $scope.onSubmit = function(form){
//$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
console.log(form);
if (form.$valid){ if (form.$valid){
$rootScope.loggedInUser = true;
$location.path("/dashboard");
var credentials = {email: form.email, password: form.password}; var credentials = {email: form.email.modelValue, password: form.password.modelValue};
var loginResponse = LoginService.login(credentials); var loginResponse = LoginService.login(credentials);
//console.log(loginResponse.value); console.log(loginResponse.value);
} }
else { else {
console.log("not valid"); console.log("not valid");
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// TODO: login url change with correct one // TODO: login url change with correct one
login.factory('LoginService', function ($http, Session) { login.factory('LoginService', function ($http, $rootScope, $location, Session) {
var loginService = {}; var loginService = {};
loginService.login = function (credentials) { loginService.login = function (credentials) {
...@@ -19,6 +19,12 @@ login.factory('LoginService', function ($http, Session) { ...@@ -19,6 +19,12 @@ login.factory('LoginService', function ($http, Session) {
}); });
}; };
loginService.changePath = function () {
$rootScope.loggedInUser = true;
$location.path("/dashboard");
};
loginService.isAuthenticated = function () { loginService.isAuthenticated = function () {
return !!Session.userId; return !!Session.userId;
}; };
......
...@@ -55,15 +55,18 @@ describe('zaerp.login module', function () { ...@@ -55,15 +55,18 @@ describe('zaerp.login module', function () {
it('should get login success', it('should get login success',
inject(function(LoginService, $httpBackend) { inject(function(LoginService, $httpBackend) {
$httpBackend.expectPOST('http://127.0.0.1:8000/login') // 204 because of access control allow origin
.respond(200, "[{'id': 1, 'user': {'id': 12, 'role': 'admin'}}]");
$httpBackend.expectPOST('http://127.0.0.1:8000/login', {email: "test@test.com", password: "password"})
//LoginService.login({email: 'test@test.com', password: 'password'}) .respond(204, {'id': 1, 'user': {'id': 12, 'role': 'admin'}});
// .then(function(data) {
// expect(data.id).not.toBe(null); var cred = {email: 'test@test.com', password: 'password'};
// }); LoginService.login(cred)
// .then(function(data) {
//$httpBackend.flush(); expect(data.id).not.toBe(null);
});
$httpBackend.flush();
}) })
); );
......
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