mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 08:22:41 +00:00
fix bad tests, fix invalid value object validations
This commit is contained in:
@@ -22,7 +22,7 @@ export class Point extends ValueObject<PointProps> {
|
||||
return this.props.lat;
|
||||
}
|
||||
|
||||
protected validate(props: PointProps): void {
|
||||
validate(props: PointProps): void {
|
||||
if (props.lon > 180 || props.lon < -180)
|
||||
throw new ArgumentOutOfRangeException('lon must be between -180 and 180');
|
||||
if (props.lat > 90 || props.lat < -90)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ArgumentInvalidException, ValueObject } from '@mobicoop/ddd-library';
|
||||
import { PointProps } from './point.value-object';
|
||||
import { Point, PointProps } from './point.value-object';
|
||||
|
||||
/** Note:
|
||||
* Value Objects with multiple properties can contain
|
||||
@@ -29,6 +29,11 @@ export class Step extends ValueObject<StepProps> {
|
||||
}
|
||||
|
||||
protected validate(props: StepProps): void {
|
||||
// validate point props
|
||||
new Point({
|
||||
lon: props.lon,
|
||||
lat: props.lat,
|
||||
});
|
||||
if (props.duration < 0)
|
||||
throw new ArgumentInvalidException(
|
||||
'duration must be greater than or equal to 0',
|
||||
|
||||
@@ -11,39 +11,31 @@ describe('Point value object', () => {
|
||||
expect(pointVO.lon).toBe(6.17651);
|
||||
});
|
||||
it('should throw an exception if longitude is invalid', () => {
|
||||
try {
|
||||
expect(() => {
|
||||
new Point({
|
||||
lat: 48.689445,
|
||||
lon: 186.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
expect(() => {
|
||||
new Point({
|
||||
lat: 48.689445,
|
||||
lon: -186.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
});
|
||||
it('should throw an exception if latitude is invalid', () => {
|
||||
try {
|
||||
expect(() => {
|
||||
new Point({
|
||||
lat: 148.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
expect(() => {
|
||||
new Point({
|
||||
lat: -148.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,71 +18,59 @@ describe('Step value object', () => {
|
||||
expect(stepVO.lon).toBe(6.17651);
|
||||
});
|
||||
it('should throw an exception if longitude is invalid', () => {
|
||||
try {
|
||||
expect(() => {
|
||||
new Step({
|
||||
lat: 48.689445,
|
||||
lon: 186.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
expect(() => {
|
||||
new Step({
|
||||
lon: 48.689445,
|
||||
lat: -186.17651,
|
||||
lat: 48.689445,
|
||||
lon: -186.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
});
|
||||
it('should throw an exception if latitude is invalid', () => {
|
||||
try {
|
||||
expect(() => {
|
||||
new Step({
|
||||
lat: 248.689445,
|
||||
lon: 6.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
expect(() => {
|
||||
new Step({
|
||||
lon: -148.689445,
|
||||
lat: 6.17651,
|
||||
lat: -148.689445,
|
||||
lon: 6.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
}).toThrow(ArgumentOutOfRangeException);
|
||||
});
|
||||
it('should throw an exception if distance is invalid', () => {
|
||||
try {
|
||||
expect(() => {
|
||||
new Step({
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
duration: 150,
|
||||
distance: -12000,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentInvalidException);
|
||||
}
|
||||
}).toThrow(ArgumentInvalidException);
|
||||
});
|
||||
it('should throw an exception if duration is invalid', () => {
|
||||
try {
|
||||
expect(() => {
|
||||
new Step({
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
duration: -150,
|
||||
distance: 12000,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentInvalidException);
|
||||
}
|
||||
}).toThrow(ArgumentInvalidException);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user