Skip to content

Commit

Permalink
Fixed logic for upgrading nonexistent filter to expression
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Aug 10, 2024
1 parent 4c7e742 commit d6b6da1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function decimalYearFromDate(date) {
* that require the feature to overlap with the date range.
*/
function constrainFilterByDateRange(filter, dateRange) {
if (typeof filter !== 'undefined' || isLegacyFilter(filter)) {
if (typeof filter !== 'undefined' && isLegacyFilter(filter)) {
return constrainLegacyFilterByDateRange(filter, dateRange);
} else {
return constrainExpressionFilterByDateRange(filter, dateRange);
Expand Down
9 changes: 9 additions & 0 deletions index.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
dateRangeFromISODate,
decimalYearFromDate,
dateRangeFromDate,
constrainFilterByDateRange,
constrainLegacyFilterByDateRange,
constrainExpressionFilterByDateRange,
isLegacyFilter,
Expand Down Expand Up @@ -172,6 +173,14 @@ describe('isLegacyFilter', () => {
});
});

describe('constrainFilterByDateRange', () => {
it('should upgrade nonexistent filter to expression-based filter', () => {
let upgraded = constrainFilterByDateRange(undefined, { startDecimalYear: 2013 });
assert.equal(upgraded.length, 10);
assert.equal(upgraded[0], 'let');
});
});

describe('constrainLegacyFilterByDateRange', () => {
it('should upgrade top-level non-combining filter', () => {
let original = ['in', 'class', 'primary', 'secondary', 'tertiary'];
Expand Down

0 comments on commit d6b6da1

Please # to comment.