mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 08:02:41 +00:00
add graphhopper georouter
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { GeorouterPort } from '@modules/geography/core/application/ports/georouter.port';
|
||||
import { GetRouteQuery } from '@modules/geography/core/application/queries/get-route/get-route.query';
|
||||
import { GetRouteQueryHandler } from '@modules/geography/core/application/queries/get-route/get-route.query-handler';
|
||||
import { Waypoint } from '@modules/geography/core/application/types/waypoint.type';
|
||||
import { RouteEntity } from '@modules/geography/core/domain/route.entity';
|
||||
import { Role } from '@modules/geography/core/domain/route.types';
|
||||
import { Role, Waypoint } from '@modules/geography/core/domain/route.types';
|
||||
import { GEOROUTER } from '@modules/geography/geography.di-tokens';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { GeorouterPort } from '@modules/geography/core/application/ports/georouter.port';
|
||||
import { Coordinates } from '@modules/geography/core/application/types/coordinates.type';
|
||||
import { RouteEntity } from '@modules/geography/core/domain/route.entity';
|
||||
import { RouteNotFoundException } from '@modules/geography/core/domain/route.errors';
|
||||
import {
|
||||
Coordinates,
|
||||
CreateRouteProps,
|
||||
PathType,
|
||||
Role,
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { DefaultParamsProviderPort } from '@modules/geography/core/application/ports/default-params-provider.port';
|
||||
import {
|
||||
Path,
|
||||
PathType,
|
||||
Route,
|
||||
} from '@modules/geography/core/domain/route.types';
|
||||
import { PARAMS_PROVIDER } from '@modules/geography/geography.di-tokens';
|
||||
import { GraphhopperGeorouter } from '@modules/geography/infrastructure/graphhopper-georouter';
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const driverPath: Path = {
|
||||
type: PathType.DRIVER,
|
||||
points: [
|
||||
{
|
||||
lon: 6,
|
||||
lat: 47,
|
||||
},
|
||||
{
|
||||
lon: 6.1,
|
||||
lat: 47.1,
|
||||
},
|
||||
{
|
||||
lon: 6.2,
|
||||
lat: 47.2,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const mockHttpService = {};
|
||||
|
||||
const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||
getParams: jest.fn().mockImplementation(() => ({
|
||||
GEOROUTER_URL: 'http://localhost:8989',
|
||||
})),
|
||||
};
|
||||
|
||||
describe('Graphhopper Georouter', () => {
|
||||
let graphhopperGeorouter: GraphhopperGeorouter;
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [],
|
||||
providers: [
|
||||
GraphhopperGeorouter,
|
||||
{
|
||||
provide: HttpService,
|
||||
useValue: mockHttpService,
|
||||
},
|
||||
{
|
||||
provide: PARAMS_PROVIDER,
|
||||
useValue: mockDefaultParamsProvider,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
graphhopperGeorouter =
|
||||
module.get<GraphhopperGeorouter>(GraphhopperGeorouter);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(graphhopperGeorouter).toBeDefined();
|
||||
});
|
||||
|
||||
it('should return basic driver routes', async () => {
|
||||
const paths: Path[] = [driverPath];
|
||||
const driverRoutes: Route[] = await graphhopperGeorouter.routes(paths, {
|
||||
detailedDistance: false,
|
||||
detailedDuration: false,
|
||||
points: true,
|
||||
});
|
||||
expect(driverRoutes.length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Coordinates } from '@modules/geography/core/application/types/coordinates.type';
|
||||
import { Coordinates } from '@modules/geography/core/domain/route.types';
|
||||
import { PostgresDirectionEncoder } from '@modules/geography/infrastructure/postgres-direction-encoder';
|
||||
|
||||
describe('Postgres direction encoder', () => {
|
||||
|
||||
Reference in New Issue
Block a user