Browse Source

test: fix broken tests

pull/9576/head
bnymncoskuner 5 years ago
parent
commit
92848ff399
  1. 6
      npm/ng-packs/packages/core/src/lib/tests/api.interceptor.spec.ts
  2. 6
      npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts
  3. 2
      npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts
  4. 32
      npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts

6
npm/ng-packs/packages/core/src/lib/tests/api.interceptor.spec.ts

@ -5,6 +5,7 @@ import { OAuthService } from 'angular-oauth2-oidc';
import { Subject, timer } from 'rxjs'; import { Subject, timer } from 'rxjs';
import { ApiInterceptor } from '../interceptors'; import { ApiInterceptor } from '../interceptors';
import { HttpWaitService, SessionStateService } from '../services'; import { HttpWaitService, SessionStateService } from '../services';
import { TENANT_KEY } from '../tokens/tenant-key.token';
describe('ApiInterceptor', () => { describe('ApiInterceptor', () => {
let spectator: SpectatorService<ApiInterceptor>; let spectator: SpectatorService<ApiInterceptor>;
@ -13,9 +14,12 @@ describe('ApiInterceptor', () => {
let sessionState: SpyObject<SessionStateService>; let sessionState: SpyObject<SessionStateService>;
let httpWaitService: SpyObject<HttpWaitService>; let httpWaitService: SpyObject<HttpWaitService>;
const testTenantKey = 'TEST_TENANT_KEY';
const createService = createServiceFactory({ const createService = createServiceFactory({
service: ApiInterceptor, service: ApiInterceptor,
mocks: [OAuthService, SessionStateService], mocks: [OAuthService, SessionStateService],
providers: [{ provide: TENANT_KEY, useValue: testTenantKey }],
}); });
beforeEach(() => { beforeEach(() => {
@ -38,7 +42,7 @@ describe('ApiInterceptor', () => {
handle: (req: HttpRequest<any>) => { handle: (req: HttpRequest<any>) => {
expect(req.headers.get('Authorization')).toEqual('Bearer ey892mkwa8^2jk'); expect(req.headers.get('Authorization')).toEqual('Bearer ey892mkwa8^2jk');
expect(req.headers.get('Accept-Language')).toEqual('tr'); expect(req.headers.get('Accept-Language')).toEqual('tr');
expect(req.headers.get('__tenant')).toEqual('Volosoft'); expect(req.headers.get(testTenantKey)).toEqual('Volosoft');
done(); done();
return handleRes$; return handleRes$;
}, },

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

@ -5,8 +5,9 @@ import {
CurrentUserDto, CurrentUserDto,
} from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models'; } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models';
import { ConfigStateService } from '../services'; import { ConfigStateService } from '../services';
import { CoreTestingModule } from '@abp/ng.core/testing';
export const CONFIG_STATE_DATA = ({ export const CONFIG_STATE_DATA = {
environment: { environment: {
production: false, production: false,
application: { application: {
@ -97,7 +98,7 @@ export const CONFIG_STATE_DATA = ({
}, },
}, },
registerLocaleFn: () => Promise.resolve(), registerLocaleFn: () => Promise.resolve(),
} as any) as ApplicationConfigurationDto; } as any as ApplicationConfigurationDto;
describe('ConfigState', () => { describe('ConfigState', () => {
let spectator: SpectatorService<ConfigStateService>; let spectator: SpectatorService<ConfigStateService>;
@ -105,6 +106,7 @@ describe('ConfigState', () => {
const createService = createServiceFactory({ const createService = createServiceFactory({
service: ConfigStateService, service: ConfigStateService,
imports: [CoreTestingModule.withConfig()],
}); });
beforeEach(() => { beforeEach(() => {

2
npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts

@ -15,7 +15,7 @@ describe('Date Utils', () => {
let config: ConfigStateService; let config: ConfigStateService;
beforeEach(() => { beforeEach(() => {
config = new ConfigStateService(); config = new ConfigStateService(null);
}); });
describe('#getShortDateFormat', () => { describe('#getShortDateFormat', () => {

32
npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts

@ -1,14 +1,15 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import clone from 'just-clone'; import clone from 'just-clone';
import { BehaviorSubject } from 'rxjs'; import { of } from 'rxjs';
import { AbpTenantService } from '../proxy/pages/abp/multi-tenancy/abp-tenant.service';
import { import {
CurrentTenantDto, CurrentTenantDto,
FindTenantResultDto, FindTenantResultDto,
} from '../proxy/volo/abp/asp-net-core/mvc/multi-tenancy/models'; } from '../proxy/volo/abp/asp-net-core/mvc/multi-tenancy/models';
import { EnvironmentService, MultiTenancyService } from '../services'; import { EnvironmentService, MultiTenancyService } from '../services';
import { parseTenantFromUrl } from '../utils'; import { parseTenantFromUrl } from '../utils';
import { TENANT_KEY } from '../tokens';
const environment = { const environment = {
production: false, production: false,
@ -45,6 +46,8 @@ const setHref = url => {
}); });
}; };
const testTenantKey = 'TEST_TENANT_KEY';
@Component({ @Component({
selector: 'abp-dummy', selector: 'abp-dummy',
template: '', template: '',
@ -56,7 +59,7 @@ describe('MultiTenancyUtils', () => {
const createComponent = createComponentFactory({ const createComponent = createComponentFactory({
component: DummyComponent, component: DummyComponent,
mocks: [EnvironmentService, MultiTenancyService], mocks: [EnvironmentService, MultiTenancyService],
providers: [{ provide: AbpTenantService, useValue: { findTenantByName: () => {} } }], providers: [{ provide: TENANT_KEY, useValue: testTenantKey }],
}); });
beforeEach(() => (spectator = createComponent())); beforeEach(() => (spectator = createComponent()));
@ -65,27 +68,30 @@ describe('MultiTenancyUtils', () => {
test('should get the tenancyName, set replaced environment and call the findTenantByName method of AbpTenantService', async () => { test('should get the tenancyName, set replaced environment and call the findTenantByName method of AbpTenantService', async () => {
const environmentService = spectator.inject(EnvironmentService); const environmentService = spectator.inject(EnvironmentService);
const multiTenancyService = spectator.inject(MultiTenancyService); const multiTenancyService = spectator.inject(MultiTenancyService);
const abpTenantService = spectator.inject(AbpTenantService); const setTenantByName = jest.spyOn(multiTenancyService, 'setTenantByName');
const findTenantByNameSpy = jest.spyOn(abpTenantService, 'findTenantByName');
const getEnvironmentSpy = jest.spyOn(environmentService, 'getEnvironment'); const getEnvironmentSpy = jest.spyOn(environmentService, 'getEnvironment');
const setStateSpy = jest.spyOn(environmentService, 'setState'); const setStateSpy = jest.spyOn(environmentService, 'setState');
getEnvironmentSpy.mockReturnValue(clone(environment)); getEnvironmentSpy.mockReturnValue(clone(environment));
const testTenant: FindTenantResultDto = {
name: 'abp',
tenantId: '1',
isActive: true,
success: true,
};
setHref('https://abp.volosoft.com/'); setHref('https://abp.volosoft.com/');
findTenantByNameSpy.mockReturnValue( setTenantByName.mockReturnValue(of(testTenant));
new BehaviorSubject({ name: 'abp', tenantId: '1', success: true } as FindTenantResultDto),
);
const mockInjector = { const mockInjector = {
get: arg => { get: arg => {
if (arg === EnvironmentService) return environmentService; if (arg === EnvironmentService) return environmentService;
if (arg === AbpTenantService) return abpTenantService;
if (arg === MultiTenancyService) return multiTenancyService; if (arg === MultiTenancyService) return multiTenancyService;
}, },
}; };
parseTenantFromUrl(mockInjector); await parseTenantFromUrl(mockInjector);
const replacedEnv = { const replacedEnv = {
...environment, ...environment,
@ -106,10 +112,10 @@ describe('MultiTenancyUtils', () => {
}; };
expect(setStateSpy).toHaveBeenCalledWith(replacedEnv); expect(setStateSpy).toHaveBeenCalledWith(replacedEnv);
expect(findTenantByNameSpy).toHaveBeenCalledWith('abp', { __tenant: '' });
expect(multiTenancyService.domainTenant).toEqual({ expect(multiTenancyService.domainTenant).toEqual({
id: '1', id: testTenant.tenantId,
name: 'abp', name: testTenant.name,
isAvailable: true,
} as CurrentTenantDto); } as CurrentTenantDto);
}); });
}); });

Loading…
Cancel
Save