Skip to content

Commit 99c77fd

Browse files
authored
test(github): add buildCommitClock unit tests (JhaSourav07#1157)
## Description Fixes JhaSourav07#1058 Added focused unit tests for `buildCommitClock` to verify weekday aggregation behavior and output structure. ## Pillar * [ ] 🎨 Pillar 1 β€” New Theme Design * [ ] πŸ“ Pillar 2 β€” Geometric SVG Improvement * [ ] πŸ• Pillar 3 β€” Timezone Logic Optimization * [x] πŸ› οΈ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable β€” test-only change. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). * [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. * [x] I have started the repo. * [x] I have made sure that I have only one commit to merge in this PR. * [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). * [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 5447fd1 + c831af9 commit 99c77fd

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
@@ -6,6 +6,7 @@ import {
66
fetchUserRepos,
77
getFullDashboardData,
88
generateAchievements,
9+
buildCommitClock,
910
clearGitHubApiCacheForTests,
1011
GITHUB_CACHE_TTL_MS,
1112
validateGitHubUsername,
@@ -909,6 +910,46 @@ describe('buildInsights', () => {
909910
});
910911
});
911912

913+
describe('buildCommitClock', () => {
914+
it('counts commits only on Sunday when all days are Sunday', () => {
915+
const result = buildCommitClock([
916+
{ date: '2024-01-07', contributionCount: 3 },
917+
{ date: '2024-01-14', contributionCount: 2 },
918+
]);
919+
920+
expect(result).toHaveLength(7);
921+
expect(result[0].commits).toBeGreaterThan(0);
922+
expect(result.slice(1).every((item) => item.commits === 0)).toBe(true);
923+
});
924+
925+
it('returns 7 days with zero commits for empty input', () => {
926+
const result = buildCommitClock([]);
927+
928+
expect(result).toHaveLength(7);
929+
expect(result.every((item) => item.commits === 0)).toBe(true);
930+
});
931+
932+
it('always returns exactly 7 items', () => {
933+
const result = buildCommitClock([{ date: '2024-01-07', contributionCount: 1 }]);
934+
935+
expect(result).toHaveLength(7);
936+
});
937+
938+
it('uses weekday labels from Sunday to Saturday', () => {
939+
const result = buildCommitClock([]);
940+
941+
expect(result.map((item) => item.day)).toEqual([
942+
'Sun',
943+
'Mon',
944+
'Tue',
945+
'Wed',
946+
'Thu',
947+
'Fri',
948+
'Sat',
949+
]);
950+
});
951+
});
952+
912953
// ---------- EPIC ENHANCEMENT TESTS ----------
913954

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

0 commit comments

Comments
Β (0)