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

54 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {inject, TestBed} from '@angular/core/testing';
2018-05-23 08:27:07 +08:00
import {HttpClientTestingModule} from '@angular/common/http/testing';
2018-03-31 03:30:30 +08:00
import {NetworkService} from './network.service';
import {UserService} from './user.service';
import {LoginCredential} from '../../../../common/entities/LoginCredential';
2018-05-23 08:27:07 +08:00
import {SlimLoadingBarService} from 'ng2-slim-loading-bar';
import {ShareService} from '../../gallery/share.service';
2016-05-05 04:37:26 +08:00
2018-05-23 08:27:07 +08:00
class MockShareService {
wait() {
return Promise.resolve(true);
}
isSharing() {
return false;
}
}
2016-05-05 04:37:26 +08:00
describe('UserService', () => {
2018-05-23 08:27:07 +08:00
beforeEach(() => {
TestBed.configureTestingModule({
2018-05-23 08:27:07 +08:00
imports: [HttpClientTestingModule],
providers: [
2018-05-23 08:27:07 +08:00
UserService,
SlimLoadingBarService,
NetworkService,
2018-05-23 08:27:07 +08:00
{provide: ShareService, useClass: MockShareService}
]
});
2018-05-23 08:27:07 +08:00
});
2016-12-27 06:36:38 +08:00
2018-05-23 08:27:07 +08:00
it('should call postJson at login', inject([UserService, NetworkService],
2018-11-29 06:49:33 +08:00
async (userService: UserService, networkService: 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');
2018-05-23 08:27:07 +08:00
await userService.login(credential);
expect(networkService.postJson).toHaveBeenCalled();
2018-11-29 06:49:33 +08:00
expect((<any>networkService.postJson).calls.argsFor(0)).toEqual(['/user/login', {'loginCredential': credential}]);
}));
2018-05-23 08:27:07 +08:00
it('should call getJson at getSessionUser', inject([UserService, NetworkService],
2018-11-29 06:49:33 +08:00
async (userService: UserService, networkService: NetworkService) => {
2018-03-31 03:30:30 +08:00
spyOn(networkService, 'getJson');
2018-05-23 08:27:07 +08:00
await userService.getSessionUser();
expect(networkService.getJson).toHaveBeenCalled();
2018-11-29 06:49:33 +08:00
expect((<any>networkService.getJson).calls.argsFor(0)).toEqual(['/user/login']);
}));
});
2018-05-23 08:27:07 +08:00