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:
parent
f0552f6bfd
commit
a65e9eade6
@ -37,5 +37,21 @@ describe('AuthenticationService', () => {
|
|||||||
expect(userService.login).toHaveBeenCalled();
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -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>) =>{
|
this._userService.login(credential).then( (message:Message<User>) =>{
|
||||||
if(message.error){
|
if(message.error){
|
||||||
console.log(ErrorCodes[message.error.code] + "message: "+ message.error.message);
|
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{
|
public isAuthenticated():boolean{
|
||||||
return (this._user && this._user != null) ? true : false;
|
return (this._user && this._user != null) ? true : false;
|
||||||
|
Loading…
Reference in New Issue
Block a user