1import {firstStartDateAfterDate, startDaysBetween, fillEmptyStartDaysWithZeroes} from './time.js';
2
3test('startDaysBetween', () => {
4 expect(startDaysBetween(new Date('2024-02-15'), new Date('2024-04-18'))).toEqual([
5 1708214400000,
6 1708819200000,
7 1709424000000,
8 1710028800000,
9 1710633600000,
10 1711238400000,
11 1711843200000,
12 1712448000000,
13 1713052800000,
14 ]);
15});
16
17test('firstStartDateAfterDate', () => {
18 const expectedDate = new Date('2024-02-18').getTime();
19 expect(firstStartDateAfterDate(new Date('2024-02-15'))).toEqual(expectedDate);
20
21 expect(() => firstStartDateAfterDate('2024-02-15')).toThrowError('Invalid date');
22});
23test('fillEmptyStartDaysWithZeroes with data', () => {
24 expect(fillEmptyStartDaysWithZeroes([1708214400000, 1708819200000, 1708819300000], {
25 1708214400000: {'week': 1708214400000, 'additions': 1, 'deletions': 2, 'commits': 3},
26 1708819200000: {'week': 1708819200000, 'additions': 4, 'deletions': 5, 'commits': 6},
27 })).toEqual([
28 {'week': 1708214400000, 'additions': 1, 'deletions': 2, 'commits': 3},
29 {'week': 1708819200000, 'additions': 4, 'deletions': 5, 'commits': 6},
30 {
31 'additions': 0,
32 'commits': 0,
33 'deletions': 0,
34 'week': 1708819300000,
35 }]);
36});
37
38test('fillEmptyStartDaysWithZeroes with empty array', () => {
39 expect(fillEmptyStartDaysWithZeroes([], {})).toEqual([]);
40});