|
|
@ -4,6 +4,7 @@ import { Store } from '@ngxs/store'; |
|
|
import clone from 'just-clone'; |
|
|
import clone from 'just-clone'; |
|
|
import { BehaviorSubject } from 'rxjs'; |
|
|
import { BehaviorSubject } from 'rxjs'; |
|
|
import { FindTenantResultDto } from '../models/find-tenant-result-dto'; |
|
|
import { FindTenantResultDto } from '../models/find-tenant-result-dto'; |
|
|
|
|
|
import { EnvironmentService } from '../services'; |
|
|
import { MultiTenancyService } from '../services/multi-tenancy.service'; |
|
|
import { MultiTenancyService } from '../services/multi-tenancy.service'; |
|
|
import { parseTenantFromUrl } from '../utils'; |
|
|
import { parseTenantFromUrl } from '../utils'; |
|
|
|
|
|
|
|
|
@ -53,33 +54,34 @@ describe('MultiTenancyUtils', () => { |
|
|
let spectator: Spectator<DummyComponent>; |
|
|
let spectator: Spectator<DummyComponent>; |
|
|
const createComponent = createComponentFactory({ |
|
|
const createComponent = createComponentFactory({ |
|
|
component: DummyComponent, |
|
|
component: DummyComponent, |
|
|
mocks: [Store, MultiTenancyService], |
|
|
mocks: [EnvironmentService, MultiTenancyService], |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
beforeEach(() => (spectator = createComponent())); |
|
|
beforeEach(() => (spectator = createComponent())); |
|
|
|
|
|
|
|
|
describe('#parseTenantFromUrl', () => { |
|
|
describe('#parseTenantFromUrl', () => { |
|
|
test('should get the tenancyName, set replaced environment and call the findTenantByName method of MultiTenancyService', async () => { |
|
|
test('should get the tenancyName, set replaced environment and call the findTenantByName method of MultiTenancyService', async () => { |
|
|
const injector = spectator.inject(Injector); |
|
|
const environmentService = spectator.inject(EnvironmentService); |
|
|
const injectorSpy = jest.spyOn(injector, 'get'); |
|
|
|
|
|
const store = spectator.inject(Store); |
|
|
|
|
|
const selectSnapshotSpy = jest.spyOn(store, 'selectSnapshot'); |
|
|
|
|
|
const dispatchSpy = jest.spyOn(store, 'dispatch'); |
|
|
|
|
|
const multiTenancyService = spectator.inject(MultiTenancyService); |
|
|
const multiTenancyService = spectator.inject(MultiTenancyService); |
|
|
const findTenantByNameSpy = jest.spyOn(multiTenancyService, 'findTenantByName'); |
|
|
const findTenantByNameSpy = jest.spyOn(multiTenancyService, 'findTenantByName'); |
|
|
|
|
|
const getEnvironmentSpy = jest.spyOn(environmentService, 'getEnvironment'); |
|
|
|
|
|
const setStateSpy = jest.spyOn(environmentService, 'setState'); |
|
|
|
|
|
|
|
|
injectorSpy.mockReturnValueOnce(spectator.inject(Store)); |
|
|
getEnvironmentSpy.mockReturnValue(clone(environment)); |
|
|
injectorSpy.mockReturnValueOnce(multiTenancyService); |
|
|
|
|
|
selectSnapshotSpy.mockReturnValue(clone(environment)); |
|
|
|
|
|
|
|
|
|
|
|
setHref('https://abp.volosoft.com/'); |
|
|
setHref('https://abp.volosoft.com/'); |
|
|
|
|
|
|
|
|
dispatchSpy.mockReturnValue(new BehaviorSubject(true)); |
|
|
|
|
|
findTenantByNameSpy.mockReturnValue( |
|
|
findTenantByNameSpy.mockReturnValue( |
|
|
new BehaviorSubject({ name: 'abp', tenantId: '1', success: true } as FindTenantResultDto), |
|
|
new BehaviorSubject({ name: 'abp', tenantId: '1', success: true } as FindTenantResultDto), |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
parseTenantFromUrl(injector); |
|
|
const mockInjector = { |
|
|
|
|
|
get: arg => { |
|
|
|
|
|
if (arg === EnvironmentService) return environmentService; |
|
|
|
|
|
if (arg === MultiTenancyService) return multiTenancyService; |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
parseTenantFromUrl(mockInjector); |
|
|
|
|
|
|
|
|
const replacedEnv = { |
|
|
const replacedEnv = { |
|
|
...environment, |
|
|
...environment, |
|
|
@ -95,7 +97,7 @@ describe('MultiTenancyUtils', () => { |
|
|
}, |
|
|
}, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
expect(dispatchSpy).toHaveBeenCalledWith({ environment: replacedEnv }); |
|
|
expect(setStateSpy).toHaveBeenCalledWith(replacedEnv); |
|
|
expect(findTenantByNameSpy).toHaveBeenCalledWith('abp', { __tenant: '' }); |
|
|
expect(findTenantByNameSpy).toHaveBeenCalledWith('abp', { __tenant: '' }); |
|
|
expect(multiTenancyService.domainTenant).toEqual({ id: '1', name: 'abp' }); |
|
|
expect(multiTenancyService.domainTenant).toEqual({ id: '1', name: 'abp' }); |
|
|
}); |
|
|
}); |
|
|
|