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

Commit

Permalink
feat: fall back to first projection for secondary fields (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff authored Mar 10, 2020
1 parent e99daf9 commit ea1d4b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function projectionReducer(location, targetAltitudePointer, result) {
} else if (valueNotInOptions(value, options[field])) {
// Do not return location values if no projection was found.
return { ...result, options };
} else if (fieldsConcat.includes(field)) {
// Fall back to first projection for secondary fields.
const first = Object.keys(projection)[0];
projection = projection[first];
} else {
// Location does not provide any more values for conditions.
break;
Expand Down
23 changes: 22 additions & 1 deletion test/project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,21 @@ describe('valid options', () => {
).toStrictEqual(['unknown', '<20', '>20']);
});

test('empty option field for incomplete location values', () => {
test('option for secondary field', () => {
expect(
project({
forestEcoregion: '1',
altitudinalZone: '90',
forestType: '60*',
}).options.relief,
).toStrictEqual(['unknown']);
});

test('empty option field for incomplete location values', () => {
expect(
project({
forestEcoregion: '1',
}).options.forestType,
).toBe(undefined);
expect(
project({
Expand All @@ -135,6 +143,19 @@ describe('valid projections', () => {
).toStrictEqual([{ altitudinalZone: '50', forestType: '1' }]);
});

test('projection with missing secondary fields', () => {
expect(
project(
{
forestEcoregion: '1',
altitudinalZone: '90',
forestType: '60*',
},
'81',
).projections,
).toStrictEqual([{ altitudinalZone: '81', forestType: '50*' }]);
});

test('projection with valid transitionForestType', () => {
expect(
project(
Expand Down

0 comments on commit ea1d4b1

Please sign in to comment.