diff --git a/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.spec.ts b/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.spec.ts index 5b30b38622..2d0cc835b7 100644 --- a/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.spec.ts +++ b/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.spec.ts @@ -26,13 +26,13 @@ describe(`when features miss cost`, () => { describe(`when given GeoJson isn't a FeatureCollection`, () => { it(`throws exception`, () => { expect(() => sut.extract(fixtures.simpleGeometry())).toThrow( - /is supported/, + /Only FeatureCollection is supported/, ); }); }); describe(`when given GeoJson has pu costs`, () => { - it(`throws exception`, () => { + it(`resolves them`, () => { expect(sut.extract(fixtures.geoFeaturesWithData())).toMatchInlineSnapshot(` Array [ Object { diff --git a/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.ts b/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.ts index dd21e9560d..0adcf55838 100644 --- a/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.ts +++ b/api/apps/geoprocessing/src/modules/surface-cost/adapters/extract-pu-cost.ts @@ -1,4 +1,5 @@ import { isDefined } from '@marxan/utils'; +import { MaybeProperties } from '@marxan/utils/types'; import { FeatureCollection, GeoJSON, Geometry } from 'geojson'; import { PlanningUnitCost } from '../ports/planning-unit-cost'; import { PuExtractorPort } from '../ports/pu-extractor/pu-extractor.port'; @@ -7,14 +8,15 @@ type Properties = { cost: number; planningUnitId: string; }; -type MaybeProperties = Partial | undefined | null; + +type MaybeCost = MaybeProperties; export class ExtractPuCost implements PuExtractorPort { extract(geo: GeoJSON): PlanningUnitCost[] { if (!this.isFeatureCollection(geo)) { throw new Error('Only FeatureCollection is supported.'); } - const input: FeatureCollection = geo; + const input: FeatureCollection = geo; const puCosts = input.features .map((feature) => feature.properties) @@ -36,7 +38,7 @@ export class ExtractPuCost implements PuExtractorPort { return geo.type === 'FeatureCollection'; } - private hasCostValues(properties: MaybeProperties): properties is Properties { + private hasCostValues(properties: MaybeCost): properties is Properties { return ( isDefined(properties) && isDefined(properties.cost) && diff --git a/api/libs/utils/src/types/index.ts b/api/libs/utils/src/types/index.ts new file mode 100644 index 0000000000..57cfe27a74 --- /dev/null +++ b/api/libs/utils/src/types/index.ts @@ -0,0 +1 @@ +export { MaybeProperties } from './maybe-properties'; diff --git a/api/libs/utils/src/types/maybe-properties.ts b/api/libs/utils/src/types/maybe-properties.ts new file mode 100644 index 0000000000..c9c2ab203c --- /dev/null +++ b/api/libs/utils/src/types/maybe-properties.ts @@ -0,0 +1 @@ +export type MaybeProperties = Partial | undefined | null;