Skip to content

Commit f7d23fa

Browse files
authored
test(github): verify wrapped date range (JhaSourav07#1110)
## Description Fixes JhaSourav07#1061 Added test coverage verifying that `getWrappedData` passes the correct year-specific `from` and `to` date range when fetching GitHub contribution data. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [x] 🕐 Pillar 3 — Timezone Logic Optimization * [ ] 🛠️ 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 7bc9c64 + 05751c3 commit f7d23fa

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

lib/github.test.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,22 +992,31 @@ describe('getWrappedData', () => {
992992
beforeEach(() => {
993993
vi.spyOn(global, 'fetch');
994994
});
995+
995996
afterEach(() => {
996997
vi.restoreAllMocks();
997998
});
998999

9991000
it('returns wrapped statistics and top language correctly', async () => {
10001001
vi.mocked(fetch).mockImplementation(async (url) => {
10011002
const urlStr = typeof url === 'string' ? url : (url?.toString() ?? '');
1002-
// Return 2 TS repos, 1 Rust repo
1003-
if (urlStr.includes('/repos'))
1003+
1004+
if (urlStr.includes('/repos')) {
10041005
return mockResponse([
10051006
{ language: 'TypeScript' },
10061007
{ language: 'TypeScript' },
10071008
{ language: 'Rust' },
10081009
]);
1010+
}
1011+
10091012
return mockResponse({
1010-
data: { user: { contributionsCollection: { contributionCalendar: mockCalendar } } },
1013+
data: {
1014+
user: {
1015+
contributionsCollection: {
1016+
contributionCalendar: mockCalendar,
1017+
},
1018+
},
1019+
},
10111020
});
10121021
});
10131022

@@ -1016,4 +1025,35 @@ describe('getWrappedData', () => {
10161025
expect(result.topLanguage).toBe('TypeScript');
10171026
expect(result.totalContributions).toBe(mockCalendar.totalContributions);
10181027
});
1028+
1029+
it('passes the correct from and to date range to GitHub contributions fetch', async () => {
1030+
vi.mocked(fetch).mockImplementation(async (url) => {
1031+
const urlStr = typeof url === 'string' ? url : (url?.toString() ?? '');
1032+
1033+
if (urlStr.includes('/repos')) {
1034+
return mockResponse([]);
1035+
}
1036+
1037+
return mockResponse({
1038+
data: {
1039+
user: {
1040+
contributionsCollection: {
1041+
contributionCalendar: mockCalendar,
1042+
},
1043+
},
1044+
},
1045+
});
1046+
});
1047+
1048+
await getWrappedData('octocat', '2024');
1049+
1050+
const graphQLCall = vi
1051+
.mocked(fetch)
1052+
.mock.calls.find(([url]) => url.toString().includes('/graphql'));
1053+
1054+
const body = JSON.parse(graphQLCall?.[1]?.body as string);
1055+
1056+
expect(body.variables.from).toBe('2024-01-01T00:00:00Z');
1057+
expect(body.variables.to).toBe('2024-12-31T23:59:59Z');
1058+
});
10191059
});

0 commit comments

Comments
 (0)