mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 07:52:41 +00:00
use configuration package for georouter
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import { DefaultParams } from '@modules/geography/core/application/types/default-params.type';
|
||||
import { DefaultParamsProvider } from '@modules/geography/infrastructure/default-params-provider';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const mockConfigService = {
|
||||
get: jest.fn().mockImplementation((value: string) => {
|
||||
switch (value) {
|
||||
case 'GEOROUTER_TYPE':
|
||||
return 'graphhopper';
|
||||
case 'GEOROUTER_URL':
|
||||
return 'http://localhost:8989';
|
||||
default:
|
||||
return 'some_default_value';
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
describe('DefaultParamsProvider', () => {
|
||||
let defaultParamsProvider: DefaultParamsProvider;
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [],
|
||||
providers: [
|
||||
DefaultParamsProvider,
|
||||
{
|
||||
provide: ConfigService,
|
||||
useValue: mockConfigService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
defaultParamsProvider = module.get<DefaultParamsProvider>(
|
||||
DefaultParamsProvider,
|
||||
);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(defaultParamsProvider).toBeDefined();
|
||||
});
|
||||
|
||||
it('should provide default params', async () => {
|
||||
const params: DefaultParams = defaultParamsProvider.getParams();
|
||||
expect(params.GEOROUTER_TYPE).toBe('graphhopper');
|
||||
expect(params.GEOROUTER_URL).toBe('http://localhost:8989');
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,19 @@
|
||||
import { DefaultParamsProviderPort } from '@modules/geography/core/application/ports/default-params-provider.port';
|
||||
import {
|
||||
ConfigurationDomain,
|
||||
ConfigurationDomainGet,
|
||||
Configurator,
|
||||
GetConfigurationRepositoryPort,
|
||||
} from '@mobicoop/configuration-module';
|
||||
import { GeodesicPort } from '@modules/geography/core/application/ports/geodesic.port';
|
||||
import {
|
||||
GeorouterUnavailableException,
|
||||
RouteNotFoundException,
|
||||
} from '@modules/geography/core/domain/route.errors';
|
||||
import { Route, Step } from '@modules/geography/core/domain/route.types';
|
||||
import { GEOGRAPHY_CONFIG_GEOROUTER_URL } from '@modules/geography/geography.constants';
|
||||
import {
|
||||
GEODESIC,
|
||||
PARAMS_PROVIDER,
|
||||
GEOGRAPHY_CONFIGURATION_REPOSITORY,
|
||||
} from '@modules/geography/geography.di-tokens';
|
||||
import { GraphhopperGeorouter } from '@modules/geography/infrastructure/graphhopper-georouter';
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
@@ -262,10 +268,23 @@ const mockGeodesic: GeodesicPort = {
|
||||
distance: jest.fn().mockImplementation(() => 50000),
|
||||
};
|
||||
|
||||
const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||
getParams: jest.fn().mockImplementation(() => ({
|
||||
GEOROUTER_URL: 'http://localhost:8989',
|
||||
})),
|
||||
const mockConfigurationRepository: GetConfigurationRepositoryPort = {
|
||||
get: jest.fn(),
|
||||
mget: jest.fn().mockImplementation(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
(domain: ConfigurationDomain, configs: ConfigurationDomainGet[]) => {
|
||||
switch (domain) {
|
||||
case ConfigurationDomain.GEOGRAPHY:
|
||||
return new Configurator(ConfigurationDomain.GEOGRAPHY, [
|
||||
{
|
||||
domain: ConfigurationDomain.GEOGRAPHY,
|
||||
key: GEOGRAPHY_CONFIG_GEOROUTER_URL,
|
||||
value: 'http://localhost:8989',
|
||||
},
|
||||
]);
|
||||
}
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
describe('Graphhopper Georouter', () => {
|
||||
@@ -281,8 +300,8 @@ describe('Graphhopper Georouter', () => {
|
||||
useValue: mockHttpService,
|
||||
},
|
||||
{
|
||||
provide: PARAMS_PROVIDER,
|
||||
useValue: mockDefaultParamsProvider,
|
||||
provide: GEOGRAPHY_CONFIGURATION_REPOSITORY,
|
||||
useValue: mockConfigurationRepository,
|
||||
},
|
||||
{
|
||||
provide: GEODESIC,
|
||||
|
||||
Reference in New Issue
Block a user