Skip to content

Commit c831af9

Browse files
committed
test(github): add buildCommitClock unit tests
1 parent bcd0718 commit c831af9

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

lib/github.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
fetchUserRepos,
66
getFullDashboardData,
77
generateAchievements,
8+
buildCommitClock,
89
clearGitHubApiCacheForTests,
910
GITHUB_CACHE_TTL_MS,
1011
validateGitHubUsername,
@@ -709,6 +710,46 @@ describe('buildInsights', () => {
709710
});
710711
});
711712

713+
describe('buildCommitClock', () => {
714+
it('counts commits only on Sunday when all days are Sunday', () => {
715+
const result = buildCommitClock([
716+
{ date: '2024-01-07', contributionCount: 3 },
717+
{ date: '2024-01-14', contributionCount: 2 },
718+
]);
719+
720+
expect(result).toHaveLength(7);
721+
expect(result[0].commits).toBeGreaterThan(0);
722+
expect(result.slice(1).every((item) => item.commits === 0)).toBe(true);
723+
});
724+
725+
it('returns 7 days with zero commits for empty input', () => {
726+
const result = buildCommitClock([]);
727+
728+
expect(result).toHaveLength(7);
729+
expect(result.every((item) => item.commits === 0)).toBe(true);
730+
});
731+
732+
it('always returns exactly 7 items', () => {
733+
const result = buildCommitClock([{ date: '2024-01-07', contributionCount: 1 }]);
734+
735+
expect(result).toHaveLength(7);
736+
});
737+
738+
it('uses weekday labels from Sunday to Saturday', () => {
739+
const result = buildCommitClock([]);
740+
741+
expect(result.map((item) => item.day)).toEqual([
742+
'Sun',
743+
'Mon',
744+
'Tue',
745+
'Wed',
746+
'Thu',
747+
'Fri',
748+
'Sat',
749+
]);
750+
});
751+
});
752+
712753
// ---------- EPIC ENHANCEMENT TESTS ----------
713754

714755
describe('fetchOrgMembers', () => {

0 commit comments

Comments
 (0)