route tests

This commit is contained in:
sbriat
2023-08-21 17:06:28 +02:00
parent e93d8b0c9d
commit dad964b39c
9 changed files with 290 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
export type GeorouterSettings = {
withPoints: boolean;
withTime: boolean;
withDistance: boolean;
points: boolean;
detailedDuration: boolean;
detailedDistance: boolean;
};

View File

@@ -1,7 +1,7 @@
import { PathType } from '../../domain/route.types';
import { Point } from './point.type';
import { Coordinates } from './coordinates.type';
export type Path = {
type: PathType;
points: Point[];
points: Coordinates[];
};

View File

@@ -1,6 +0,0 @@
import { PointContext } from '../../domain/route.types';
import { Coordinates } from './coordinates.type';
export type Point = Coordinates & {
context?: PointContext;
};

View File

@@ -1,5 +1,5 @@
import { PathType } from '../../domain/route.types';
import { Point } from './point.type';
import { Coordinates } from './coordinates.type';
import { SpacetimePoint } from './spacetime-point.type';
export type Route = {
@@ -9,6 +9,6 @@ export type Route = {
fwdAzimuth: number;
backAzimuth: number;
distanceAzimuth: number;
points: Point[];
points: Coordinates[];
spacetimePoints: SpacetimePoint[];
};

View File

@@ -1,6 +1,6 @@
import { Point } from './point.type';
import { Coordinates } from './coordinates.type';
export type SpacetimePoint = Point & {
export type SpacetimePoint = Coordinates & {
duration: number;
distance: number;
};

View File

@@ -1,5 +1,5 @@
import { Point } from './point.type';
import { Coordinates } from './coordinates.type';
export type Waypoint = Point & {
export type Waypoint = Coordinates & {
position: number;
};

View File

@@ -10,15 +10,23 @@ import {
import { WaypointProps } from './value-objects/waypoint.value-object';
import { Route } from '../application/types/route.type';
import { v4 } from 'uuid';
import { RouteNotFoundException } from './route.errors';
export class RouteEntity extends AggregateRoot<RouteProps> {
protected readonly _id: AggregateID;
static create = async (create: CreateRouteProps): Promise<RouteEntity> => {
const directions: Direction[] = await create.georouter.routes(
this.getPaths(create.roles, create.waypoints),
create.georouterSettings,
);
let directions: Direction[];
try {
directions = await create.georouter.routes(
this.getPaths(create.roles, create.waypoints),
create.georouterSettings,
);
if (!directions || directions.length == 0)
throw new RouteNotFoundException();
} catch (e: any) {
throw e;
}
let driverRoute: Route;
let passengerRoute: Route;
if (directions.some((route: Route) => route.type == PathType.GENERIC)) {

View File

@@ -0,0 +1,11 @@
import { ExceptionBase } from '@mobicoop/ddd-library';
export class RouteNotFoundException extends ExceptionBase {
static readonly message = 'Route not found';
public readonly code = 'ROUTE.NOT_FOUND';
constructor(cause?: Error, metadata?: unknown) {
super(RouteNotFoundException.message, cause, metadata);
}
}