add graphhopper georouter

This commit is contained in:
sbriat
2023-08-23 11:35:48 +02:00
parent a6836b168c
commit 158b12b150
19 changed files with 253 additions and 71 deletions

View File

@@ -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';

View File

@@ -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,

View File

@@ -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);
});
});

View File

@@ -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', () => {