diff --git a/lib/src/project.js b/lib/src/project.js index 7f0d0b83..e2f37a25 100644 --- a/lib/src/project.js +++ b/lib/src/project.js @@ -70,6 +70,7 @@ function projectionReducer(location, targetAltitudePointer, result) { .sort((a, b) => a.altitudePointer - b.altitudePointer) .reverse() .find(({ altitudePointer }) => altitudePointer <= targetAltitudePointer); + if (projection && typeof projection.forestType === 'string') { const { altitudinalZone, forestType } = projection; result.projections.push({ altitudinalZone, forestType }); @@ -101,6 +102,16 @@ function project(location = {}, targetAltitude, previousResult) { if (previous && previous.altitudinalZone === last.altitudinalZone) { // Could not find projection to targetAltitude result.projections = []; + + // Try to find projection using "unknown" for secondary fields. + for (let i = 0; i < secondaryFields.length; i += 1) { + const secondaryField = secondaryFields[i]; + if (location[secondaryField] !== 'unknown') { + location[secondaryField] = 'unknown'; + result = project(location, targetAltitude, result); + break; + } + } } else if (lastAltitudeIdx < targetAltitudeIdx) { result = project({ ...location, ...last }, targetAltitude, result); } diff --git a/lib/test/project.test.js b/lib/test/project.test.js index e44c9c33..c36e0fe6 100644 --- a/lib/test/project.test.js +++ b/lib/test/project.test.js @@ -156,6 +156,20 @@ describe('valid projections', () => { ).toStrictEqual([{ altitudinalZone: '80', forestType: '50*' }]); }); + test('projection with fallback to unknown secondary field (silverFirArea)', () => { + expect( + project( + { + forestEcoregion: '2a', + altitudinalZone: '80', + forestType: '50*', + silverFirArea: '2', + }, + '50', + ).projections.slice(-1)[0], + ).toStrictEqual({ altitudinalZone: '50', forestType: '12a' }); + }); + test('projection with valid transitionForestType', () => { expect( project(