test: fix broken tests

pull/9576/head
bnymncoskuner 4 years ago
parent 7a33df11c2
commit 92848ff399

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

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

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

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

Loading…
Cancel
Save