2018-03-31 03:30:30 +08:00
|
|
|
import {inject, TestBed} from '@angular/core/testing';
|
|
|
|
import {BaseRequestOptions, Http} from '@angular/http';
|
|
|
|
import {MockBackend} from '@angular/http/testing';
|
|
|
|
import 'rxjs/Rx';
|
|
|
|
import {NetworkService} from './network.service';
|
|
|
|
import {UserService} from './user.service';
|
|
|
|
import {LoginCredential} from '../../../../common/entities/LoginCredential';
|
2016-05-05 04:37:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
describe('UserService', () => {
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
providers: [
|
|
|
|
MockBackend,
|
|
|
|
BaseRequestOptions,
|
|
|
|
{
|
|
|
|
provide: Http, useFactory: (backend, options) => {
|
2018-03-31 03:30:30 +08:00
|
|
|
return new Http(backend, options);
|
|
|
|
}, deps: [MockBackend, BaseRequestOptions]
|
2017-06-11 04:32:56 +08:00
|
|
|
},
|
|
|
|
NetworkService,
|
|
|
|
UserService]
|
|
|
|
});
|
2016-12-27 06:36:38 +08:00
|
|
|
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
it('should call postJson at login', inject([UserService, NetworkService], (userService, networkService) => {
|
2018-03-31 03:30:30 +08:00
|
|
|
spyOn(networkService, 'postJson');
|
2018-05-04 07:17:08 +08:00
|
|
|
const credential = new LoginCredential('name', 'pass');
|
2017-06-11 04:32:56 +08:00
|
|
|
userService.login(credential);
|
|
|
|
expect(networkService.postJson).toHaveBeenCalled();
|
2018-03-31 03:30:30 +08:00
|
|
|
expect(networkService.postJson.calls.argsFor(0)).toEqual(['/user/login', {'loginCredential': credential}]);
|
2017-06-11 04:32:56 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should call getJson at getSessionUser', inject([UserService, NetworkService], (userService, networkService) => {
|
2018-03-31 03:30:30 +08:00
|
|
|
spyOn(networkService, 'getJson');
|
2017-06-11 04:32:56 +08:00
|
|
|
userService.getSessionUser();
|
|
|
|
expect(networkService.getJson).toHaveBeenCalled();
|
2018-03-31 03:30:30 +08:00
|
|
|
expect(networkService.getJson.calls.argsFor(0)).toEqual(['/user/login']);
|
2017-06-11 04:32:56 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|