use strict null checks
This commit is contained in:
parent
effe51b9a2
commit
f15e7d11b1
|
@ -13,7 +13,7 @@
|
||||||
"@grpc/proto-loader": "^0.7.6",
|
"@grpc/proto-loader": "^0.7.6",
|
||||||
"@liaoliaots/nestjs-redis": "^9.0.5",
|
"@liaoliaots/nestjs-redis": "^9.0.5",
|
||||||
"@mobicoop/configuration-module": "^1.2.0",
|
"@mobicoop/configuration-module": "^1.2.0",
|
||||||
"@mobicoop/ddd-library": "^1.1.0",
|
"@mobicoop/ddd-library": "file:../../packages/dddlibrary",
|
||||||
"@mobicoop/health-module": "^2.0.0",
|
"@mobicoop/health-module": "^2.0.0",
|
||||||
"@mobicoop/message-broker-module": "^1.2.0",
|
"@mobicoop/message-broker-module": "^1.2.0",
|
||||||
"@nestjs/axios": "^2.0.0",
|
"@nestjs/axios": "^2.0.0",
|
||||||
|
@ -1505,9 +1505,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@mobicoop/ddd-library": {
|
"node_modules/@mobicoop/ddd-library": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@mobicoop/ddd-library/-/ddd-library-1.1.0.tgz",
|
"resolved": "file:../../packages/dddlibrary",
|
||||||
"integrity": "sha512-x4X7j2CJYZQPDZgLuZP5TFk59fle1wTPdX++Z2YyD7VwwV+yOmVvMIRfTyLRFUTzLObrd6FKs8mh+g59n9jUlA==",
|
"license": "AGPL",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/event-emitter": "^1.4.2",
|
"@nestjs/event-emitter": "^1.4.2",
|
||||||
"@nestjs/microservices": "^9.4.0",
|
"@nestjs/microservices": "^9.4.0",
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
"@grpc/proto-loader": "^0.7.6",
|
"@grpc/proto-loader": "^0.7.6",
|
||||||
"@liaoliaots/nestjs-redis": "^9.0.5",
|
"@liaoliaots/nestjs-redis": "^9.0.5",
|
||||||
"@mobicoop/configuration-module": "^1.2.0",
|
"@mobicoop/configuration-module": "^1.2.0",
|
||||||
"@mobicoop/ddd-library": "^1.1.0",
|
"@mobicoop/ddd-library": "file:../../packages/dddlibrary",
|
||||||
"@mobicoop/health-module": "^2.0.0",
|
"@mobicoop/health-module": "^2.0.0",
|
||||||
"@mobicoop/message-broker-module": "^1.2.0",
|
"@mobicoop/message-broker-module": "^1.2.0",
|
||||||
"@nestjs/axios": "^2.0.0",
|
"@nestjs/axios": "^2.0.0",
|
||||||
|
|
|
@ -18,7 +18,7 @@ export class CreateAdCommand extends Command {
|
||||||
|
|
||||||
constructor(props: CommandProps<CreateAdCommand>) {
|
constructor(props: CommandProps<CreateAdCommand>) {
|
||||||
super(props);
|
super(props);
|
||||||
this.id = props.id;
|
this.id = props.id as string;
|
||||||
this.driver = props.driver;
|
this.driver = props.driver;
|
||||||
this.passenger = props.passenger;
|
this.passenger = props.passenger;
|
||||||
this.frequency = props.frequency;
|
this.frequency = props.frequency;
|
||||||
|
|
|
@ -18,10 +18,10 @@ export type AdBaseModel = {
|
||||||
seatsProposed: number;
|
seatsProposed: number;
|
||||||
seatsRequested: number;
|
seatsRequested: number;
|
||||||
strict: boolean;
|
strict: boolean;
|
||||||
driverDuration: number;
|
driverDuration?: number;
|
||||||
driverDistance: number;
|
driverDistance?: number;
|
||||||
passengerDuration: number;
|
passengerDuration?: number;
|
||||||
passengerDistance: number;
|
passengerDistance?: number;
|
||||||
fwdAzimuth: number;
|
fwdAzimuth: number;
|
||||||
backAzimuth: number;
|
backAzimuth: number;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export type DefaultParams = {
|
export type DefaultParams = {
|
||||||
GEOROUTER_TYPE: string;
|
GEOROUTER_TYPE?: string;
|
||||||
GEOROUTER_URL: string;
|
GEOROUTER_URL?: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,8 +25,9 @@ export class RouteEntity extends AggregateRoot<RouteProps> {
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
let driverRoute: Route;
|
let baseRoute: Route;
|
||||||
let passengerRoute: Route;
|
let driverRoute: Route | undefined;
|
||||||
|
let passengerRoute: Route | undefined;
|
||||||
if (routes.some((route: Route) => route.type == PathType.GENERIC)) {
|
if (routes.some((route: Route) => route.type == PathType.GENERIC)) {
|
||||||
driverRoute = passengerRoute = routes.find(
|
driverRoute = passengerRoute = routes.find(
|
||||||
(route: Route) => route.type == PathType.GENERIC,
|
(route: Route) => route.type == PathType.GENERIC,
|
||||||
|
@ -41,22 +42,21 @@ export class RouteEntity extends AggregateRoot<RouteProps> {
|
||||||
? routes.find((route: Route) => route.type == PathType.PASSENGER)
|
? routes.find((route: Route) => route.type == PathType.PASSENGER)
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
if (driverRoute) {
|
||||||
|
baseRoute = driverRoute;
|
||||||
|
} else {
|
||||||
|
baseRoute = passengerRoute as Route;
|
||||||
|
}
|
||||||
const routeProps: RouteProps = {
|
const routeProps: RouteProps = {
|
||||||
driverDistance: driverRoute?.distance,
|
driverDistance: driverRoute?.distance,
|
||||||
driverDuration: driverRoute?.duration,
|
driverDuration: driverRoute?.duration,
|
||||||
passengerDistance: passengerRoute?.distance,
|
passengerDistance: passengerRoute?.distance,
|
||||||
passengerDuration: passengerRoute?.duration,
|
passengerDuration: passengerRoute?.duration,
|
||||||
fwdAzimuth: driverRoute
|
fwdAzimuth: baseRoute.fwdAzimuth,
|
||||||
? driverRoute.fwdAzimuth
|
backAzimuth: baseRoute.backAzimuth,
|
||||||
: passengerRoute.fwdAzimuth,
|
distanceAzimuth: baseRoute.distanceAzimuth,
|
||||||
backAzimuth: driverRoute
|
|
||||||
? driverRoute.backAzimuth
|
|
||||||
: passengerRoute.backAzimuth,
|
|
||||||
distanceAzimuth: driverRoute
|
|
||||||
? driverRoute.distanceAzimuth
|
|
||||||
: passengerRoute.distanceAzimuth,
|
|
||||||
waypoints: create.waypoints,
|
waypoints: create.waypoints,
|
||||||
points: driverRoute ? driverRoute.points : passengerRoute.points,
|
points: baseRoute.points,
|
||||||
};
|
};
|
||||||
return new RouteEntity({
|
return new RouteEntity({
|
||||||
id: v4(),
|
id: v4(),
|
||||||
|
@ -111,52 +111,3 @@ export class RouteEntity extends AggregateRoot<RouteProps> {
|
||||||
points,
|
points,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// import { IGeodesic } from '../interfaces/geodesic.interface';
|
|
||||||
// import { Point } from '../types/point.type';
|
|
||||||
// import { SpacetimePoint } from './spacetime-point';
|
|
||||||
|
|
||||||
// export class Route {
|
|
||||||
// distance: number;
|
|
||||||
// duration: number;
|
|
||||||
// fwdAzimuth: number;
|
|
||||||
// backAzimuth: number;
|
|
||||||
// distanceAzimuth: number;
|
|
||||||
// points: Point[];
|
|
||||||
// spacetimePoints: SpacetimePoint[];
|
|
||||||
// private geodesic: IGeodesic;
|
|
||||||
|
|
||||||
// constructor(geodesic: IGeodesic) {
|
|
||||||
// this.distance = undefined;
|
|
||||||
// this.duration = undefined;
|
|
||||||
// this.fwdAzimuth = undefined;
|
|
||||||
// this.backAzimuth = undefined;
|
|
||||||
// this.distanceAzimuth = undefined;
|
|
||||||
// this.points = [];
|
|
||||||
// this.spacetimePoints = [];
|
|
||||||
// this.geodesic = geodesic;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// setPoints = (points: Point[]): void => {
|
|
||||||
// this.points = points;
|
|
||||||
// this.setAzimuth(points);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// setSpacetimePoints = (spacetimePoints: SpacetimePoint[]): void => {
|
|
||||||
// this.spacetimePoints = spacetimePoints;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// protected setAzimuth = (points: Point[]): void => {
|
|
||||||
// const inverse = this.geodesic.inverse(
|
|
||||||
// points[0].lon,
|
|
||||||
// points[0].lat,
|
|
||||||
// points[points.length - 1].lon,
|
|
||||||
// points[points.length - 1].lat,
|
|
||||||
// );
|
|
||||||
// this.fwdAzimuth =
|
|
||||||
// inverse.azimuth >= 0 ? inverse.azimuth : 360 - Math.abs(inverse.azimuth);
|
|
||||||
// this.backAzimuth =
|
|
||||||
// this.fwdAzimuth > 180 ? this.fwdAzimuth - 180 : this.fwdAzimuth + 180;
|
|
||||||
// this.distanceAzimuth = inverse.distance;
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ export type Waypoint = Coordinates & {
|
||||||
|
|
||||||
export type SpacetimePoint = Coordinates & {
|
export type SpacetimePoint = Coordinates & {
|
||||||
duration: number;
|
duration: number;
|
||||||
distance: number;
|
distance?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum Role {
|
export enum Role {
|
||||||
|
|
|
@ -22,6 +22,7 @@ export class Geodesic implements GeodesicPort {
|
||||||
lat2,
|
lat2,
|
||||||
lon2,
|
lon2,
|
||||||
);
|
);
|
||||||
|
if (!azimuth || !distance) throw new Error('Azimuth not found');
|
||||||
return { azimuth, distance };
|
return { azimuth, distance };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,11 +72,12 @@ export class GraphhopperGeorouter implements GeorouterPort {
|
||||||
.map((point) => [point.lat, point.lon].join('%2C'))
|
.map((point) => [point.lat, point.lon].join('%2C'))
|
||||||
.join('&point='),
|
.join('&point='),
|
||||||
].join('');
|
].join('');
|
||||||
const route = await lastValueFrom(
|
return await lastValueFrom(
|
||||||
this.httpService.get(url).pipe(
|
this.httpService.get(url).pipe(
|
||||||
map((res) =>
|
map((response) => {
|
||||||
res.data ? this.createRoute(res, path.type) : undefined,
|
if (response.data) return this.createRoute(response, path.type);
|
||||||
),
|
throw new Error();
|
||||||
|
}),
|
||||||
catchError((error: AxiosError) => {
|
catchError((error: AxiosError) => {
|
||||||
if (error.code == AxiosError.ERR_BAD_REQUEST) {
|
if (error.code == AxiosError.ERR_BAD_REQUEST) {
|
||||||
throw new RouteNotFoundException(
|
throw new RouteNotFoundException(
|
||||||
|
@ -88,7 +89,6 @@ export class GraphhopperGeorouter implements GeorouterPort {
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return route;
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return routes;
|
return routes;
|
||||||
|
@ -156,12 +156,20 @@ export class GraphhopperGeorouter implements GeorouterPort {
|
||||||
const indices = this.getIndices(points, snappedWaypoints);
|
const indices = this.getIndices(points, snappedWaypoints);
|
||||||
const times = this.getTimes(durations, indices);
|
const times = this.getTimes(durations, indices);
|
||||||
const distances = this.getDistances(instructions, indices);
|
const distances = this.getDistances(instructions, indices);
|
||||||
return indices.map((index) => ({
|
return indices.map((index) => {
|
||||||
lon: points[index][1],
|
const duration = times.find((time) => time.index == index);
|
||||||
lat: points[index][0],
|
if (!duration)
|
||||||
distance: distances.find((distance) => distance.index == index)?.distance,
|
throw new Error(`Duration not found for waypoint #${index}`);
|
||||||
duration: times.find((time) => time.index == index)?.duration,
|
const distance = distances.find((distance) => distance.index == index);
|
||||||
}));
|
if (!distance && instructions.length > 0)
|
||||||
|
throw new Error(`Distance not found for waypoint #${index}`);
|
||||||
|
return {
|
||||||
|
lon: points[index][1],
|
||||||
|
lat: points[index][0],
|
||||||
|
distance: distance?.distance,
|
||||||
|
duration: duration.duration,
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private getIndices = (
|
private getIndices = (
|
||||||
|
@ -182,7 +190,7 @@ export class GraphhopperGeorouter implements GeorouterPort {
|
||||||
index: number;
|
index: number;
|
||||||
originIndex: number;
|
originIndex: number;
|
||||||
waypoint: number[];
|
waypoint: number[];
|
||||||
nearest: number;
|
nearest?: number;
|
||||||
distance: number;
|
distance: number;
|
||||||
}
|
}
|
||||||
>{
|
>{
|
||||||
|
@ -209,7 +217,7 @@ export class GraphhopperGeorouter implements GeorouterPort {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const missedWaypoint of missedWaypoints) {
|
for (const missedWaypoint of missedWaypoints) {
|
||||||
indices[missedWaypoint.originIndex] = missedWaypoint.nearest;
|
indices[missedWaypoint.originIndex] = missedWaypoint.nearest as number;
|
||||||
}
|
}
|
||||||
return indices;
|
return indices;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,26 +14,20 @@ import { RouteResponseDto } from './interface/dtos/route.response.dto';
|
||||||
export class RouteMapper
|
export class RouteMapper
|
||||||
implements Mapper<RouteEntity, undefined, undefined, RouteResponseDto>
|
implements Mapper<RouteEntity, undefined, undefined, RouteResponseDto>
|
||||||
{
|
{
|
||||||
toPersistence = (): undefined => {
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
toDomain = (): undefined => {
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
toResponse = (entity: RouteEntity): RouteResponseDto => {
|
toResponse = (entity: RouteEntity): RouteResponseDto => {
|
||||||
const response = new RouteResponseDto();
|
const response = new RouteResponseDto();
|
||||||
response.driverDistance = Math.round(entity.getProps().driverDistance);
|
response.driverDistance = entity.getProps().driverDistance
|
||||||
response.driverDuration = Math.round(entity.getProps().driverDuration);
|
? Math.round(entity.getProps().driverDistance as number)
|
||||||
response.passengerDistance = Math.round(
|
: undefined;
|
||||||
entity.getProps().passengerDistance,
|
response.driverDuration = entity.getProps().driverDuration
|
||||||
);
|
? Math.round(entity.getProps().driverDuration as number)
|
||||||
response.passengerDuration = Math.round(
|
: undefined;
|
||||||
entity.getProps().passengerDuration,
|
response.passengerDistance = entity.getProps().passengerDistance
|
||||||
);
|
? Math.round(entity.getProps().passengerDistance as number)
|
||||||
|
: undefined;
|
||||||
|
response.passengerDuration = entity.getProps().passengerDuration
|
||||||
|
? Math.round(entity.getProps().passengerDuration as number)
|
||||||
|
: undefined;
|
||||||
response.fwdAzimuth = Math.round(entity.getProps().fwdAzimuth);
|
response.fwdAzimuth = Math.round(entity.getProps().fwdAzimuth);
|
||||||
response.backAzimuth = Math.round(entity.getProps().backAzimuth);
|
response.backAzimuth = Math.round(entity.getProps().backAzimuth);
|
||||||
response.distanceAzimuth = Math.round(entity.getProps().distanceAzimuth);
|
response.distanceAzimuth = Math.round(entity.getProps().distanceAzimuth);
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe('Matcher geodesic', () => {
|
||||||
it('should get inverse values', () => {
|
it('should get inverse values', () => {
|
||||||
const geodesic: Geodesic = new Geodesic();
|
const geodesic: Geodesic = new Geodesic();
|
||||||
const inv = geodesic.inverse(0, 0, 1, 1);
|
const inv = geodesic.inverse(0, 0, 1, 1);
|
||||||
expect(Math.round(inv.azimuth)).toBe(45);
|
expect(Math.round(inv.azimuth as number)).toBe(45);
|
||||||
expect(Math.round(inv.distance)).toBe(156900);
|
expect(Math.round(inv.distance as number)).toBe(156900);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,14 +16,6 @@ describe('Route Mapper', () => {
|
||||||
expect(routeMapper).toBeDefined();
|
expect(routeMapper).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should map domain entity to persistence data', async () => {
|
|
||||||
expect(routeMapper.toPersistence()).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should map persisted data to domain entity', async () => {
|
|
||||||
expect(routeMapper.toDomain()).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should map domain entity to response', async () => {
|
it('should map domain entity to response', async () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const routeEntity: RouteEntity = new RouteEntity({
|
const routeEntity: RouteEntity = new RouteEntity({
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
import { WaypointDto } from '../waypoint.dto';
|
import { WaypointDto } from '../waypoint.dto';
|
||||||
|
|
||||||
export const hasValidPositionIndexes = (waypoints: WaypointDto[]): boolean => {
|
export const hasValidPositionIndexes = (waypoints: WaypointDto[]): boolean => {
|
||||||
if (!waypoints) return false;
|
|
||||||
if (waypoints.length == 0) return false;
|
if (waypoints.length == 0) return false;
|
||||||
if (waypoints.every((waypoint) => waypoint.position === undefined))
|
const positions = Array.from(waypoints, (waypoint) => waypoint.position);
|
||||||
return false;
|
positions.sort();
|
||||||
if (waypoints.every((waypoint) => typeof waypoint.position === 'number')) {
|
for (let i = 1; i < positions.length; i++)
|
||||||
const positions = Array.from(waypoints, (waypoint) => waypoint.position);
|
if (positions[i] != positions[i - 1] + 1) return false;
|
||||||
positions.sort();
|
|
||||||
for (let i = 1; i < positions.length; i++)
|
|
||||||
if (positions[i] != positions[i - 1] + 1) return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { IsInt, IsOptional } from 'class-validator';
|
import { IsInt } from 'class-validator';
|
||||||
import { AddressDto } from './address.dto';
|
import { AddressDto } from './address.dto';
|
||||||
|
|
||||||
export class WaypointDto extends AddressDto {
|
export class WaypointDto extends AddressDto {
|
||||||
@IsOptional()
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
position?: number;
|
position: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { hasValidPositionIndexes } from '@modules/matcher/interface/grpc-controllers/dtos/validators/has-valid-position-indexes.validator';
|
import { hasValidPositionIndexes } from '@modules/matcher/interface/grpc-controllers/dtos/validators/has-valid-position-indexes.validator';
|
||||||
import { WaypointDto } from '@modules/matcher/interface/grpc-controllers/dtos/waypoint.dto';
|
import { WaypointDto } from '@modules/matcher/interface/grpc-controllers/dtos/waypoint.dto';
|
||||||
|
|
||||||
describe('addresses position validator', () => {
|
describe('Waypoint position validator', () => {
|
||||||
const mockAddress1: WaypointDto = {
|
const mockAddress1: WaypointDto = {
|
||||||
|
position: 0,
|
||||||
lon: 48.689445,
|
lon: 48.689445,
|
||||||
lat: 6.17651,
|
lat: 6.17651,
|
||||||
houseNumber: '5',
|
houseNumber: '5',
|
||||||
|
@ -12,6 +13,7 @@ describe('addresses position validator', () => {
|
||||||
country: 'France',
|
country: 'France',
|
||||||
};
|
};
|
||||||
const mockAddress2: WaypointDto = {
|
const mockAddress2: WaypointDto = {
|
||||||
|
position: 1,
|
||||||
lon: 48.8566,
|
lon: 48.8566,
|
||||||
lat: 2.3522,
|
lat: 2.3522,
|
||||||
locality: 'Paris',
|
locality: 'Paris',
|
||||||
|
@ -19,45 +21,15 @@ describe('addresses position validator', () => {
|
||||||
country: 'France',
|
country: 'France',
|
||||||
};
|
};
|
||||||
const mockAddress3: WaypointDto = {
|
const mockAddress3: WaypointDto = {
|
||||||
|
position: 2,
|
||||||
lon: 49.2628,
|
lon: 49.2628,
|
||||||
lat: 4.0347,
|
lat: 4.0347,
|
||||||
locality: 'Reims',
|
locality: 'Reims',
|
||||||
postalCode: '51454',
|
postalCode: '51000',
|
||||||
country: 'France',
|
country: 'France',
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should not validate if no position is defined', () => {
|
it('should validate if positions are ordered', () => {
|
||||||
expect(
|
|
||||||
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
|
||||||
).toBeFalsy();
|
|
||||||
});
|
|
||||||
it('should not validate if only one position is defined', () => {
|
|
||||||
mockAddress1.position = 0;
|
|
||||||
expect(
|
|
||||||
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
|
||||||
).toBeFalsy();
|
|
||||||
});
|
|
||||||
it('should not validate if positions are partially defined', () => {
|
|
||||||
mockAddress1.position = 0;
|
|
||||||
mockAddress2.position = null;
|
|
||||||
mockAddress3.position = undefined;
|
|
||||||
expect(
|
|
||||||
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
|
||||||
).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not validate if multiple positions have same value', () => {
|
|
||||||
mockAddress1.position = 0;
|
|
||||||
mockAddress2.position = 1;
|
|
||||||
mockAddress3.position = 1;
|
|
||||||
expect(
|
|
||||||
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
|
||||||
).toBeFalsy();
|
|
||||||
});
|
|
||||||
it('should validate if all positions are ordered', () => {
|
|
||||||
mockAddress1.position = 0;
|
|
||||||
mockAddress2.position = 1;
|
|
||||||
mockAddress3.position = 2;
|
|
||||||
expect(
|
expect(
|
||||||
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
@ -68,8 +40,23 @@ describe('addresses position validator', () => {
|
||||||
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
it('should not validate if positions are not valid', () => {
|
||||||
|
mockAddress1.position = 0;
|
||||||
|
mockAddress2.position = 2;
|
||||||
|
mockAddress3.position = 3;
|
||||||
|
expect(
|
||||||
|
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
||||||
|
).toBeFalsy();
|
||||||
|
});
|
||||||
|
it('should not validate if multiple positions have same value', () => {
|
||||||
|
mockAddress1.position = 0;
|
||||||
|
mockAddress2.position = 1;
|
||||||
|
mockAddress3.position = 1;
|
||||||
|
expect(
|
||||||
|
hasValidPositionIndexes([mockAddress1, mockAddress2, mockAddress3]),
|
||||||
|
).toBeFalsy();
|
||||||
|
});
|
||||||
it('should not validate if no waypoints are defined', () => {
|
it('should not validate if no waypoints are defined', () => {
|
||||||
expect(hasValidPositionIndexes(undefined)).toBeFalsy();
|
|
||||||
expect(hasValidPositionIndexes([])).toBeFalsy();
|
expect(hasValidPositionIndexes([])).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strictNullChecks": false,
|
"strictNullChecks": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"strictBindCallApply": false,
|
"strictBindCallApply": false,
|
||||||
"forceConsistentCasingInFileNames": false,
|
"forceConsistentCasingInFileNames": false,
|
||||||
|
|
Loading…
Reference in New Issue