route tests
This commit is contained in:
parent
dad964b39c
commit
65dd8d64b1
|
@ -43,7 +43,6 @@ export type Path = {
|
||||||
export type Point = {
|
export type Point = {
|
||||||
lon: number;
|
lon: number;
|
||||||
lat: number;
|
lat: number;
|
||||||
context?: PointContext;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SpacetimePoint = Point & {
|
export type SpacetimePoint = Point & {
|
||||||
|
@ -56,14 +55,6 @@ export enum Role {
|
||||||
PASSENGER = 'PASSENGER',
|
PASSENGER = 'PASSENGER',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PointContext {
|
|
||||||
HOUSE_NUMBER = 'HOUSE_NUMBER',
|
|
||||||
STREET_ADDRESS = 'STREET_ADDRESS',
|
|
||||||
LOCALITY = 'LOCALITY',
|
|
||||||
VENUE = 'VENUE',
|
|
||||||
OTHER = 'OTHER',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum PathType {
|
export enum PathType {
|
||||||
GENERIC = 'generic',
|
GENERIC = 'generic',
|
||||||
DRIVER = 'driver',
|
DRIVER = 'driver',
|
||||||
|
|
|
@ -3,7 +3,6 @@ import {
|
||||||
ArgumentOutOfRangeException,
|
ArgumentOutOfRangeException,
|
||||||
ValueObject,
|
ValueObject,
|
||||||
} from '@mobicoop/ddd-library';
|
} from '@mobicoop/ddd-library';
|
||||||
import { PointContext } from '../route.types';
|
|
||||||
|
|
||||||
/** Note:
|
/** Note:
|
||||||
* Value Objects with multiple properties can contain
|
* Value Objects with multiple properties can contain
|
||||||
|
@ -14,7 +13,6 @@ export interface WaypointProps {
|
||||||
position: number;
|
position: number;
|
||||||
lon: number;
|
lon: number;
|
||||||
lat: number;
|
lat: number;
|
||||||
context?: PointContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Waypoint extends ValueObject<WaypointProps> {
|
export class Waypoint extends ValueObject<WaypointProps> {
|
||||||
|
@ -30,10 +28,6 @@ export class Waypoint extends ValueObject<WaypointProps> {
|
||||||
return this.props.lat;
|
return this.props.lat;
|
||||||
}
|
}
|
||||||
|
|
||||||
get context(): PointContext {
|
|
||||||
return this.props.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected validate(props: WaypointProps): void {
|
protected validate(props: WaypointProps): void {
|
||||||
if (props.position < 0)
|
if (props.position < 0)
|
||||||
throw new ArgumentInvalidException(
|
throw new ArgumentInvalidException(
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
import {
|
||||||
|
ArgumentInvalidException,
|
||||||
|
ArgumentOutOfRangeException,
|
||||||
|
} from '@mobicoop/ddd-library';
|
||||||
|
import { Waypoint } from '@modules/geography/core/domain/value-objects/waypoint.value-object';
|
||||||
|
|
||||||
|
describe('Waypoint value object', () => {
|
||||||
|
it('should create a waypoint value object', () => {
|
||||||
|
const waypointVO = new Waypoint({
|
||||||
|
position: 0,
|
||||||
|
lon: 48.689445,
|
||||||
|
lat: 6.17651,
|
||||||
|
});
|
||||||
|
expect(waypointVO.position).toBe(0);
|
||||||
|
expect(waypointVO.lon).toBe(48.689445);
|
||||||
|
expect(waypointVO.lat).toBe(6.17651);
|
||||||
|
});
|
||||||
|
it('should throw an exception if position is invalid', () => {
|
||||||
|
try {
|
||||||
|
new Waypoint({
|
||||||
|
position: -1,
|
||||||
|
lon: 48.689445,
|
||||||
|
lat: 6.17651,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
expect(e).toBeInstanceOf(ArgumentInvalidException);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('should throw an exception if longitude is invalid', () => {
|
||||||
|
try {
|
||||||
|
new Waypoint({
|
||||||
|
position: 0,
|
||||||
|
lon: 348.689445,
|
||||||
|
lat: 6.17651,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
new Waypoint({
|
||||||
|
position: 0,
|
||||||
|
lon: -348.689445,
|
||||||
|
lat: 6.17651,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('should throw an exception if longitude is invalid', () => {
|
||||||
|
try {
|
||||||
|
new Waypoint({
|
||||||
|
position: 0,
|
||||||
|
lon: 48.689445,
|
||||||
|
lat: 96.17651,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
new Waypoint({
|
||||||
|
position: 0,
|
||||||
|
lon: 48.689445,
|
||||||
|
lat: -96.17651,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue