diff --git a/src/modules/geography/core/domain/route.entity.ts b/src/modules/geography/core/domain/route.entity.ts index 7a18c96..be0613d 100644 --- a/src/modules/geography/core/domain/route.entity.ts +++ b/src/modules/geography/core/domain/route.entity.ts @@ -19,6 +19,7 @@ export class RouteEntity extends AggregateRoot { backAzimuth: route.backAzimuth, distanceAzimuth: route.distanceAzimuth, points: route.points, + steps: route.steps, }; return new RouteEntity({ id: v4(), diff --git a/src/modules/geography/core/domain/route.types.ts b/src/modules/geography/core/domain/route.types.ts index 87d9130..e478575 100644 --- a/src/modules/geography/core/domain/route.types.ts +++ b/src/modules/geography/core/domain/route.types.ts @@ -1,6 +1,7 @@ import { GeorouterPort } from '../application/ports/georouter.port'; import { GeorouterSettings } from '../application/types/georouter-settings.type'; import { PointProps } from './value-objects/point.value-object'; +import { StepProps } from './value-objects/step.value-object'; // All properties that a Route has export interface RouteProps { @@ -10,6 +11,7 @@ export interface RouteProps { backAzimuth: number; distanceAzimuth: number; points: PointProps[]; + steps?: StepProps[]; } // Properties that are needed for a Route creation diff --git a/src/modules/geography/core/domain/value-objects/step.value-object.ts b/src/modules/geography/core/domain/value-objects/step.value-object.ts index 5c04757..0c6d8df 100644 --- a/src/modules/geography/core/domain/value-objects/step.value-object.ts +++ b/src/modules/geography/core/domain/value-objects/step.value-object.ts @@ -8,7 +8,7 @@ import { PointProps } from './point.value-object'; export interface StepProps extends PointProps { duration: number; - distance: number; + distance?: number; } export class Step extends ValueObject { @@ -16,7 +16,7 @@ export class Step extends ValueObject { return this.props.duration; } - get distance(): number { + get distance(): number | undefined { return this.props.distance; } @@ -33,7 +33,7 @@ export class Step extends ValueObject { throw new ArgumentInvalidException( 'duration must be greater than or equal to 0', ); - if (props.distance < 0) + if (props.distance !== undefined && props.distance < 0) throw new ArgumentInvalidException( 'distance must be greater than or equal to 0', ); diff --git a/src/modules/geography/route.mapper.ts b/src/modules/geography/route.mapper.ts index 6353bad..43728f9 100644 --- a/src/modules/geography/route.mapper.ts +++ b/src/modules/geography/route.mapper.ts @@ -22,6 +22,7 @@ export class RouteMapper response.backAzimuth = Math.round(entity.getProps().backAzimuth); response.distanceAzimuth = Math.round(entity.getProps().distanceAzimuth); response.points = entity.getProps().points; + response.steps = entity.getProps().steps; return response; }; } diff --git a/src/modules/geography/tests/unit/infrastructure/graphhopper-georouter.spec.ts b/src/modules/geography/tests/unit/infrastructure/graphhopper-georouter.spec.ts index dad71fb..ce9dec2 100644 --- a/src/modules/geography/tests/unit/infrastructure/graphhopper-georouter.spec.ts +++ b/src/modules/geography/tests/unit/infrastructure/graphhopper-georouter.spec.ts @@ -26,6 +26,11 @@ const mockHttpService = { .mockImplementationOnce(() => { return throwError(() => 'Router unavailable'); }) + .mockImplementationOnce(() => { + return of({ + status: 200, + }); + }) .mockImplementationOnce(() => { return of({ status: 200, @@ -338,6 +343,28 @@ describe('Graphhopper Georouter', () => { ).rejects.toBeInstanceOf(GeorouterUnavailableException); }); + it('should fail if georouter response is corrupted', async () => { + await expect( + graphhopperGeorouter.route( + [ + { + lon: 0, + lat: 0, + }, + { + lon: 1, + lat: 1, + }, + ], + { + detailedDistance: false, + detailedDuration: false, + points: false, + }, + ), + ).rejects.toBeInstanceOf(GeorouterUnavailableException); + }); + it('should create a basic route', async () => { const route: Route = await graphhopperGeorouter.route( [