Repository navigation
Expand file tree
/
Copy pathdiff.test.ts
More file actions
63 lines (60 loc) · 1.6 KB
/
Copy pathdiff.test.ts
File metadata and controls
63 lines (60 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { describe, it, expect } from 'vitest';
import { diffContributions } from '@/lib/realtime/diffContributions';
import type { ContributionCalendar } from '@/types';
describe('diffContributions', () => {
it('should return empty list when old calendar is null', () => {
const newCal: ContributionCalendar = {
totalContributions: 5,
weeks: [
{
contributionDays: [{ date: '2026-07-20', contributionCount: 5 }],
},
],
};
const result = diffContributions('user1', null, newCal);
expect(result).toEqual([]);
});
it('should detect added contributions', () => {
const oldCal: ContributionCalendar = {
totalContributions: 5,
weeks: [
{
contributionDays: [
{ date: '2026-07-20', contributionCount: 5 },
{ date: '2026-07-21', contributionCount: 0 },
],
},
],
};
const newCal: ContributionCalendar = {
totalContributions: 8,
weeks: [
{
contributionDays: [
{ date: '2026-07-20', contributionCount: 6 }, // +1
{ date: '2026-07-21', contributionCount: 2 }, // +2
],
},
],
};
const result = diffContributions('user1', oldCal, newCal);
expect(result).toEqual([
{
type: 'contribution_added',
payload: {
username: 'user1',
date: '2026-07-20',
count: 1,
},
},
{
type: 'contribution_added',
payload: {
username: 'user1',
date: '2026-07-21',
count: 2,
},
},
]);
});
});