add steps to route response

This commit is contained in:
sbriat 2023-09-19 14:30:56 +02:00
parent 1f1502a623
commit 7cac8cbef9
5 changed files with 34 additions and 3 deletions

View File

@ -19,6 +19,7 @@ export class RouteEntity extends AggregateRoot<RouteProps> {
backAzimuth: route.backAzimuth,
distanceAzimuth: route.distanceAzimuth,
points: route.points,
steps: route.steps,
};
return new RouteEntity({
id: v4(),

View File

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

View File

@ -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<StepProps> {
@ -16,7 +16,7 @@ export class Step extends ValueObject<StepProps> {
return this.props.duration;
}
get distance(): number {
get distance(): number | undefined {
return this.props.distance;
}
@ -33,7 +33,7 @@ export class Step extends ValueObject<StepProps> {
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',
);

View File

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

View File

@ -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(
[