Skip to content

Commit deb0155

Browse files
committed
add more tests for timeSeries()
1 parent d0440f7 commit deb0155

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

packages/cubejs-backend-shared/test/time.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,59 @@ describe('timeSeries', () => {
2323
]);
2424
});
2525

26+
it('time series - month', () => {
27+
expect(timeSeries('month', ['2021-01-01', '2021-06-01'])).toEqual([
28+
['2021-01-01T00:00:00.000', '2021-01-31T23:59:59.999'],
29+
['2021-02-01T00:00:00.000', '2021-02-28T23:59:59.999'],
30+
['2021-03-01T00:00:00.000', '2021-03-31T23:59:59.999'],
31+
['2021-04-01T00:00:00.000', '2021-04-30T23:59:59.999'],
32+
['2021-05-01T00:00:00.000', '2021-05-31T23:59:59.999'],
33+
['2021-06-01T00:00:00.000', '2021-06-30T23:59:59.999'],
34+
]);
35+
});
36+
37+
it('time series - year', () => {
38+
expect(timeSeries('year', ['2019-01-01', '2021-12-31'])).toEqual([
39+
['2019-01-01T00:00:00.000', '2019-12-31T23:59:59.999'],
40+
['2020-01-01T00:00:00.000', '2020-12-31T23:59:59.999'],
41+
['2021-01-01T00:00:00.000', '2021-12-31T23:59:59.999'],
42+
]);
43+
});
44+
45+
it('time series - hour', () => {
46+
expect(timeSeries('hour', ['2021-01-01T10:00:00', '2021-01-01T12:00:00'])).toEqual([
47+
['2021-01-01T10:00:00.000', '2021-01-01T10:59:59.999'],
48+
['2021-01-01T11:00:00.000', '2021-01-01T11:59:59.999'],
49+
['2021-01-01T12:00:00.000', '2021-01-01T12:59:59.999'],
50+
]);
51+
});
52+
53+
it('time series - minute', () => {
54+
expect(timeSeries('minute', ['2021-01-01T10:00:00', '2021-01-01T10:02:00'])).toEqual([
55+
['2021-01-01T10:00:00.000', '2021-01-01T10:00:59.999'],
56+
['2021-01-01T10:01:00.000', '2021-01-01T10:01:59.999'],
57+
['2021-01-01T10:02:00.000', '2021-01-01T10:02:59.999'],
58+
]);
59+
});
60+
61+
it('time series - second', () => {
62+
expect(timeSeries('second', ['2021-01-01T10:00:00', '2021-01-01T10:00:02'])).toEqual([
63+
['2021-01-01T10:00:00.000', '2021-01-01T10:00:00.999'],
64+
['2021-01-01T10:00:01.000', '2021-01-01T10:00:01.999'],
65+
['2021-01-01T10:00:02.000', '2021-01-01T10:00:02.999'],
66+
]);
67+
});
68+
69+
it('time series - week', () => {
70+
expect(timeSeries('week', ['2021-01-01', '2021-01-31'])).toEqual([
71+
['2020-12-28T00:00:00.000', '2021-01-03T23:59:59.999'],
72+
['2021-01-04T00:00:00.000', '2021-01-10T23:59:59.999'],
73+
['2021-01-11T00:00:00.000', '2021-01-17T23:59:59.999'],
74+
['2021-01-18T00:00:00.000', '2021-01-24T23:59:59.999'],
75+
['2021-01-25T00:00:00.000', '2021-01-31T23:59:59.999'],
76+
]);
77+
});
78+
2679
it('time series - quarter', () => {
2780
expect(timeSeries('quarter', ['2021-01-01', '2021-12-31'])).toEqual([
2881
['2021-01-01T00:00:00.000', '2021-03-31T23:59:59.999'],
@@ -39,6 +92,18 @@ describe('timeSeries', () => {
3992
]);
4093
});
4194

95+
it('should throw an error for unsupported granularity', () => {
96+
expect(() => timeSeries('decade', ['2020-01-01', '2030-01-01'])).toThrowError(
97+
'Unsupported time granularity: decade'
98+
);
99+
});
100+
101+
it('should throw an error if timestampPrecision is missing', () => {
102+
expect(() => timeSeries('day', ['2021-01-01', '2021-01-02'], { timestampPrecision: 0 })).toThrowError(
103+
'options.timestampPrecision is required, actual: 0'
104+
);
105+
});
106+
42107
it('time series - reach limits', () => {
43108
expect(() => {
44109
timeSeries('second', ['1970-01-01', '2021-01-02']);

0 commit comments

Comments
 (0)