diff --git a/npm/ng-packs/packages/core/src/lib/tests/profile.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/profile.service.spec.ts index 7ccb0f2da3..0074088476 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/profile.service.spec.ts +++ b/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; + let environmentService: SpyObject; + 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);