route tests
This commit is contained in:
parent
dad964b39c
commit
65dd8d64b1
|
@ -43,7 +43,6 @@ export type Path = {
|
|||
export type Point = {
|
||||
lon: number;
|
||||
lat: number;
|
||||
context?: PointContext;
|
||||
};
|
||||
|
||||
export type SpacetimePoint = Point & {
|
||||
|
@ -56,14 +55,6 @@ export enum Role {
|
|||
PASSENGER = 'PASSENGER',
|
||||
}
|
||||
|
||||
export enum PointContext {
|
||||
HOUSE_NUMBER = 'HOUSE_NUMBER',
|
||||
STREET_ADDRESS = 'STREET_ADDRESS',
|
||||
LOCALITY = 'LOCALITY',
|
||||
VENUE = 'VENUE',
|
||||
OTHER = 'OTHER',
|
||||
}
|
||||
|
||||
export enum PathType {
|
||||
GENERIC = 'generic',
|
||||
DRIVER = 'driver',
|
||||
|
|
|
@ -3,7 +3,6 @@ import {
|
|||
ArgumentOutOfRangeException,
|
||||
ValueObject,
|
||||
} from '@mobicoop/ddd-library';
|
||||
import { PointContext } from '../route.types';
|
||||
|
||||
/** Note:
|
||||
* Value Objects with multiple properties can contain
|
||||
|
@ -14,7 +13,6 @@ export interface WaypointProps {
|
|||
position: number;
|
||||
lon: number;
|
||||
lat: number;
|
||||
context?: PointContext;
|
||||
}
|
||||
|
||||
export class Waypoint extends ValueObject<WaypointProps> {
|
||||
|
@ -30,10 +28,6 @@ export class Waypoint extends ValueObject<WaypointProps> {
|
|||
return this.props.lat;
|
||||
}
|
||||
|
||||
get context(): PointContext {
|
||||
return this.props.context;
|
||||
}
|
||||
|
||||
protected validate(props: WaypointProps): void {
|
||||
if (props.position < 0)
|
||||
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