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