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

Commit ea1d4b1

Browse files
authored
feat: fall back to first projection for secondary fields (#151)
1 parent e99daf9 commit ea1d4b1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/project.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ function projectionReducer(location, targetAltitudePointer, result) {
5252
} else if (valueNotInOptions(value, options[field])) {
5353
// Do not return location values if no projection was found.
5454
return { ...result, options };
55+
} else if (fieldsConcat.includes(field)) {
56+
// Fall back to first projection for secondary fields.
57+
const first = Object.keys(projection)[0];
58+
projection = projection[first];
5559
} else {
5660
// Location does not provide any more values for conditions.
5761
break;

test/project.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,21 @@ describe('valid options', () => {
104104
).toStrictEqual(['unknown', '<20', '>20']);
105105
});
106106

107-
test('empty option field for incomplete location values', () => {
107+
test('option for secondary field', () => {
108108
expect(
109109
project({
110110
forestEcoregion: '1',
111111
altitudinalZone: '90',
112112
forestType: '60*',
113113
}).options.relief,
114+
).toStrictEqual(['unknown']);
115+
});
116+
117+
test('empty option field for incomplete location values', () => {
118+
expect(
119+
project({
120+
forestEcoregion: '1',
121+
}).options.forestType,
114122
).toBe(undefined);
115123
expect(
116124
project({
@@ -135,6 +143,19 @@ describe('valid projections', () => {
135143
).toStrictEqual([{ altitudinalZone: '50', forestType: '1' }]);
136144
});
137145

146+
test('projection with missing secondary fields', () => {
147+
expect(
148+
project(
149+
{
150+
forestEcoregion: '1',
151+
altitudinalZone: '90',
152+
forestType: '60*',
153+
},
154+
'81',
155+
).projections,
156+
).toStrictEqual([{ altitudinalZone: '81', forestType: '50*' }]);
157+
});
158+
138159
test('projection with valid transitionForestType', () => {
139160
expect(
140161
project(

0 commit comments

Comments
 (0)