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

Loading…
Cancel
Save