Skip to content

Commit a4740e0

Browse files
authored
test(github): verify fetchUserRepos returns correct star count for a single repo (JhaSourav07#1692)
## Description Fixes JhaSourav07#684 Program: GSSoC 2026 This PR introduces robust unit test coverage for the `fetchUserRepos` utility function within our GitHub GraphQL/REST client integration layer. Previously, tests verified only the first item in a minimal layout. This update implements deep structural verification across a varied dataset array. ### Changes Made * Added 1 comprehensive test case in `lib/github.test.ts` mocking network responses via global `fetch`. * Structured a mock array payload containing 3 mock repositories with distinct star weights and languages. * Added 3 core assertions validating length accuracy, property presence (`stargazers_count` & `language`), and data mapping parity. ### Why this matters Ensures the repository parsing logic remains functional and correctly handles multiple project entries, protecting against broken metric calculations and rendering glitches across internal user dashboard modules. --- ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) --- ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`npm run test lib/github.test.ts`). - [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 starred the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord server for faster collaboration, mentorship, and PR support.
2 parents 2030ce9 + 90a12fe commit a4740e0

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

lib/github.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,27 @@ describe('fetchUserRepos', () => {
456456
expect(result[0].stargazers_count).toBe(1);
457457
});
458458

459+
it('returns a full three-repo payload with the expected star counts and languages', async () => {
460+
const mockedRepos = [
461+
{ stargazers_count: 7, language: 'TypeScript' },
462+
{ stargazers_count: 42, language: 'Rust' },
463+
{ stargazers_count: 128, language: 'JavaScript' },
464+
];
465+
466+
vi.mocked(fetch).mockResolvedValue(mockResponse(mockedRepos));
467+
468+
const result = await fetchUserRepos('octocat', { bypassCache: true });
469+
470+
expect(result).toHaveLength(3);
471+
result.forEach((repo, index) => {
472+
expect(repo).toHaveProperty('stargazers_count');
473+
expect(repo).toHaveProperty('language');
474+
expect(repo.stargazers_count).toBe(mockedRepos[index].stargazers_count);
475+
expect(repo.language).toBe(mockedRepos[index].language);
476+
});
477+
expect(result).toEqual(mockedRepos);
478+
});
479+
459480
it('encodes the username before using it in the REST repos path', async () => {
460481
vi.mocked(fetch).mockResolvedValue(
461482
mockResponse([{ stargazers_count: 1, language: 'TypeScript' }])

0 commit comments

Comments
 (0)