Browse Source

test: fix profile.service.spec testing errors

pull/6343/head
mehmet-erim 6 years ago
parent
commit
868b7bf1d1
  1. 20
      npm/ng-packs/packages/core/src/lib/tests/profile.service.spec.ts

20
npm/ng-packs/packages/core/src/lib/tests/profile.service.spec.ts

@ -1,27 +1,32 @@
import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator/jest';
import { ProfileService, RestService } from '../services';
import { createHttpFactory, HttpMethod, SpectatorHttp, SpyObject } from '@ngneat/spectator/jest';
import { EnvironmentService, ProfileService, RestService } from '../services';
import { Store } from '@ngxs/store';
import { CORE_OPTIONS } from '../tokens';
describe('ProfileService', () => {
let spectator: SpectatorHttp<ProfileService>;
let environmentService: SpyObject<EnvironmentService>;
const createHttp = createHttpFactory({
dataService: ProfileService,
providers: [RestService, { provide: CORE_OPTIONS, useValue: { environment: {} } }],
mocks: [Store],
providers: [RestService, { provide: CORE_OPTIONS, useValue: {} }],
mocks: [Store, EnvironmentService],
});
beforeEach(() => (spectator = createHttp()));
beforeEach(() => {
spectator = createHttp();
environmentService = spectator.inject(EnvironmentService);
const getApiUrlSpy = jest.spyOn(environmentService, 'getApiUrl');
getApiUrlSpy.mockReturnValue('https://abp.io');
});
it('should send a GET to my-profile API', () => {
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.get().subscribe();
spectator.expectOne('https://abp.io/api/identity/my-profile', HttpMethod.GET);
});
it('should send a POST to change-password API', () => {
const mock = { currentPassword: 'test', newPassword: 'test' };
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.changePassword(mock).subscribe();
const req = spectator.expectOne(
'https://abp.io/api/identity/my-profile/change-password',
@ -40,7 +45,6 @@ describe('ProfileService', () => {
isExternal: false,
hasPassword: false,
};
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.update(mock).subscribe();
const req = spectator.expectOne('https://abp.io/api/identity/my-profile', HttpMethod.PUT);
expect(req.request.body).toEqual(mock);

Loading…
Cancel
Save