diff --git a/frontend/app/model/network/autehentication.service.spec.ts b/frontend/app/model/network/autehentication.service.spec.ts index 88d20313..597355f7 100644 --- a/frontend/app/model/network/autehentication.service.spec.ts +++ b/frontend/app/model/network/autehentication.service.spec.ts @@ -37,5 +37,21 @@ describe('AuthenticationService', () => { expect(userService.login).toHaveBeenCalled(); })); + it('should have NO Authenticated use', inject([ AuthenticationService ], (authService) => { + expect(authService.getUser()).toBe(null); + expect(authService.isAuthenticated()).toBe(false); + })); + + + it('should have Authenticated use', inject([ AuthenticationService ], (authService) => { + spyOn(authService.OnAuthenticated,"trigger").and.callThrough(); + authService.login(); + authService.OnAuthenticated.on(() =>{ + expect(authService.getUser()).not.toBe(null); + expect(authService.isAuthenticated()).toBe(true); + }); + + })); + }); diff --git a/frontend/app/model/network/authentication.service.ts b/frontend/app/model/network/authentication.service.ts index 3f713bf6..7b6201a8 100644 --- a/frontend/app/model/network/authentication.service.ts +++ b/frontend/app/model/network/authentication.service.ts @@ -44,7 +44,12 @@ export class AuthenticationService{ }); } - public login(credential:LoginCredential){ + private setUser(user:User){ + this._user = user; + this.OnAuthenticated.trigger(this._user); + } + + public login(credential:LoginCredential) { this._userService.login(credential).then( (message:Message) =>{ if(message.error){ console.log(ErrorCodes[message.error.code] + "message: "+ message.error.message); @@ -53,11 +58,7 @@ export class AuthenticationService{ } }); } - - private setUser(user:User){ - this._user = user; - this.OnAuthenticated.trigger(this._user); - } + public isAuthenticated():boolean{ return (this._user && this._user != null) ? true : false;