1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

implementing authmanager test

This commit is contained in:
Braun Patrik 2016-05-04 22:20:54 +02:00
parent f0552f6bfd
commit a65e9eade6
2 changed files with 23 additions and 6 deletions

View File

@ -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);
});
}));
});

View File

@ -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<User>) =>{
if(message.error){
console.log(ErrorCodes[message.error.code] + "message: "+ message.error.message);
@ -54,10 +59,6 @@ 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;