Files
dh-inspeccion-v2/api-v3/test/unit/asset-geometry-validator.test.ts
T

48 lines
1.5 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
parseBoundingBox,
validateGeoJsonGeometry,
} from '../../src/asset-master/asset-geometry-validator';
import { AssetGeometryType } from '../../src/database/entities';
test('accepts points and strips unsupported altitude values', () => {
assert.deepEqual(validateGeoJsonGeometry({
type: AssetGeometryType.POINT,
coordinates: [-68.8458, -32.8895, 900],
}), {
type: AssetGeometryType.POINT,
coordinates: [-68.8458, -32.8895],
});
});
test('rejects invalid lines and out-of-range coordinates', () => {
assert.throws(() => validateGeoJsonGeometry({
type: AssetGeometryType.LINESTRING,
coordinates: [[-68, -32], [-68, -32]],
}));
assert.throws(() => validateGeoJsonGeometry({
type: AssetGeometryType.POINT,
coordinates: [-181, -32],
}));
});
test('requires closed, non-degenerate polygon rings', () => {
assert.throws(() => validateGeoJsonGeometry({
type: AssetGeometryType.POLYGON,
coordinates: [[[-68, -32], [-67, -32], [-67, -33]]],
}));
assert.deepEqual(validateGeoJsonGeometry({
type: AssetGeometryType.POLYGON,
coordinates: [[
[-68, -32], [-67, -32], [-67, -33], [-68, -32],
]],
}).type, AssetGeometryType.POLYGON);
});
test('parses only ordered WGS84 bounding boxes', () => {
assert.deepEqual(parseBoundingBox('-70,-35,-66,-31'), [-70, -35, -66, -31]);
assert.throws(() => parseBoundingBox('-66,-31,-70,-35'));
assert.throws(() => parseBoundingBox('-200,-35,-66,-31'));
});