mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
implementing userService test
This commit is contained in:
parent
a65e9eade6
commit
ffb720757d
50
frontend/app/model/network/user.service.spec.ts
Normal file
50
frontend/app/model/network/user.service.spec.ts
Normal file
@ -0,0 +1,50 @@
|
||||
///<reference path="../../../browser.d.ts"/>
|
||||
|
||||
import {it, inject, beforeEachProviders, beforeEach, afterEach} from "@angular/core/testing";
|
||||
import {BaseRequestOptions, Http, Response, ResponseOptions} from "@angular/http";
|
||||
import {MockBackend, MockConnection} from "@angular/http/testing";
|
||||
import {provide} from "@angular/core";
|
||||
import "rxjs/Rx";
|
||||
import {NetworkService} from "./network.service";
|
||||
import {Message} from "../../../../common/entities/Message";
|
||||
import {UserService} from "./user.service";
|
||||
import {LoginComponent} from "../../login/login.component";
|
||||
import {LoginCredential} from "../../../../common/entities/LoginCredential";
|
||||
|
||||
|
||||
describe('UserService', () => {
|
||||
|
||||
|
||||
beforeEachProviders(() => [
|
||||
MockBackend,
|
||||
BaseRequestOptions,
|
||||
provide(Http, {
|
||||
useFactory: (backend, options) => {
|
||||
return new Http(backend, options);
|
||||
}, deps: [MockBackend, BaseRequestOptions]
|
||||
}),
|
||||
NetworkService,
|
||||
UserService
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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.calls.argsFor(0)).toEqual(["/user/login",{"loginCredential": credential}]);
|
||||
}));
|
||||
|
||||
it('should call getJson at getSessionUser', inject([UserService,NetworkService], (userService,networkService) => {
|
||||
spyOn(networkService,"getJson");
|
||||
let credential = new LoginCredential("name","pass");
|
||||
userService.login(credential);
|
||||
}));
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
@ -8,21 +8,20 @@ import {User} from "../../../../common/entities/User";
|
||||
import {Message} from "../../../../common/entities/Message";
|
||||
|
||||
@Injectable()
|
||||
export class UserService extends NetworkService{
|
||||
export class UserService{
|
||||
|
||||
|
||||
|
||||
constructor(_http:Http){
|
||||
super(_http);
|
||||
constructor(private _networkService:NetworkService){
|
||||
}
|
||||
|
||||
|
||||
public login(credential:LoginCredential): Promise<Message<User>>{
|
||||
return this.postJson("/user/login",{"loginCredential": credential});
|
||||
return this._networkService.postJson("/user/login",{"loginCredential": credential});
|
||||
}
|
||||
|
||||
public getSessionUser(): Promise<Message<User>>{
|
||||
return this.getJson("/user/login");
|
||||
return this._networkService.getJson("/user/login");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user