Skip to content

Commit f29ea9b

Browse files
authored
test(github): verify joinedDate format and stats mapping in getFullDa… (JhaSourav07#809)
## Description Fixes JhaSourav07#687 Fixes JhaSourav07#688 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A — test-only PR, no SVG output changes ## 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 7430ebc + a7136bb commit f29ea9b

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

lib/github.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,72 @@ describe('getFullDashboardData', () => {
361361
'[GitHub API] Failed to fetch profile for user "octocat"'
362362
);
363363
});
364+
365+
it('formats joinedDate as MMM YYYY', async () => {
366+
// Verifies that created_at from the REST API is formatted with toLocaleDateString('en-US')
367+
// into a stable 'Jan 2020' shape regardless of the runtime environment's system locale.
368+
vi.mocked(fetch).mockImplementation(async (url: any) => {
369+
if (typeof url === 'string' && url.includes('/users/testuser/repos')) {
370+
return mockResponse([]);
371+
}
372+
if (typeof url === 'string' && url.includes('/users/testuser')) {
373+
return mockResponse({
374+
login: 'testuser',
375+
name: 'Test User',
376+
avatar_url: 'https://example.com/avatar.png',
377+
bio: null,
378+
location: null,
379+
public_repos: 0,
380+
followers: 0,
381+
following: 0,
382+
created_at: '2020-01-15T00:00:00Z',
383+
});
384+
}
385+
return mockResponse({
386+
data: { user: { contributionsCollection: { contributionCalendar: mockCalendar } } },
387+
});
388+
});
389+
390+
const result = await getFullDashboardData('testuser');
391+
392+
// 'en-US' locale with { month: 'short', year: 'numeric' } always produces 'Jan 2020'
393+
expect(result.profile.joinedDate).toMatch(/^[A-Za-z]+ \d{4}$/);
394+
});
395+
396+
it('maps calculateStreak output correctly to stats', async () => {
397+
// Verifies that getFullDashboardData correctly pipes the contribution calendar
398+
// through calculateStreak and maps the result onto the returned stats object.
399+
vi.mocked(fetch).mockImplementation(async (url: any) => {
400+
if (typeof url === 'string' && url.includes('/users/testuser/repos')) {
401+
return mockResponse([]);
402+
}
403+
if (typeof url === 'string' && url.includes('/users/testuser')) {
404+
return mockResponse({
405+
login: 'testuser',
406+
name: 'Test User',
407+
avatar_url: 'https://example.com/avatar.png',
408+
bio: null,
409+
location: null,
410+
public_repos: 0,
411+
followers: 0,
412+
following: 0,
413+
created_at: '2020-01-15T00:00:00Z',
414+
});
415+
}
416+
return mockResponse({
417+
data: { user: { contributionsCollection: { contributionCalendar: mockCalendar } } },
418+
});
419+
});
420+
421+
const result = await getFullDashboardData('testuser');
422+
423+
// totalContributions must be passed through unchanged from the calendar
424+
expect(result.stats.totalContributions).toBe(mockCalendar.totalContributions);
425+
// streak values are non-negative by definition
426+
expect(result.stats.currentStreak).toBeGreaterThanOrEqual(0);
427+
// peak (longestStreak) can never be less than the current streak
428+
expect(result.stats.peakStreak).toBeGreaterThanOrEqual(result.stats.currentStreak);
429+
});
364430
});
365431

366432
describe('GitHub API cache behavior', () => {

0 commit comments

Comments
 (0)