From a65e9eade6860fb7b39f12e5a1ee97492de38336 Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Wed, 4 May 2016 22:20:54 +0200 Subject: [PATCH] implementing authmanager test --- .../network/autehentication.service.spec.ts | 16 ++++++++++++++++ .../app/model/network/authentication.service.ts | 13 +++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) 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;