Skip to content

Commit 7dc6919

Browse files
committed
more tests for PreAggregationPartitionRangeLoader.intersectDateRanges()
1 parent ea32c3d commit 7dc6919

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

packages/cubejs-query-orchestrator/test/unit/PreAggregations.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,50 @@ describe('PreAggregations', () => {
396396
['2024-01-05T00:00:00.000', '2024-01-05T23:59:59.999']
397397
);
398398
});
399+
400+
test('returns null if ranges do not overlap', () => {
401+
expect(
402+
PreAggregationPartitionRangeLoader.intersectDateRanges(
403+
['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999'],
404+
['2024-02-01T00:00:00.000', '2024-02-28T23:59:59.999']
405+
)
406+
).toBeNull();
407+
});
408+
409+
test('returns rangeA if rangeB is null', () => {
410+
expect(
411+
PreAggregationPartitionRangeLoader.intersectDateRanges(
412+
['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999'],
413+
null
414+
)
415+
).toEqual(['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999']);
416+
});
417+
418+
test('returns rangeB if rangeA is null', () => {
419+
expect(
420+
PreAggregationPartitionRangeLoader.intersectDateRanges(
421+
null,
422+
['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999']
423+
)
424+
).toEqual(['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999']);
425+
});
426+
427+
test('throws error if range is not a tuple of two strings', () => {
428+
expect(() => PreAggregationPartitionRangeLoader.intersectDateRanges(
429+
['2024-01-01T00:00:00.000'],
430+
['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999']
431+
)).toThrow('Date range expected to be an array with 2 elements');
432+
433+
expect(() => PreAggregationPartitionRangeLoader.intersectDateRanges(
434+
['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999', '2024-01-01T00:00:00.000'],
435+
['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999']
436+
))
437+
.toThrow('Date range expected to be an array with 2 elements');
438+
439+
expect(() => PreAggregationPartitionRangeLoader.intersectDateRanges(
440+
['2024-01-01T00:00:00', '2024-01-31T23:59:59.999'], // incorrect format
441+
['2024-01-01T00:00:00.000', '2024-01-31T23:59:59.999']
442+
)).toThrow('Date range expected to be in YYYY-MM-DDTHH:mm:ss.SSS format');
443+
});
399444
});
400445
});

0 commit comments

Comments
 (0)