Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
fix: do not return empty array for missing projections
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Mar 21, 2020
1 parent 89012e2 commit 26db797
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ function project(location = {}, targetAltitude, previousResult) {
const { transitionForestType, transitionAltitudinalZone, ...tl } = location;
tl.forestType = transitionForestType;
tl.altitudinalZone = transitionAltitudinalZone;
const { options, projections: tp } = project(tl, targetAltitude);
Object.entries(options).forEach(([k, v]) => {
const transition = project(tl, targetAltitude);
const tp = transition.projections || [];
Object.entries(transition.options).forEach(([k, v]) => {
if (fieldsConcat.includes(k)) {
result.options[k] = concat(result.options[k], v);
}
Expand All @@ -126,6 +127,10 @@ function project(location = {}, targetAltitude, previousResult) {
.map(ft => ft.code);
}

if (!previousResult && result.projections.length === 0) {
delete result.projections;
}

return result;
}

Expand Down
4 changes: 2 additions & 2 deletions test/project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('valid projections', () => {
},
'50',
).projections,
).toStrictEqual([]);
).toStrictEqual(undefined);
});

test('multi altitudinal zone projection', () => {
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('valid projections', () => {
},
'30',
).projections,
).toStrictEqual([]);
).toStrictEqual(undefined);
});

test('projections based on fixtures', () => {
Expand Down

0 comments on commit 26db797

Please sign in to comment.