diff --git a/tests/bbox.test.ts b/tests/bbox.test.ts index d630f62..1570ef5 100644 --- a/tests/bbox.test.ts +++ b/tests/bbox.test.ts @@ -98,3 +98,15 @@ describe("GeoJSONBBox", () => { }); }); }); + +/** + * Invalid bbox to test types + */ +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidBbox0D: GeoJSONBbox = []; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidBbox1D: GeoJSONBbox = [0.0]; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidBbox2D: GeoJSONBbox = [0.0, 0.0]; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidBbox3D: GeoJSONBbox = [0.0, 0.0, 0.0]; diff --git a/tests/feature.test.ts b/tests/feature.test.ts index 1b62252..4e6a8cb 100644 --- a/tests/feature.test.ts +++ b/tests/feature.test.ts @@ -6,7 +6,14 @@ import { geoJsonFeaturePolygon2D, geoJsonFeaturePolygon3DWithBbox, } from "../examples/feature"; -import { GeoJSON2DFeatureSchema, GeoJSON3DFeatureSchema, GeoJSONFeatureSchema } from "../src"; +import { + GeoJSON2DFeature, + GeoJSON2DFeatureSchema, + GeoJSON3DFeature, + GeoJSON3DFeatureSchema, + GeoJSONFeature, + GeoJSONFeatureSchema, +} from "../src"; function passGeoJSONFeatureSchemaTest(object: unknown) { expect(GeoJSONFeatureSchema.parse(object)).toEqual(object); @@ -165,3 +172,125 @@ describe("GeoJSONFeature", () => { }); }); }); + +/** + * Invalid GeoJSON Feature to test types + */ +export const invalidGeoJsonFeature: GeoJSONFeature = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", +}; + +/** + * Invalid 2D GeoJSON Feature to test types + */ +export const invalidGeoJsonFeature2DPositionTooSmall: GeoJSON2DFeature = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonFeature2DPositionTooBig: GeoJSON2DFeature = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0], + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0, 0.0], +}; + +/** + * Invalid 3D GeoJSON Feature to test types + */ +export const invalidGeoJsonFeature3DPositionTooSmall: GeoJSON3DFeature = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonFeature3DPositionTooBig: GeoJSON3DFeature = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0, 0.0], + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0, 0.0], +}; diff --git a/tests/feature_collection.test.ts b/tests/feature_collection.test.ts index d53c8bb..3ed22ef 100644 --- a/tests/feature_collection.test.ts +++ b/tests/feature_collection.test.ts @@ -8,8 +8,11 @@ import { singleGeoJsonFeatureCollection3D, } from "../examples/feature_collection"; import { + GeoJSON2DFeatureCollection, GeoJSON2DFeatureCollectionSchema, + GeoJSON3DFeatureCollection, GeoJSON3DFeatureCollectionSchema, + GeoJSONFeatureCollection, GeoJSONFeatureCollectionSchema, } from "../src"; @@ -102,3 +105,176 @@ describe("GeoJSONFeatureCollection", () => { }); }); }); + +/** + * Invalid GeoJSON Feature Collection to test types + */ +export const invalidGeoJsonFeatureCollection: GeoJSONFeatureCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + otherKey: "allowed", +}; + +/** + * Invalid 2D GeoJSON Feature Collection to test types + */ +export const invalidGeoJsonFeatureCollection2DPositionTooSmall: GeoJSON2DFeatureCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonFeatureCollection2DPositionTooBig: GeoJSON2DFeatureCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0], + }, + }, + ], +}; + +/** + * Invalid 3D GeoJSON Feature Collection to test types + */ +export const invalidGeoJsonFeatureCollection3DPositionTooSmall: GeoJSON3DFeatureCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonFeatureCollection3DPositionTooBig: GeoJSON3DFeatureCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0, 0.0], + }, + }, + ], +}; diff --git a/tests/geojson.test.ts b/tests/geojson.test.ts index 2bc0a1f..0d1ac7e 100644 --- a/tests/geojson.test.ts +++ b/tests/geojson.test.ts @@ -3,7 +3,17 @@ import { ZodError } from "zod"; import { geoJsonFeaturePolygon2D } from "../examples/feature"; import { multiGeoJsonFeatureCollection2D } from "../examples/feature_collection"; import { geoJsonPoint3D } from "../examples/geometry/point"; -import { GeoJSON2DSchema, GeoJSON3DSchema, GeoJSONSchema } from "../src"; +import { + GeoJSON, + GeoJSON2D, + GeoJSON2DGeometry, + GeoJSON2DSchema, + GeoJSON3D, + GeoJSON3DGeometry, + GeoJSON3DSchema, + GeoJSONGeometry, + GeoJSONSchema, +} from "../src"; describe("GeoJSONSchema", () => { it("allows a basic geometry", () => { @@ -38,3 +48,287 @@ describe("GeoJSONSchema", () => { }); }); }); + +/** + * Invalid GeoJSON to test types + */ +const testGeometry: GeoJSONGeometry = { type: "Point", coordinates: [0.0, 0.0] }; +export const invalidGeoJsonPoint: GeoJSON = { + type: "Point", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], +}; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonPointProperties: GeoJSON = { + type: "Point", + coordinates: [0.0, 0.0], + properties: {}, + geometry: testGeometry, + features: [], + geometries: [], +}; +export const invalidGeoJsonGeometryCollection: GeoJSON = { + type: "GeometryCollection", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonFeature: GeoJSON = { + type: "Feature", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonFeatureCollection: GeoJSON = { + type: "FeatureCollection", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], +}; + +/** + * Invalid 2D GeoJSON to test types + */ +const testGeometry2D: GeoJSON2DGeometry = { type: "Point", coordinates: [0.0, 0.0] }; +export const invalidGeoJson2DPoint: GeoJSON2D = { + type: "Point", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, +}; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJson2DPointProperties: GeoJSON2D = { + type: "Point", + coordinates: [0.0, 0.0], + properties: {}, + geometry: testGeometry2D, + features: [], + geometries: [], +}; +export const invalidGeoJson2DGeometryCollection: GeoJSON2D = { + type: "GeometryCollection", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, +}; +export const invalidGeoJson2DFeature: GeoJSON2D = { + type: "Feature", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, +}; +export const invalidGeoJson2DFeatureCollection: GeoJSON2D = { + type: "FeatureCollection", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, +}; + +/** + * Invalid 3D GeoJSON to test types + */ +const testGeometry3D: GeoJSON3DGeometry = { type: "Point", coordinates: [0.0, 0.0, 0.0] }; +export const invalidGeoJson3DPoint: GeoJSON3D = { + type: "Point", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, +}; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJson3DPointProperties: GeoJSON3D = { + type: "Point", + coordinates: [0.0, 0.0, 0.0], + properties: {}, + geometry: testGeometry3D, + features: [], + geometries: [], +}; +export const invalidGeoJson3DGeometryCollection: GeoJSON3D = { + type: "GeometryCollection", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, +}; +export const invalidGeoJson3DFeature: GeoJSON3D = { + type: "Feature", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, +}; +export const invalidGeoJson3DFeatureCollection: GeoJSON3D = { + type: "FeatureCollection", + features: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + geometry: { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Bar", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", + }, + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: {}, + otherKey: "allowed", + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, +}; diff --git a/tests/geometry/geometry.test.ts b/tests/geometry/geometry.test.ts new file mode 100644 index 0000000..33f464a --- /dev/null +++ b/tests/geometry/geometry.test.ts @@ -0,0 +1,134 @@ +import { singleGeoJsonGeometryCollection2D } from "../../examples/geometry/geometry_collection"; +import { geoJsonPoint2D } from "../../examples/geometry/point"; +import { GeoJSON2DGeometry, GeoJSON3DGeometry, GeoJSONGeometry, GeoJSONGeometrySchema } from "../../src"; +import { describe, expect, it } from "@jest/globals"; + +describe("GeoJSONGeometry", () => { + it("allows a valid simple geometry", () => { + expect(GeoJSONGeometrySchema.parse(geoJsonPoint2D)).toEqual(geoJsonPoint2D); + }); + + it("allows a valid geometry collection", () => { + expect(GeoJSONGeometrySchema.parse(singleGeoJsonGeometryCollection2D)).toEqual( + singleGeoJsonGeometryCollection2D, + ); + }); +}); + +/** + * Invalid GeoJSON Geometry to test types + */ +export const invalidGeoJsonGeometry: GeoJSONGeometry = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonGeometryAsCollection: GeoJSONGeometry = { + type: "GeometryCollection", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; + +/** + * Invalid 2D GeoJSON Geometry to test types + */ +export const invalidGeoJsonGeometry2DPositionTooSmall: GeoJSON2DGeometry = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonGeometry2DPositionTooBig: GeoJSON2DGeometry = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0, 0.0], +}; +export const invalidGeoJsonGeometry2DAsCollection: GeoJSON2DGeometry = { + type: "GeometryCollection", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; + +/** + * Invalid 3D GeoJSON Geometry to test types + */ +export const invalidGeoJsonGeometry3DPositionTooSmall: GeoJSON3DGeometry = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonGeometry3DPositionTooBig: GeoJSON3DGeometry = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0, 0.0], +}; +export const invalidGeoJsonGeometry3DAsCollection: GeoJSON3DGeometry = { + type: "GeometryCollection", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0], + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; diff --git a/tests/geometry/geometry_collection.test.ts b/tests/geometry/geometry_collection.test.ts index 0649bc0..af064e6 100644 --- a/tests/geometry/geometry_collection.test.ts +++ b/tests/geometry/geometry_collection.test.ts @@ -12,8 +12,11 @@ import { geoJsonLineString3D } from "../../examples/geometry/line_string"; import { geoJsonMultiPoint2D } from "../../examples/geometry/multi_point"; import { geoJsonPoint2D } from "../../examples/geometry/point"; import { + GeoJSON2DGeometryCollection, GeoJSON2DGeometryCollectionSchema, + GeoJSON3DGeometryCollection, GeoJSON3DGeometryCollectionSchema, + GeoJSONGeometryCollection, GeoJSONGeometryCollectionSchema, } from "../../src"; import { failGeoJSONGeometrySchemaTest, passGeoJSONGeometrySchemaTest } from "./_helpers"; @@ -178,3 +181,112 @@ describe("GeoJSONGeometryCollection", () => { }); }); }); + +/** + * Invalid GeoJSON GeometryCollection to test types + */ +export const invalidGeoJsonGeometryCollection: GeoJSONGeometryCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; + +/** + * Invalid 2D GeoJSON GeometryCollection to test types + */ +export const invalidGeoJsonGeometryCollection2DPositionTooSmall: GeoJSON2DGeometryCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonGeometryCollection2DPositionTooBig: GeoJSON2DGeometryCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0, 0.0], +}; + +/** + * Invalid 3D GeoJSON GeometryCollection to test types + */ +export const invalidGeoJsonGeometryCollection3DPositionTooSmall: GeoJSON3DGeometryCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonGeometryCollection3DPositionTooBig: GeoJSON3DGeometryCollection = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + geometries: [ + { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Foo", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 0.0, 0.0, 0.0], + }, + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0, 0.0], +}; diff --git a/tests/geometry/line_string.test.ts b/tests/geometry/line_string.test.ts index 9ad81e9..7cdd35f 100644 --- a/tests/geometry/line_string.test.ts +++ b/tests/geometry/line_string.test.ts @@ -6,7 +6,14 @@ import { geoJsonLineString3D, geoJsonLineString3DWithBbox, } from "../../examples/geometry/line_string"; -import { GeoJSON2DLineStringSchema, GeoJSON3DLineStringSchema, GeoJSONLineStringSchema } from "../../src"; +import { + GeoJSON2DLineString, + GeoJSON2DLineStringSchema, + GeoJSON3DLineString, + GeoJSON3DLineStringSchema, + GeoJSONLineString, + GeoJSONLineStringSchema, +} from "../../src"; import { failGeoJSONGeometrySchemaTest, passGeoJSONGeometrySchemaTest } from "./_helpers"; function passGeoJSONLineStringTest(value: unknown): void { @@ -140,3 +147,115 @@ describe("GeoJSONLineString", () => { }); }); }); + +/** + * Invalid GeoJSON MultiPoint to test types + */ +export const invalidGeoJsonLineStringTooFewPositions: GeoJSONLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 0.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonLineStringPositionTooSmall: GeoJSONLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 0.0], [0.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], +}; + +/** + * Invalid 2D GeoJSON LineString to test types + */ +export const invalidGeoJsonLineString2DTooFewPositions: GeoJSON2DLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 0.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonLineString2DPositionTooSmall: GeoJSON2DLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 0.0], [0.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], +}; +export const invalidGeoJsonLineString2DPositionTooBig: GeoJSON2DLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0, 0.0], +}; + +/** + * Invalid 3D GeoJSON LineString to test types + */ +export const invalidGeoJsonLineString3DTooFewPositions: GeoJSON3DLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 2.0, 0.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonLineString3DPositionTooSmall: GeoJSON3DLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [1.0, 2.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 2.0], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], +}; +export const invalidGeoJsonLineString3DPositionTooBig: GeoJSON3DLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [1.0, 2.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 2.0, 0.0, 0.0], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0, 3.0], +}; diff --git a/tests/geometry/multi_line_string.test.ts b/tests/geometry/multi_line_string.test.ts index 499b1a2..cd4aaed 100644 --- a/tests/geometry/multi_line_string.test.ts +++ b/tests/geometry/multi_line_string.test.ts @@ -10,8 +10,11 @@ import { singleGeoJsonMultiLineString3DWithBbox, } from "../../examples/geometry/multi_line_string"; import { + GeoJSON2DMultiLineString, GeoJSON2DMultiLineStringSchema, + GeoJSON3DMultiLineString, GeoJSON3DMultiLineStringSchema, + GeoJSONMultiLineString, GeoJSONMultiLineStringSchema, } from "../../src"; import { failGeoJSONGeometrySchemaTest, passGeoJSONGeometrySchemaTest } from "./_helpers"; @@ -161,3 +164,127 @@ describe("GeoJSONMultiLineString", () => { }); }); }); + +/** + * Invalid GeoJSON MultiPoint to test types + */ +export const invalidGeoJsonMultiLineStringTooFewPositions: GeoJSONMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + [1.0, 0.0], + [1.0, 0.0], + ], + // @ts-expect-error -- THIS SHOULD FAIL + [[0.0, 0.0]], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiLineStringPositionTooSmall: GeoJSONMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[1.0, 0.0], [0.0]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], +}; + +/** + * Invalid 2D GeoJSON MultiLineString to test types + */ +export const invalidGeoJsonMultiLineString2DTooFewPositions: GeoJSON2DMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[1.0, 0.0]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiLineString2DPositionTooSmall: GeoJSON2DMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[1.0, 0.0], [0.0]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0], +}; +export const invalidGeoJsonMultiLineString2DPositionTooBig: GeoJSON2DMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0, 0.0], +}; + +/** + * Invalid 3D GeoJSON MultiLineString to test types + */ +export const invalidGeoJsonMultiLineString3DTooFewPositions: GeoJSON3DMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[1.0, 2.0, 0.0]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiLineString3DPositionTooSmall: GeoJSON3DMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + [1.0, 2.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 2.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], +}; +export const invalidGeoJsonMultiLineString3DPositionTooBig: GeoJSON3DMultiLineString = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + [1.0, 2.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 2.0, 0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0, 3.0], +}; diff --git a/tests/geometry/multi_point.test.ts b/tests/geometry/multi_point.test.ts index aec29e3..68da7b9 100644 --- a/tests/geometry/multi_point.test.ts +++ b/tests/geometry/multi_point.test.ts @@ -7,7 +7,14 @@ import { geoJsonMultiPoint3DWithBbox, } from "../../examples/geometry/multi_point"; import { geoJsonPoint2D, geoJsonPoint3D } from "../../examples/geometry/point"; -import { GeoJSON2DMultiPointSchema, GeoJSON3DMultiPointSchema, GeoJSONMultiPointSchema } from "../../src"; +import { + GeoJSON2DMultiPoint, + GeoJSON2DMultiPointSchema, + GeoJSON3DMultiPoint, + GeoJSON3DMultiPointSchema, + GeoJSONMultiPoint, + GeoJSONMultiPointSchema, +} from "../../src"; import { failGeoJSONGeometrySchemaTest, passGeoJSONGeometrySchemaTest } from "./_helpers"; function passGeoJSONMultiPointTest(value: unknown): void { @@ -137,3 +144,82 @@ describe("GeoJSONMultiPoint", () => { }); }); }); + +/** + * Invalid GeoJSON MultiPoint to test types + */ +export const invalidGeoJsonMultiPoint: GeoJSONMultiPoint = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; + +/** + * Invalid 2D GeoJSON MultiPoint to test types + */ +export const invalidGeoJsonMultiPoint2DPositionTooSmall: GeoJSON2DMultiPoint = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiPoint2DPositionTooBig: GeoJSON2DMultiPoint = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 2.0, 3.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], +}; + +/** + * Invalid 3D GeoJSON MultiPoint to test types + */ +export const invalidGeoJsonMultiPoint3DPositionTooSmall: GeoJSON3DMultiPoint = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 2.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiPoint3DPositionTooBig: GeoJSON3DMultiPoint = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[1.0, 2.0, 0.0, 0.0]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0, 3.0], +}; diff --git a/tests/geometry/multi_polygon.test.ts b/tests/geometry/multi_polygon.test.ts index 5ed3705..e7b0be6 100644 --- a/tests/geometry/multi_polygon.test.ts +++ b/tests/geometry/multi_polygon.test.ts @@ -9,7 +9,14 @@ import { singleGeoJsonMultiPolygon3DWithBbox, } from "../../examples/geometry/multi_polygon"; import { geoJsonPolygon2D, geoJsonPolygon3D } from "../../examples/geometry/polygon"; -import { GeoJSON2DMultiPolygonSchema, GeoJSON3DMultiPolygonSchema, GeoJSONMultiPolygonSchema } from "../../src"; +import { + GeoJSON2DMultiPolygon, + GeoJSON2DMultiPolygonSchema, + GeoJSON3DMultiPolygon, + GeoJSON3DMultiPolygonSchema, + GeoJSONMultiPolygon, + GeoJSONMultiPolygonSchema, +} from "../../src"; import { failGeoJSONGeometrySchemaTest, passGeoJSONGeometrySchemaTest } from "./_helpers"; function passGeoJSONMultiPolygonTest(value: unknown): void { @@ -190,3 +197,164 @@ describe("GeoJSONMultiPolygon", () => { }); }); }); + +/** + * Invalid GeoJSON MultiPolygon to test types + */ +export const invalidGeoJsonMultiPolygonRingTooSmall: GeoJSONMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [ + [0.0, 0.0], + [1.0, 0.0], + [0.0, 0.0], + ], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiPolygonPositionsTooSmall: GeoJSONMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[[0.0], [1.0], [0.0], [0.0]]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], +}; + +/** + * Invalid 2D GeoJSON MultiPolygon to test types + */ +export const invalidGeoJsonMultiPolygon2DRingTooSmall: GeoJSON2DMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [ + [0.0, 0.0], + [1.0, 0.0], + [0.0, 0.0], + ], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiPolygon2DPositionsTooSmall: GeoJSON2DMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[0.0], [1.0], [0.0], [0.0]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], +}; +export const invalidGeoJsonMultiPolygon2DPositionsTooBig: GeoJSON2DMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0, 0.0], +}; + +/** + * Invalid 3D GeoJSON MultiPolygon to test types + */ +export const invalidGeoJsonMultiPolygon3DRingTooSmall: GeoJSON3DMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [ + [0.0, 0.0, 0.0], + [1.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonMultiPolygon3DPositionsTooSmall: GeoJSON3DMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0], + ], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], +}; +export const invalidGeoJsonMultiPolygon3DPositionsTooBig: GeoJSON3DMultiPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0, 0.0], + ], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0, 0.0], +}; diff --git a/tests/geometry/point.test.ts b/tests/geometry/point.test.ts index 6d7e0d3..fe9c243 100644 --- a/tests/geometry/point.test.ts +++ b/tests/geometry/point.test.ts @@ -147,28 +147,71 @@ export const invalidGeoJsonPoint: GeoJSONPoint = { coordinates: [1.0], // @ts-expect-error -- THIS SHOULD FAIL bbox: [1.0, 2.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", }; /** - * Invalid 2D GeoJSON Point to test types + * Invalid 2D GeoJSON Points to test types */ -export const invalidGeoJsonPoint2D: GeoJSON2DPoint = { +export const invalidGeoJsonPoint2DPositionTooSmall: GeoJSON2DPoint = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonPoint2DPositionTooBig: GeoJSON2DPoint = { // @ts-expect-error -- THIS SHOULD FAIL type: "Hello", // @ts-expect-error -- THIS SHOULD FAIL coordinates: [1.0, 2.0, 3.0], // @ts-expect-error -- THIS SHOULD FAIL - bbox: [1.0], + bbox: [1.0, 0.0, 0.0], }; /** * Invalid 3D GeoJSON Point to test types */ -export const invalidGeoJsonPoint3D: GeoJSON3DPoint = { +export const invalidGeoJsonPoint3DPositionTooSmall: GeoJSON3DPoint = { // @ts-expect-error -- THIS SHOULD FAIL type: "Hello", // @ts-expect-error -- THIS SHOULD FAIL coordinates: [1.0, 2.0], // @ts-expect-error -- THIS SHOULD FAIL - bbox: [1.0, 2.0, 3.0], + bbox: [1.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonPoint3DPositionTooBig: GeoJSON3DPoint = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [1.0, 2.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [1.0, 2.0], }; diff --git a/tests/geometry/polygon.test.ts b/tests/geometry/polygon.test.ts index d4f7464..d9c9cb9 100644 --- a/tests/geometry/polygon.test.ts +++ b/tests/geometry/polygon.test.ts @@ -6,7 +6,14 @@ import { geoJsonPolygon2DWithHoleAndBbox, geoJsonPolygon3D, } from "../../examples/geometry/polygon"; -import { GeoJSON2DPolygonSchema, GeoJSON3DPolygonSchema, GeoJSONPolygonSchema } from "../../src"; +import { + GeoJSON2DPolygon, + GeoJSON2DPolygonSchema, + GeoJSON3DPolygon, + GeoJSON3DPolygonSchema, + GeoJSONPolygon, + GeoJSONPolygonSchema, +} from "../../src"; import { failGeoJSONGeometrySchemaTest, passGeoJSONGeometrySchemaTest } from "./_helpers"; function passGeoJSONPolygonTest(value: unknown): void { @@ -186,3 +193,154 @@ describe("GeoJSONPolygon", () => { }); }); }); + +/** + * Invalid GeoJSON Polygon to test types + */ +export const invalidGeoJsonPolygonRingTooSmall: GeoJSONPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + // @ts-expect-error -- THIS SHOULD FAIL + [ + [0.0, 0.0], + [1.0, 0.0], + [0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonPolygonPositionsTooSmall: GeoJSONPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[0.0], [1.0], [0.0], [0.0]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], +}; + +/** + * Invalid 2D GeoJSON Polygon to test types + */ +export const invalidGeoJsonPolygon2DRingTooSmall: GeoJSON2DPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + // @ts-expect-error -- THIS SHOULD FAIL + [ + [0.0, 0.0], + [1.0, 0.0], + [0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonPolygon2DPositionsTooSmall: GeoJSON2DPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + // @ts-expect-error -- THIS SHOULD FAIL + coordinates: [[[0.0], [1.0], [0.0], [0.0]]], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], +}; +export const invalidGeoJsonPolygon2DPositionsTooBig: GeoJSON2DPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0, 0.0], +}; + +/** + * Invalid 3D GeoJSON Polygon to test types + */ +export const invalidGeoJsonPolygon3DRingTooSmall: GeoJSON3DPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + // @ts-expect-error -- THIS SHOULD FAIL + [ + [0.0, 0.0, 0.0], + [1.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0], + // @ts-expect-error -- THIS SHOULD FAIL + features: [], + // @ts-expect-error -- THIS SHOULD FAIL + geometries: [], + // @ts-expect-error -- THIS SHOULD FAIL + properties: {}, + // @ts-expect-error -- THIS SHOULD FAIL + geometry: {}, + otherKey: "allowed", +}; +export const invalidGeoJsonPolygon3DPositionsTooSmall: GeoJSON3DPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0], +}; +export const invalidGeoJsonPolygon3DPositionsTooBig: GeoJSON3DPolygon = { + // @ts-expect-error -- THIS SHOULD FAIL + type: "Hello", + coordinates: [ + [ + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [1.0, 0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0, 0.0], + // @ts-expect-error -- THIS SHOULD FAIL + [0.0, 0.0, 0.0, 0.0], + ], + ], + // @ts-expect-error -- THIS SHOULD FAIL + bbox: [0.0, 0.0, 0.0], +}; diff --git a/tests/position.test.ts b/tests/geometry/position.test.ts similarity index 63% rename from tests/position.test.ts rename to tests/geometry/position.test.ts index 714e8a8..c29e35c 100644 --- a/tests/position.test.ts +++ b/tests/geometry/position.test.ts @@ -1,6 +1,13 @@ import { describe, expect, it } from "@jest/globals"; import { ZodError } from "zod"; -import { GeoJSON2DPositionSchema, GeoJSON3DPositionSchema, GeoJSONPosition, GeoJSONPositionSchema } from "../src"; +import { + GeoJSON2DPosition, + GeoJSON2DPositionSchema, + GeoJSON3DPosition, + GeoJSON3DPositionSchema, + GeoJSONPosition, + GeoJSONPositionSchema, +} from "../../src"; const position2D: GeoJSONPosition = [0, 0]; @@ -44,3 +51,25 @@ describe("GeoJSONPosition", () => { }); }); }); + +/** + * Invalid GeoJSON position to test types + */ +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonPosition: GeoJSONPosition = [1]; + +/** + * Invalid 2D GeoJSON positions to test types + */ +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonPosition2DTooBig: GeoJSON2DPosition = [1, 2, 3]; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonPosition2DTooSmall: GeoJSON2DPosition = [1]; + +/** + * Invalid 3D GeoJSON positions to test types + */ +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonPosition3DTooBig: GeoJSON3DPosition = [1, 2, 3, 4]; +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonPosition3DTooSmall: GeoJSON3DPosition = [1, 2]; diff --git a/tests/geometry/type.test.ts b/tests/geometry/type.test.ts new file mode 100644 index 0000000..bed9348 --- /dev/null +++ b/tests/geometry/type.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from "@jest/globals"; +import { ZodError } from "zod"; +import { GeoJSONGeometryType, GeoJSONGeometryTypeSchema, GeoJSONTypeSchema } from "../../src"; + +describe("GeoJSONGeometryType", () => { + const geoJsonGeometryTypes: GeoJSONGeometryType[] = [ + "Point", + "MultiPoint", + "LineString", + "MultiLineString", + "Polygon", + "MultiPolygon", + "GeometryCollection", + ]; + + geoJsonGeometryTypes.forEach((type) => + it(`allows ${type} geojson geometry type`, () => { + expect(GeoJSONGeometryTypeSchema.parse(type)).toEqual(type); + expect(GeoJSONTypeSchema.parse(type)).toEqual(type); + }), + ); + + it("does not allow an invalid geojson geometry type", () => { + expect(() => GeoJSONGeometryTypeSchema.parse("InvalidType")).toThrow(ZodError); + }); +}); + +/** + * Invalid GeoJSON geometry type to test types + */ +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonGeometryType: GeoJSONGeometryType = "Foo"; diff --git a/tests/type.test.ts b/tests/type.test.ts index aeae8d6..217aefd 100644 --- a/tests/type.test.ts +++ b/tests/type.test.ts @@ -1,29 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { ZodError } from "zod"; -import { GeoJSONGeometryType, GeoJSONGeometryTypeSchema, GeoJSONType, GeoJSONTypeSchema } from "../src"; - -describe("GeoJSONGeometryType", () => { - const geoJsonGeometryTypes: GeoJSONGeometryType[] = [ - "Point", - "MultiPoint", - "LineString", - "MultiLineString", - "Polygon", - "MultiPolygon", - "GeometryCollection", - ]; - - geoJsonGeometryTypes.forEach((type) => - it(`allows ${type} geojson geometry type`, () => { - expect(GeoJSONGeometryTypeSchema.parse(type)).toEqual(type); - expect(GeoJSONTypeSchema.parse(type)).toEqual(type); - }), - ); - - it("does not allow an invalid geojson geometry type", () => { - expect(() => GeoJSONGeometryTypeSchema.parse("InvalidType")).toThrow(ZodError); - }); -}); +import { GeoJSONType, GeoJSONTypeSchema } from "../src"; describe("GeoJSONType", () => { const geoJsonTypes: GeoJSONType[] = ["Feature", "FeatureCollection"]; @@ -35,3 +12,9 @@ describe("GeoJSONType", () => { expect(() => GeoJSONTypeSchema.parse("InvalidType")).toThrow(ZodError); }); }); + +/** + * Invalid GeoJSON type to test types + */ +// @ts-expect-error -- THIS SHOULD FAIL +export const invalidGeoJsonType: GeoJSONType = "Foo";