2016-04-30 18:01:54 +02:00
|
|
|
///<reference path="../../../browser.d.ts"/>
|
2016-03-19 10:58:27 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
it,
|
|
|
|
inject,
|
2016-05-04 17:20:21 +02:00
|
|
|
beforeEachProviders
|
|
|
|
} from '@angular/core/testing';
|
|
|
|
|
2016-03-19 10:58:27 +02:00
|
|
|
|
2016-05-04 20:10:28 +02:00
|
|
|
import {provide} from '@angular/core';
|
2016-04-30 18:01:54 +02:00
|
|
|
import {UserService} from "./user.service.ts";
|
|
|
|
import {User} from "../../../../common/entities/User";
|
|
|
|
import {Message} from "../../../../common/entities/Message";
|
2016-03-19 11:55:46 +02:00
|
|
|
import "rxjs/Rx";
|
2016-04-30 18:01:54 +02:00
|
|
|
import {LoginCredential} from "../../../../common/entities/LoginCredential";
|
2016-05-04 20:10:28 +02:00
|
|
|
import {AuthenticationService} from "./authentication.service";
|
2016-03-19 10:58:27 +02:00
|
|
|
|
2016-03-19 11:55:46 +02:00
|
|
|
class MockUserService {
|
|
|
|
public login(credential:LoginCredential){
|
2016-05-05 18:05:40 +02:00
|
|
|
return Promise.resolve(new Message<User>(null,new User(0,"testUserName")))
|
2016-03-19 11:55:46 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-19 10:58:27 +02:00
|
|
|
|
2016-05-04 21:08:05 +02:00
|
|
|
describe('AuthenticationService', () => {
|
2016-03-19 10:58:27 +02:00
|
|
|
beforeEachProviders(() => [
|
2016-03-19 11:55:46 +02:00
|
|
|
provide(UserService, {useClass: MockUserService}),
|
2016-03-19 10:58:27 +02:00
|
|
|
AuthenticationService
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
it('should call User service login', inject([ AuthenticationService,UserService ], (authService, userService) => {
|
2016-03-19 11:55:46 +02:00
|
|
|
spyOn(userService,"login").and.callThrough();
|
|
|
|
|
2016-03-19 10:58:27 +02:00
|
|
|
expect(userService.login).not.toHaveBeenCalled();
|
|
|
|
authService.login();
|
|
|
|
expect(userService.login).toHaveBeenCalled();
|
|
|
|
}));
|
|
|
|
|
2016-05-04 22:20:54 +02:00
|
|
|
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(() =>{
|
2016-05-05 18:14:11 +02:00
|
|
|
expect(authService.OnAuthenticated.trigger).toHaveBeenCalled();
|
2016-05-04 22:20:54 +02:00
|
|
|
expect(authService.getUser()).not.toBe(null);
|
|
|
|
expect(authService.isAuthenticated()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
2016-03-19 10:58:27 +02:00
|
|
|
|
|
|
|
});
|