Browse Source

test: fix testing errors

pull/4956/head
mehmet-erim 6 years ago
parent
commit
42ace83cef
  1. 5
      npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts
  2. 19
      npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts
  3. 2
      npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts

5
npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts

@ -6,6 +6,7 @@ import { SetLanguage } from '../actions';
import { Config } from '../models/config';
import { ApplicationConfigurationService, ConfigStateService } from '../services';
import { ConfigState } from '../states';
import { OAuthService } from 'angular-oauth2-oidc';
export const CONFIG_STATE_DATA = {
environment: {
@ -107,14 +108,14 @@ describe('ConfigState', () => {
const createService = createServiceFactory({
service: ConfigStateService,
mocks: [ApplicationConfigurationService, Store, HttpClient],
mocks: [ApplicationConfigurationService, Store, HttpClient, OAuthService],
});
beforeEach(() => {
spectator = createService();
store = spectator.inject(Store);
service = spectator.service;
state = new ConfigState(spectator.inject(HttpClient), store);
state = new ConfigState(spectator.inject(HttpClient), store, spectator.inject(OAuthService));
});
describe('#getAll', () => {

19
npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts

@ -3,8 +3,9 @@ import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store';
import { of } from 'rxjs';
import { GetAppConfiguration } from '../actions';
import { getInitialData, localeInitializer, configureOAuth } from '../utils';
import { getInitialData, localeInitializer, configureOAuth, checkAccessToken } from '../utils';
import { OAuthService } from 'angular-oauth2-oidc';
import * as multiTenancyUtils from '../utils/multi-tenancy-utils';
@Component({
selector: 'abp-dummy',
@ -41,6 +42,8 @@ describe('InitialUtils', () => {
const injectorSpy = jest.spyOn(injector, 'get');
const store = spectator.inject(Store);
const dispatchSpy = jest.spyOn(store, 'dispatch');
const parseTenantFromUrlSpy = jest.spyOn(multiTenancyUtils, 'parseTenantFromUrl');
parseTenantFromUrlSpy.mockReturnValue(Promise.resolve());
injectorSpy.mockReturnValueOnce(store);
injectorSpy.mockReturnValueOnce({ skipGetAppConfiguration: false });
@ -57,16 +60,16 @@ describe('InitialUtils', () => {
test('should call logOut fn of OAuthService when token is valid and current user not found', async () => {
const injector = spectator.inject(Injector);
const injectorSpy = jest.spyOn(injector, 'get');
const store = spectator.inject(Store);
const dispatchSpy = jest.spyOn(store, 'dispatch');
const logOutFn = jest.fn();
injectorSpy.mockReturnValueOnce(store);
injectorSpy.mockReturnValueOnce({ skipGetAppConfiguration: false });
injectorSpy.mockReturnValueOnce({ hasValidAccessToken: () => true, logOut: logOutFn });
dispatchSpy.mockReturnValue(of({ currentUser: { id: null } }));
injectorSpy.mockReturnValue({ hasValidAccessToken: () => true, logOut: logOutFn });
getInitialData(injector)();
checkAccessToken(
{
selectSnapshot: () => false,
} as any,
injector,
);
expect(logOutFn).toHaveBeenCalled();
});
});

2
npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts

@ -6,6 +6,7 @@ import { Rest } from '../models';
import { RestService } from '../services/rest.service';
import { ConfigState } from '../states/config.state';
import { CORE_OPTIONS } from '../tokens';
import { OAuthService } from 'angular-oauth2-oidc';
describe('HttpClient testing', () => {
let spectator: SpectatorHttp<RestService>;
@ -16,6 +17,7 @@ describe('HttpClient testing', () => {
dataService: RestService,
imports: [NgxsModule.forRoot([ConfigState])],
providers: [{ provide: CORE_OPTIONS, useValue: { environment: {} } }],
mocks: [OAuthService],
});
beforeEach(() => {

Loading…
Cancel
Save