1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/model/network/user.service.spec.ts

46 lines
1.6 KiB
TypeScript
Raw Normal View History

2016-05-05 04:37:26 +08:00
///<reference path="../../../browser.d.ts"/>
2016-05-09 23:04:56 +08:00
import {it, inject, beforeEachProviders} from "@angular/core/testing";
import {BaseRequestOptions, Http} from "@angular/http";
import {MockBackend} from "@angular/http/testing";
2016-05-05 04:37:26 +08:00
import {provide} from "@angular/core";
import "rxjs/Rx";
import {NetworkService} from "./network.service";
import {UserService} from "./user.service";
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
]);
2016-05-09 23:04:56 +08:00
it('should call postJson at login', inject([UserService, NetworkService], (userService, networkService) => {
spyOn(networkService, "postJson");
let credential = new LoginCredential("name", "pass");
2016-05-05 04:37:26 +08:00
userService.login(credential);
2016-05-06 00:14:11 +08:00
expect(networkService.postJson).toHaveBeenCalled();
2016-05-09 23:04:56 +08:00
expect(networkService.postJson.calls.argsFor(0)).toEqual(["/user/login", {"loginCredential": credential}]);
2016-05-05 04:37:26 +08:00
}));
2016-05-09 23:04:56 +08:00
it('should call getJson at getSessionUser', inject([UserService, NetworkService], (userService, networkService) => {
spyOn(networkService, "getJson");
2016-05-06 00:00:36 +08:00
userService.getSessionUser();
2016-05-06 00:05:40 +08:00
expect(networkService.getJson).toHaveBeenCalled();
2016-05-06 00:00:36 +08:00
expect(networkService.getJson.calls.argsFor(0)).toEqual(["/user/login"]);
2016-05-05 04:37:26 +08:00
}));
});