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