Skip to content

Commit

Permalink
Improve top level geojson negative type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reilem committed Oct 23, 2024
1 parent 1f54441 commit e395b70
Showing 1 changed file with 37 additions and 76 deletions.
113 changes: 37 additions & 76 deletions tests/geojson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { GeoJSON, GeoJSON2D, GeoJSON2DSchema, GeoJSON3D, GeoJSON3DSchema, GeoJSONSchema } from "../src";
import {
GeoJSON,
GeoJSON2D,
GeoJSON2DGeometry,
GeoJSON2DSchema,
GeoJSON3D,
GeoJSON3DGeometry,
GeoJSON3DSchema,
GeoJSONGeometry,
GeoJSONSchema,
} from "../src";

describe("GeoJSONSchema", () => {
it("allows a basic geometry", () => {
Expand Down Expand Up @@ -42,21 +52,22 @@ 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
};
// @ts-expect-error -- THIS SHOULD FAIL
export const invalidGeoJsonPointProperties: GeoJSON = {
type: "Point",
coordinates: [0.0, 0.0],
properties: {},
geometry: testGeometry,
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 invalidGeoJsonGeometryCollection: GeoJSON = {
type: "GeometryCollection",
Expand All @@ -70,11 +81,6 @@ export const invalidGeoJsonGeometryCollection: GeoJSON = {
],
// @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: {},
Expand All @@ -100,10 +106,6 @@ export const invalidGeoJsonFeature: GeoJSON = {
// @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
geometries: {},
otherKey: "allowed",
};
Expand Down Expand Up @@ -139,35 +141,29 @@ export const invalidGeoJsonFeatureCollection: GeoJSON = {
],
// @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 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: [],
// @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 invalidGeoJson2DGeometryCollection: GeoJSON2D = {
type: "GeometryCollection",
Expand All @@ -182,14 +178,7 @@ export const invalidGeoJson2DGeometryCollection: GeoJSON2D = {
// @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",
};
export const invalidGeoJson2DFeature: GeoJSON2D = {
type: "Feature",
Expand All @@ -211,12 +200,7 @@ export const invalidGeoJson2DFeature: GeoJSON2D = {
// @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
geometries: {},
otherKey: "allowed",
};
export const invalidGeoJson2DFeatureCollection: GeoJSON2D = {
type: "FeatureCollection",
Expand Down Expand Up @@ -251,34 +235,30 @@ export const invalidGeoJson2DFeatureCollection: GeoJSON2D = {
// @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 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: [],
// @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 invalidGeoJson3DGeometryCollection: GeoJSON3D = {
type: "GeometryCollection",
Expand All @@ -293,14 +273,7 @@ export const invalidGeoJson3DGeometryCollection: GeoJSON3D = {
// @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",
};
export const invalidGeoJson3DFeature: GeoJSON3D = {
type: "Feature",
Expand All @@ -322,12 +295,7 @@ export const invalidGeoJson3DFeature: GeoJSON3D = {
// @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
geometries: {},
otherKey: "allowed",
};
export const invalidGeoJson3DFeatureCollection: GeoJSON3D = {
type: "FeatureCollection",
Expand Down Expand Up @@ -362,12 +330,5 @@ export const invalidGeoJson3DFeatureCollection: GeoJSON3D = {
// @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",
};

0 comments on commit e395b70

Please sign in to comment.